@devries-cameron20 / t3code Mirror · read-only / commits / 1a3f1459b2
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 10:45 UTC

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 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

George Nijo committed Oct 30, 2026 at 21:43 UTC 1a3f1459b26dd75b15a217f0183c992f68f2ab86
3 files changed +34 -3
apps/server/src/orchestration-v2/RunExecutionService.test.ts
+12 -2
@@ -36,7 +36,9 @@ import * as Layer from "effect/Layer";
36 import * as Option from "effect/Option";
37 import * as Ref from "effect/Ref";
38 import * as Stream from "effect/Stream";
39 +import { SqlError, classifySqliteError } from "effect/sql/SqlError";
40
41 +import { toPersistenceSqlError } from "../persistence/Errors.ts";
42 import * as ServerSettings from "../serverSettings.ts";
43 import * as CheckpointService from "./CheckpointService.ts";
44 import type { PendingOrchestrationEffectV2 } from "./EffectOutbox.ts";
@@ -2653,7 +2655,7 @@ it.effect.each(["failure", "defect", "interrupt-failure", "ownership-lost"] as c
2655 ReadonlyArray<ProviderAdapter.ProviderAdapterV2InterruptInput>
2656 >([]);
2657 const ids = backgroundScenarioIds(`ingestion:${failureMode}`);
2656 - const { observed, finalEvents } = yield* captureRootRunTermination({
2658 + const { written, observed, finalEvents } = yield* captureRootRunTermination({
2659 key: `ingestion:${failureMode}`,
2660 initialProviderTurnId: null,
2661 rejectTerminalWrite: failureMode === "ownership-lost",
@@ -2686,7 +2688,13 @@ it.effect.each(["failure", "defect", "interrupt-failure", "ownership-lost"] as c
2688 const error = new ProviderEventIngestor.ProviderEventPublishError({
2689 providerSessionId: ProviderSessionId.make(`session:${failureMode}`),
2690 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 + ),
2698 });
2699 return failureMode === "defect" ? Effect.die(error) : Effect.fail(error);
2700 },
@@ -2730,6 +2738,8 @@ it.effect.each(["failure", "defect", "interrupt-failure", "ownership-lost"] as c
2738 failureMode === "interrupt-failure",
2739 );
2740 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)");
2743 const repaired = finalEvents.find((event) => event.type === "provider-turn.updated");
2744 if (failureMode === "interrupt-failure") {
2745 assert.isUndefined(repaired);
apps/server/src/orchestration-v2/RunExecutionService.ts
+10 -1
@@ -48,11 +48,13 @@ import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"
48 import * as ProviderEventIngestor from "./ProviderEventIngestor.ts";
49 import type { ProjectionStoreV2Error } from "./ProjectionStore.ts";
50 import {
51 + knownProviderFailureMessage,
52 makeProviderFailure,
53 makeProviderFailureTurnItem,
54 } from "@t3tools/provider-core/server/failure";
55 import * as RunFinalizationService from "./RunFinalizationService.ts";
56 import * as TurnItemPositionStore from "./TurnItemPositionStore.ts";
57 +import { userFacingDatabaseErrorMessage } from "./UserFacingErrors.ts";
58
59 export interface ProviderEventRoutingState {
60 readonly ownedThreadIds: ReadonlySet<ThreadId>;
@@ -1554,6 +1556,7 @@ export const layer: Layer.Layer<
1556 : null;
1557 const latestItemOrdinal = yield* Ref.get(latestTurnItemOrdinal);
1558 const openSubagents = yield* Ref.get(openRunOwnedSubagents);
1559 + const squashed = Cause.squash(cause);
1560 let nextRetryWarningAt = completedAt;
1561 yield* writeFinalRunEvents({
1562 run: input.run,
@@ -1569,7 +1572,13 @@ export const layer: Layer.Layer<
1572 ...(abandonedProviderTurn === null ? {} : { abandonedProviderTurn }),
1573 completedAt,
1574 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 + }),
1582 latestItemOrdinal + 1,
1583 ),
1584 failureItemPersisted: false,
apps/server/src/orchestration-v2/UserFacingErrors.ts
+12
@@ -37,6 +37,18 @@ function databaseErrorMessage(value: unknown): string | undefined {
37 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.";
38 }
39
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 +
52 const CAPABILITY_REJECTION_MESSAGES: Record<string, (provider: string) => string> = {
53 queued_messages: (p) => `${p} cannot queue messages behind an active run.`,
54 active_steering: (p) =>