Skip to content

Commit 1a3f145

Browse files
georgenijoclaudemaria-rcks
authored
fix(server): show the database error instead of "Provider turn failed." when event ingestion can't write (#26782)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 6366aba commit 1a3f145

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎apps/server/src/orchestration-v2/RunExecutionService.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ import * as Layer from "effect/Layer";
3636
import * as Option from "effect/Option";
3737
import * as Ref from "effect/Ref";
3838
import * as Stream from "effect/Stream";
39+
import { SqlError, classifySqliteError } from "effect/sql/SqlError";
3940

41+
import { toPersistenceSqlError } from "../persistence/Errors.ts";
4042
import * as ServerSettings from "../serverSettings.ts";
4143
import * as CheckpointService from "./CheckpointService.ts";
4244
import type { PendingOrchestrationEffectV2 } from "./EffectOutbox.ts";
@@ -2653,7 +2655,7 @@ it.effect.each(["failure", "defect", "interrupt-failure", "ownership-lost"] as c
26532655
ReadonlyArray<ProviderAdapter.ProviderAdapterV2InterruptInput>
26542656
>([]);
26552657
const ids = backgroundScenarioIds(`ingestion:${failureMode}`);
2656-
const { observed, finalEvents } = yield* captureRootRunTermination({
2658+
const { written, observed, finalEvents } = yield* captureRootRunTermination({
26572659
key: `ingestion:${failureMode}`,
26582660
initialProviderTurnId: null,
26592661
rejectTerminalWrite: failureMode === "ownership-lost",
@@ -2686,7 +2688,13 @@ it.effect.each(["failure", "defect", "interrupt-failure", "ownership-lost"] as c
26862688
const error = new ProviderEventIngestor.ProviderEventPublishError({
26872689
providerSessionId: ProviderSessionId.make(`session:${failureMode}`),
26882690
eventCount: 1,
2689-
cause: new Error("SQLITE_FULL: database or disk is full"),
2691+
cause: toPersistenceSqlError("OrchestrationEventStore.appendAgentEvents:insert")(
2692+
new SqlError({
2693+
reason: classifySqliteError(
2694+
Object.assign(new Error("unable to open database file"), { errcode: 14 }),
2695+
),
2696+
}),
2697+
),
26902698
});
26912699
return failureMode === "defect" ? Effect.die(error) : Effect.fail(error);
26922700
},
@@ -2730,6 +2738,8 @@ it.effect.each(["failure", "defect", "interrupt-failure", "ownership-lost"] as c
27302738
failureMode === "interrupt-failure",
27312739
);
27322740
assert.deepEqual(observed, ["run:failed", "pull-requests-refreshed"]);
2741+
const error = written.find((item) => item.type === "error");
2742+
assert.include(error?.failure.message ?? "", "(SQLITE_CANTOPEN)");
27332743
const repaired = finalEvents.find((event) => event.type === "provider-turn.updated");
27342744
if (failureMode === "interrupt-failure") {
27352745
assert.isUndefined(repaired);

‎apps/server/src/orchestration-v2/RunExecutionService.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"
4848
import * as ProviderEventIngestor from "./ProviderEventIngestor.ts";
4949
import type { ProjectionStoreV2Error } from "./ProjectionStore.ts";
5050
import {
51+
knownProviderFailureMessage,
5152
makeProviderFailure,
5253
makeProviderFailureTurnItem,
5354
} from "@t3tools/provider-core/server/failure";
5455
import * as RunFinalizationService from "./RunFinalizationService.ts";
5556
import * as TurnItemPositionStore from "./TurnItemPositionStore.ts";
57+
import { userFacingDatabaseErrorMessage } from "./UserFacingErrors.ts";
5658

5759
export interface ProviderEventRoutingState {
5860
readonly ownedThreadIds: ReadonlySet<ThreadId>;
@@ -1554,6 +1556,7 @@ export const layer: Layer.Layer<
15541556
: null;
15551557
const latestItemOrdinal = yield* Ref.get(latestTurnItemOrdinal);
15561558
const openSubagents = yield* Ref.get(openRunOwnedSubagents);
1559+
const squashed = Cause.squash(cause);
15571560
let nextRetryWarningAt = completedAt;
15581561
yield* writeFinalRunEvents({
15591562
run: input.run,
@@ -1569,7 +1572,13 @@ export const layer: Layer.Layer<
15691572
...(abandonedProviderTurn === null ? {} : { abandonedProviderTurn }),
15701573
completedAt,
15711574
terminal: makeFailedTerminalEvent(
1572-
makeProviderFailure({ cause: Cause.squash(cause), class: "unknown" }),
1575+
makeProviderFailure({
1576+
cause: squashed,
1577+
message:
1578+
knownProviderFailureMessage(squashed) ??
1579+
userFacingDatabaseErrorMessage(squashed),
1580+
class: "unknown",
1581+
}),
15731582
latestItemOrdinal + 1,
15741583
),
15751584
failureItemPersisted: false,

‎apps/server/src/orchestration-v2/UserFacingErrors.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ function databaseErrorMessage(value: unknown): string | undefined {
3737
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.";
3838
}
3939

40+
export function userFacingDatabaseErrorMessage(cause: unknown): string | undefined {
41+
const seen = new Set<unknown>();
42+
let value = cause;
43+
while (Predicate.isObject(value) && !seen.has(value)) {
44+
seen.add(value);
45+
const message = databaseErrorMessage(value);
46+
if (message !== undefined) return message;
47+
value = value.cause;
48+
}
49+
return undefined;
50+
}
51+
4052
const CAPABILITY_REJECTION_MESSAGES: Record<string, (provider: string) => string> = {
4153
queued_messages: (p) => `${p} cannot queue messages behind an active run.`,
4254
active_steering: (p) =>

0 commit comments

Comments
 (0)