Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions apps/server/src/orchestration-v2/RunExecutionService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Ref from "effect/Ref";
import * as Stream from "effect/Stream";
import { SqlError, classifySqliteError } from "effect/sql/SqlError";

import { toPersistenceSqlError } from "../persistence/Errors.ts";
import * as ServerSettings from "../serverSettings.ts";
import * as CheckpointService from "./CheckpointService.ts";
import type { PendingOrchestrationEffectV2 } from "./EffectOutbox.ts";
Expand Down Expand Up @@ -2585,7 +2587,7 @@ it.effect.each(["failure", "defect", "interrupt-failure", "ownership-lost"] as c
ReadonlyArray<ProviderAdapter.ProviderAdapterV2InterruptInput>
>([]);
const ids = backgroundScenarioIds(`ingestion:${failureMode}`);
const { observed, finalEvents } = yield* captureRootRunTermination({
const { written, observed, finalEvents } = yield* captureRootRunTermination({
key: `ingestion:${failureMode}`,
initialProviderTurnId: null,
rejectTerminalWrite: failureMode === "ownership-lost",
Expand Down Expand Up @@ -2618,7 +2620,13 @@ it.effect.each(["failure", "defect", "interrupt-failure", "ownership-lost"] as c
const error = new ProviderEventIngestor.ProviderEventPublishError({
providerSessionId: ProviderSessionId.make(`session:${failureMode}`),
eventCount: 1,
cause: new Error("SQLITE_FULL: database or disk is full"),
cause: toPersistenceSqlError("OrchestrationEventStore.appendAgentEvents:insert")(
new SqlError({
reason: classifySqliteError(
Object.assign(new Error("unable to open database file"), { errcode: 14 }),
),
}),
),
});
return failureMode === "defect" ? Effect.die(error) : Effect.fail(error);
},
Expand Down Expand Up @@ -2662,6 +2670,8 @@ it.effect.each(["failure", "defect", "interrupt-failure", "ownership-lost"] as c
failureMode === "interrupt-failure",
);
assert.deepEqual(observed, ["run:failed", "pull-requests-refreshed"]);
const error = written.find((item) => item.type === "error");
assert.include(error?.failure.message ?? "", "(SQLITE_CANTOPEN)");
const repaired = finalEvents.find((event) => event.type === "provider-turn.updated");
if (failureMode === "interrupt-failure") {
assert.isUndefined(repaired);
Expand Down
11 changes: 10 additions & 1 deletion apps/server/src/orchestration-v2/RunExecutionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"
import * as ProviderEventIngestor from "./ProviderEventIngestor.ts";
import type { ProjectionStoreV2Error } from "./ProjectionStore.ts";
import {
knownProviderFailureMessage,
makeProviderFailure,
makeProviderFailureTurnItem,
} from "@t3tools/provider-core/server/failure";
import * as RunFinalizationService from "./RunFinalizationService.ts";
import * as TurnItemPositionStore from "./TurnItemPositionStore.ts";
import { userFacingDatabaseErrorMessage } from "./UserFacingErrors.ts";

export interface ProviderEventRoutingState {
readonly ownedThreadIds: ReadonlySet<ThreadId>;
Expand Down Expand Up @@ -1536,6 +1538,7 @@ export const layer: Layer.Layer<
: null;
const latestItemOrdinal = yield* Ref.get(latestTurnItemOrdinal);
const openSubagents = yield* Ref.get(openRunOwnedSubagents);
const squashed = Cause.squash(cause);
let nextRetryWarningAt = completedAt;
yield* writeFinalRunEvents({
run: input.run,
Expand All @@ -1551,7 +1554,13 @@ export const layer: Layer.Layer<
...(abandonedProviderTurn === null ? {} : { abandonedProviderTurn }),
completedAt,
terminal: makeFailedTerminalEvent(
makeProviderFailure({ cause: Cause.squash(cause), class: "unknown" }),
makeProviderFailure({
cause: squashed,
message:
knownProviderFailureMessage(squashed) ??
userFacingDatabaseErrorMessage(squashed),
class: "unknown",
}),
latestItemOrdinal + 1,
),
failureItemPersisted: false,
Expand Down
12 changes: 12 additions & 0 deletions apps/server/src/orchestration-v2/UserFacingErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ function databaseErrorMessage(value: unknown): string | undefined {
return "The T3 Code server could not complete this database request. Retry once; if it still fails, check the server logs for the database error.";
}

export function userFacingDatabaseErrorMessage(cause: unknown): string | undefined {
const seen = new Set<unknown>();
let value = cause;
while (Predicate.isObject(value) && !seen.has(value)) {
seen.add(value);
const message = databaseErrorMessage(value);
if (message !== undefined) return message;
value = value.cause;
}
return undefined;
}

const CAPABILITY_REJECTION_MESSAGES: Record<string, (provider: string) => string> = {
queued_messages: (p) => `${p} cannot queue messages behind an active run.`,
active_steering: (p) =>
Expand Down
Loading