The best way to control Claude Code, Codex and more from any computer or phone
fix: database errors show actionable recovery guidance (#20748)
Co-authored-by: SAPHID <saphid@users.noreply.github.com>
Alex Southwell committed
Oct 19, 2026 at 06:34 UTC
38c662508caf750812e61f81bc89d7adf762d7b9
3 files changed
+130
-7
apps/server/src/orchestration-v2/UserFacingErrors.test.ts
+95
@@ -1,5 +1,13 @@
1
import { assert, describe, it } from "@effect/vitest";
2
+import * as NodeServices from "@effect/platform-node/NodeServices";
3
+import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
4
+import * as Effect from "effect/Effect";
5
+import * as FileSystem from "effect/FileSystem";
6
+import * as Path from "effect/Path";
7
+import * as SqlClient from "effect/sql/SqlClient";
8
+import { SqlError, classifySqliteError } from "effect/sql/SqlError";
9
10
+import { toPersistenceSqlError } from "../persistence/Errors.ts";
11
import { userFacingDispatchErrorMessage } from "./UserFacingErrors.ts";
12
13
describe("userFacingDispatchErrorMessage", () => {
@@ -65,4 +73,91 @@ describe("userFacingDispatchErrorMessage", () => {
73
"Claude provider thread provider-thread-1 has no live query.",
74
);
75
});
76
+
77
+ it.effect("explains a real database open failure through dispatch and persistence wrappers", () =>
78
+ Effect.gen(function* () {
79
+ const fs = yield* FileSystem.FileSystem;
80
+ const path = yield* Path.Path;
81
+ const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-database-error-" });
82
+ const cause = yield* Effect.void.pipe(
83
+ Effect.provide(
84
+ NodeSqliteClient.layer({ filename: path.join(directory, "missing", "state.sqlite") }),
85
+ ),
86
+ Effect.flip,
87
+ );
88
+ const message = userFacingDispatchErrorMessage({
89
+ message: "Failed to dispatch orchestration command message.dispatch (command-1).",
90
+ cause: toPersistenceSqlError("OrchestrationEventStore.append:query")(cause),
91
+ });
92
+
93
+ assert.include(message, "server could not open a database file (SQLITE_CANTOPEN)");
94
+ assert.include(message, "machine running the server");
95
+ assert.include(message, "free disk space");
96
+ assert.include(message, "data and temporary directories exist and are writable");
97
+ assert.include(message, "then retry");
98
+ assert.notInclude(message, directory);
99
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
100
+ );
101
+
102
+ it.effect("explains a full database and allows a retry after capacity is restored", () =>
103
+ Effect.gen(function* () {
104
+ const sql = yield* SqlClient.SqlClient;
105
+ yield* sql`CREATE TABLE entries (payload BLOB)`;
106
+ yield* sql`PRAGMA max_page_count = 2`;
107
+ const cause = yield* sql`INSERT INTO entries VALUES (zeroblob(16384))`.pipe(Effect.flip);
108
+ const message = userFacingDispatchErrorMessage({ cause });
109
+
110
+ assert.include(message, "database or disk is full (SQLITE_FULL)");
111
+ assert.include(message, "Free space on the machine running the server, then retry");
112
+ assert.include(message, "database size limit");
113
+
114
+ yield* sql`PRAGMA max_page_count = 100`;
115
+ yield* sql`INSERT INTO entries VALUES (zeroblob(16384))`;
116
+ const rows = yield* sql<{ count: number }>`SELECT COUNT(*) AS count FROM entries`;
117
+ assert.equal(rows[0]?.count, 1);
118
+ }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
119
+ );
120
+
121
+ it.effect("gives server permission guidance for a real read-only failure", () =>
122
+ Effect.gen(function* () {
123
+ const sql = yield* SqlClient.SqlClient;
124
+ yield* sql`CREATE TABLE entries (payload TEXT)`;
125
+ yield* sql`PRAGMA query_only = ON`;
126
+ const cause = yield* sql`INSERT INTO entries VALUES ('private-message')`.pipe(Effect.flip);
127
+ const message = userFacingDispatchErrorMessage(cause);
128
+
129
+ assert.include(message, "server database is read-only (SQLITE_READONLY)");
130
+ assert.include(message, "data directory is writable");
131
+ assert.notInclude(message, "private-message");
132
+ }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
133
+ );
134
+
135
+ it.each([
136
+ [5, "SQLITE_BUSY", "Wait a moment, then retry"],
137
+ [6, "SQLITE_LOCKED", "Wait a moment, then retry"],
138
+ [10 | (3 << 8), "SQLITE_IOERR", "free disk space and disk health"],
139
+ [14 | (6 << 8), "SQLITE_CANTOPEN", "exist and are writable"],
140
+ [11, "SQLITE_CORRUPT", "Preserve the server data directory"],
141
+ [26, "SQLITE_NOTADB", "configured database path"],
142
+ ] as const)("maps SQLite code %i to %s with recovery guidance", (errcode, code, guidance) => {
143
+ const cause = Object.assign(new Error("private-query-data"), { errcode, errno: errcode });
144
+ const error = new SqlError({ reason: classifySqliteError(cause) });
145
+ const message = userFacingDispatchErrorMessage({ cause: error });
146
+
147
+ assert.include(message, code);
148
+ assert.include(message, guidance);
149
+ assert.notInclude(message, "private-query-data");
150
+ });
151
+
152
+ it("keeps unknown SQL failures contextual without exposing driver text or parameters", () => {
153
+ const cause = Object.assign(new Error("private-query-data"), { errcode: 1 });
154
+ const error = new SqlError({ reason: classifySqliteError(cause) });
155
+ const message = userFacingDispatchErrorMessage({
156
+ cause: toPersistenceSqlError("OrchestrationEventStore.append:query")(error),
157
+ });
158
+
159
+ assert.include(message, "server could not complete this database request");
160
+ assert.include(message, "server logs");
161
+ assert.notInclude(message, "private-query-data");
162
+ });
163
});
apps/server/src/orchestration-v2/UserFacingErrors.ts
+33
@@ -1,5 +1,6 @@
1
import { PROVIDER_DISPLAY_NAMES, type ProviderDriverKind } from "@t3tools/contracts";
2
import * as Predicate from "effect/Predicate";
3
+import * as SqlError from "effect/sql/SqlError";
4
5
const GENERIC_ERROR_PREFIXES = [
6
"Failed to dispatch orchestration V2 command",
@@ -7,6 +8,35 @@ const GENERIC_ERROR_PREFIXES = [
8
"Provider adapter failed while dispatching orchestration command ",
9
];
10
11
+const SQLITE_RECOVERY_MESSAGES: Readonly<Record<number, string>> = {
12
+ 5: "The T3 Code server database is busy (SQLITE_BUSY). Wait a moment, then retry. If this keeps happening, check for another T3 Code process using the same data directory on the server.",
13
+ 6: "The T3 Code server database is locked (SQLITE_LOCKED). Wait a moment, then retry. If this keeps happening, check the server logs for the process holding the database lock.",
14
+ 8: "The T3 Code server database is read-only (SQLITE_READONLY). On the machine running the server, check that its data directory is writable and its disk is mounted read-write, then retry.",
15
+ 10: "The T3 Code server could not read or write its database (SQLITE_IOERR). On the machine running the server, check free disk space and disk health, then retry. If it still fails, check the server logs.",
16
+ 11: "The T3 Code server database appears damaged (SQLITE_CORRUPT). Preserve the server data directory and check the server logs before restoring a database backup.",
17
+ 13: "The T3 Code server could not save this change because its database or disk is full (SQLITE_FULL). Free space on the machine running the server, then retry. If space is available, check the server logs for a database size limit.",
18
+ 14: "The T3 Code server could not open a database file (SQLITE_CANTOPEN). On the machine running the server, check free disk space and that its data and temporary directories exist and are writable, then retry. If it still fails, check the server logs.",
19
+ 26: "The T3 Code server could not read its database file (SQLITE_NOTADB). Preserve the server data directory and check the configured database path and server logs before restoring a database backup.",
20
+};
21
+
22
+function databaseErrorMessage(value: unknown): string | undefined {
23
+ if (!SqlError.isSqlError(value)) return undefined;
24
+
25
+ let cause: unknown = value.cause;
26
+ const seen = new Set<unknown>();
27
+ while (Predicate.isObject(cause) && !seen.has(cause)) {
28
+ seen.add(cause);
29
+ // node:sqlite uses extended result codes; their low byte is the primary code.
30
+ if (typeof cause.errcode === "number" && Number.isInteger(cause.errcode) && cause.errcode > 0) {
31
+ const message = SQLITE_RECOVERY_MESSAGES[cause.errcode & 0xff];
32
+ if (message !== undefined) return message;
33
+ }
34
+ cause = cause.cause;
35
+ }
36
+
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
const CAPABILITY_REJECTION_MESSAGES: Record<string, (provider: string) => string> = {
41
queued_messages: (p) => `${p} cannot queue messages behind an active run.`,
42
active_steering: (p) =>
@@ -81,6 +111,9 @@ function collectErrorMessages(value: unknown, seen: Set<unknown>): ReadonlyArray
111
return value.flatMap((item) => collectErrorMessages(item, seen));
112
}
113
114
+ const databaseMessage = databaseErrorMessage(value);
115
+ if (databaseMessage !== undefined) return [databaseMessage];
116
+
117
const message = messageFrom(value);
118
if (!Predicate.isObject(value)) {
119
return message === undefined ? [] : [message];
apps/web/src/components/chat/ThreadErrorBanner.tsx
+2
-7
@@ -3,9 +3,9 @@ import { memo } from "react";
3
import { Alert, AlertAction, AlertDescription } from "../ui/alert";
4
import { Button } from "../ui/button";
5
import { CircleAlertIcon, XIcon } from "lucide-react";
6
-import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
6
import { OpenAI } from "../Icons";
7
import { ChatGptUsageButton } from "../settings/ChatGptUsageButton";
8
+import { ExpandableText } from "../settings/ExpandableText";
9
10
export function getThreadErrorBannerKey(threadKey: string, error: string | null): string | null {
11
return error === null ? null : `${threadKey}\u0000${error}`;
@@ -59,12 +59,7 @@ export const ThreadErrorBanner = memo(function ThreadErrorBanner({
59
<p>Review your usage settings in ChatGPT to continue.</p>
60
</div>
61
) : (
62
- <Tooltip>
63
- <TooltipTrigger render={<div className="line-clamp-3" />}>{error}</TooltipTrigger>
64
- <TooltipPopup side="top" className="whitespace-pre-wrap">
65
- {error}
66
- </TooltipPopup>
67
- </Tooltip>
62
+ <ExpandableText text={error} />
63
)}
64
</AlertDescription>
65
{(chatGptUsageLimit || onDismiss) && (