GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sync: port upstream server VCS, keybindings, images, terminal, persis… · aaditagrawal/t3code@dcd00ef

This repository was archived by the owner on Oct 10, 2026. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • imageMime.test.ts
    • imageMime.ts
    • keybindings.test.ts
    • keybindings.ts
    • persistence
      • ProviderSessionRuntime.ts
      • RepositoryErrorCorrelation.test.ts
    • provider/Drivers
      • CodexHomeLayout.test.ts
      • CodexHomeLayout.ts
    • terminal
      • Manager.test.ts
      • Manager.ts
    • vcs
      • GitVcsDriverCore.test.ts
      • GitVcsDriverCore.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/imageMime.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/imageMime.test.ts
+57Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,63 @@ describe("imageMime", () => {
3232
});
3333
});
3434

35+
it("rejects payload with characters outside the base64 alphabet", () => {
36+
expect(parseBase64DataUrl("data:image/png;base64,SGVs!bG8=")).toBeNull();
37+
expect(parseBase64DataUrl("data:image/png;base64,SGVs,bG8=")).toBeNull();
38+
});
39+
40+
it("rejects structurally malformed base64", () => {
41+
// '=' before the trailing padding position
42+
expect(parseBase64DataUrl("data:image/png;base64,AB=CD===")).toBeNull();
43+
expect(parseBase64DataUrl("data:image/png;base64,SGV=bG8=")).toBeNull();
44+
// more than two padding characters
45+
expect(parseBase64DataUrl("data:image/png;base64,SGVsbG8=====AAA")).toBeNull();
46+
// length not a multiple of 4
47+
expect(parseBase64DataUrl("data:image/png;base64,SGVsbG8")).toBeNull();
48+
});
49+
50+
it("accepts base64 with one or two trailing padding characters", () => {
51+
expect(parseBase64DataUrl("data:image/png;base64,SGVsbA==")).toEqual({
52+
mimeType: "image/png",
53+
base64: "SGVsbA==",
54+
});
55+
expect(parseBase64DataUrl("data:image/png;base64,SGVsbG8h")).toEqual({
56+
mimeType: "image/png",
57+
base64: "SGVsbG8h",
58+
});
59+
});
60+
61+
it("rejects empty and whitespace-only payloads", () => {
62+
expect(parseBase64DataUrl("data:image/png;base64,")).toBeNull();
63+
expect(parseBase64DataUrl("data:image/png;base64, \r\n")).toBeNull();
64+
});
65+
66+
it("parses a case-insensitive scheme and mime type", () => {
67+
expect(parseBase64DataUrl("DATA:IMAGE/PNG;BASE64,SGVsbG8=")).toEqual({
68+
mimeType: "image/png",
69+
base64: "SGVsbG8=",
70+
});
71+
});
72+
73+
it("parses a multi-megabyte payload from a deep call stack", () => {
74+
// Regression: matching the payload with a regex borrowed the JS call
75+
// stack, so a ~10 MB image parsed inside fiber execution threw
76+
// "RangeError: Maximum call stack size exceeded".
77+
const dataUrl = `data:image/png;base64,${"A".repeat(14_000_000)}`;
78+
const atDepth = (depth: number): ReturnType<typeof parseBase64DataUrl> =>
79+
depth === 0 ? parseBase64DataUrl(dataUrl) : atDepth(depth - 1);
80+
const findMaxDepth = (depth: number): number => {
81+
try {
82+
return findMaxDepth(depth + 1);
83+
} catch {
84+
return depth;
85+
}
86+
};
87+
const result = atDepth(Math.floor(findMaxDepth(0) * 0.85));
88+
expect(result?.mimeType).toBe("image/png");
89+
expect(result?.base64.length).toBe(14_000_000);
90+
});
91+
3592
it("does not read inherited keys from mime extension map", () => {
3693
expect(inferImageExtension({ mimeType: "constructor" })).toBe(".bin");
3794
});
Collapse file

‎apps/server/src/imageMime.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/imageMime.ts
+63-8Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,43 @@ export const SAFE_IMAGE_FILE_EXTENSIONS = new Set([
2929
".webp",
3030
]);
3131

32+
// Whether `code` is a character the base64 payload may contain, aside from
33+
// the whitespace handled separately below.
34+
function isBase64Char(code: number): boolean {
35+
return (
36+
(code >= 0x61 && code <= 0x7a) || // a-z
37+
(code >= 0x41 && code <= 0x5a) || // A-Z
38+
(code >= 0x30 && code <= 0x39) || // 0-9
39+
code === 0x2b || // +
40+
code === 0x2f || // /
41+
code === 0x3d // =
42+
);
43+
}
44+
45+
function isBase64Whitespace(code: number): boolean {
46+
return code === 0x09 || code === 0x0d || code === 0x0a || code === 0x20; // \t \r \n space
47+
}
48+
49+
// Data URLs carry the full image payload, so this parser must never run a
50+
// regex across the payload: V8's regex engine borrows the JS call stack, and
51+
// matching a multi-megabyte string from a deep call stack (e.g. inside fiber
52+
// execution) throws "Maximum call stack size exceeded".
3253
export function parseBase64DataUrl(
3354
dataUrl: string,
3455
): { readonly mimeType: string; readonly base64: string } | null {
35-
const match = /^data:([^,]+),([a-z0-9+/=\r\n ]+)$/i.exec(dataUrl.trim());
36-
if (!match) return null;
56+
const trimmed = dataUrl.trim();
57+
if (trimmed.slice(0, 5).toLowerCase() !== "data:") return null;
58+
59+
const commaIndex = trimmed.indexOf(",");
60+
if (commaIndex === -1) return null;
61+
const header = trimmed.slice(5, commaIndex);
62+
if (header.length === 0) return null;
3763

3864
const headerParts: Array<string> = [];
39-
for (const part of (match[1] ?? "").split(";")) {
40-
const trimmed = part.trim();
41-
if (trimmed.length > 0) {
42-
headerParts.push(trimmed);
65+
for (const part of header.split(";")) {
66+
const partTrimmed = part.trim();
67+
if (partTrimmed.length > 0) {
68+
headerParts.push(partTrimmed);
4369
}
4470
}
4571
if (headerParts.length < 2) {
@@ -51,8 +77,37 @@ export function parseBase64DataUrl(
5177
}
5278

5379
const mimeType = headerParts[0]?.toLowerCase();
54-
const base64 = match[2]?.replace(/\s+/g, "");
55-
if (!mimeType || !base64) return null;
80+
if (!mimeType) return null;
81+
82+
const payload = trimmed.slice(commaIndex + 1);
83+
const runs: Array<string> = [];
84+
let runStart = -1;
85+
for (let index = 0; index < payload.length; index += 1) {
86+
const code = payload.charCodeAt(index);
87+
if (isBase64Char(code)) {
88+
if (runStart === -1) runStart = index;
89+
continue;
90+
}
91+
if (!isBase64Whitespace(code)) return null;
92+
if (runStart !== -1) {
93+
runs.push(payload.slice(runStart, index));
94+
runStart = -1;
95+
}
96+
}
97+
if (runStart !== -1) {
98+
runs.push(payload.slice(runStart));
99+
}
100+
const base64 = runs.length === 1 ? runs[0]! : runs.join("");
101+
if (base64.length === 0 || base64.length % 4 !== 0) return null;
102+
const firstPad = base64.indexOf("=");
103+
if (firstPad !== -1) {
104+
// '=' is only valid as one or two trailing padding characters; Node's
105+
// decoder would otherwise silently truncate at the first '='.
106+
if (base64.length - firstPad > 2) return null;
107+
for (let index = firstPad; index < base64.length; index += 1) {
108+
if (base64.charCodeAt(index) !== 0x3d) return null;
109+
}
110+
}
56111

57112
return { mimeType, base64 };
58113
}
Collapse file

‎apps/server/src/keybindings.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/keybindings.test.ts
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,28 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
411411
}).pipe(Effect.provide(makeKeybindingsLayer())),
412412
);
413413

414+
it.effect("replacing with a rule that already exists elsewhere does not duplicate it", () =>
415+
Effect.gen(function* () {
416+
const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
417+
yield* writeKeybindingsConfig(keybindingsConfigPath, [
418+
{ key: "mod+r", command: "script.run-tests.run" },
419+
{ key: "mod+alt+r", command: "script.run-tests.run" },
420+
]);
421+
yield* Effect.gen(function* () {
422+
const keybindings = yield* Keybindings.Keybindings;
423+
return yield* keybindings.upsertKeybindingRule({
424+
key: "mod+alt+r",
425+
command: "script.run-tests.run",
426+
replace: { key: "mod+r", command: "script.run-tests.run" },
427+
});
428+
});
429+
430+
const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
431+
const persistedView = persisted.map(({ key, command }) => ({ key, command }));
432+
assert.deepEqual(persistedView, [{ key: "mod+alt+r", command: "script.run-tests.run" }]);
433+
}).pipe(Effect.provide(makeKeybindingsLayer())),
434+
);
435+
414436
it.effect("removes only the targeted custom keybinding", () =>
415437
Effect.gen(function* () {
416438
const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
Collapse file

‎apps/server/src/keybindings.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/keybindings.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,9 @@ const make = Effect.gen(function* () {
658658
const nextConfig = [
659659
...customConfig.filter((entry) => {
660660
if (replaceTarget) {
661-
return !isSameKeybindingRule(entry, replaceTarget);
661+
return (
662+
!isSameKeybindingRule(entry, replaceTarget) && !isSameKeybindingRule(entry, rule)
663+
);
662664
}
663665
return !isSameKeybindingRule(entry, rule);
664666
}),
Collapse file

‎apps/server/src/persistence/ProviderSessionRuntime.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/persistence/ProviderSessionRuntime.ts
+15-6Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as Arr from "effect/Array";
12
import * as Context from "effect/Context";
23
import * as Effect from "effect/Effect";
34
import * as Layer from "effect/Layer";
@@ -280,18 +281,26 @@ export const make = Effect.gen(function* () {
280281
),
281282
),
282283
Effect.flatMap((rows) =>
284+
// Skip rows that no longer decode (e.g. written by an older build)
285+
// instead of failing the whole list — one stale row must not disable
286+
// every consumer that enumerates sessions, such as the reaper.
283287
Effect.forEach(rows, (row) =>
284288
decodeRuntimeRow(row).pipe(
285-
Effect.mapError((cause) =>
286-
PersistenceDecodeError.fromSchemaError(
287-
"ProviderSessionRuntimeRepository.list:decodeRows",
288-
cause,
289-
{ threadId: row.threadId },
290-
),
289+
Effect.map(Option.some),
290+
Effect.catch((cause) =>
291+
Effect.logWarning("provider.session.runtime.row-skipped", {
292+
threadId: row.threadId,
293+
error: PersistenceDecodeError.fromSchemaError(
294+
"ProviderSessionRuntimeRepository.list:decodeRows",
295+
cause,
296+
{ threadId: row.threadId },
297+
).message,
298+
}).pipe(Effect.as(Option.none<ProviderSessionRuntime>())),
291299
),
292300
),
293301
),
294302
),
303+
Effect.map((decoded) => Arr.getSomes(decoded)),
295304
);
296305

297306
const deleteByThreadId: ProviderSessionRuntimeRepository["Service"]["deleteByThreadId"] = (
Collapse file

‎apps/server/src/persistence/RepositoryErrorCorrelation.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/persistence/RepositoryErrorCorrelation.test.ts
+18-10Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe("persistence error correlation", () => {
182182
}).pipe(Effect.provide(authPairingLinkLayer)),
183183
);
184184

185-
it.effect("correlates provider runtime SQL and per-row decode failures by thread", () =>
185+
it.effect("skips undecodable provider runtime rows and correlates SQL failures by thread", () =>
186186
Effect.gen(function* () {
187187
const runtimes = yield* ProviderSessionRuntime.ProviderSessionRuntimeRepository;
188188
const sql = yield* SqlClient.SqlClient;
@@ -215,16 +215,24 @@ describe("persistence error correlation", () => {
215215
)
216216
`;
217217

218-
const decodeError = yield* Effect.flip(runtimes.list());
219-
assert.instanceOf(decodeError, PersistenceErrors.PersistenceDecodeError);
220-
assert.deepStrictEqual(decodeError.correlation, { threadId });
221-
assert.equal(
222-
decodeError.message,
223-
`Decode error in ProviderSessionRuntimeRepository.list:decodeRows: ${decodeError.issue}`,
218+
const validThreadId = ThreadId.make("thread-valid");
219+
yield* runtimes.upsert({
220+
threadId: validThreadId,
221+
providerName: "codex",
222+
providerInstanceId: null,
223+
adapterKey: "codex",
224+
runtimeMode: "full-access",
225+
status: "running",
226+
lastSeenAt,
227+
resumeCursor: null,
228+
runtimePayload: null,
229+
});
230+
231+
const listed = yield* runtimes.list();
232+
assert.deepStrictEqual(
233+
listed.map((runtime) => runtime.threadId),
234+
[validThreadId],
224235
);
225-
assert.notInclude(decodeError.issue, runtimePayload);
226-
assert.notInclude(decodeError.message, runtimePayload);
227-
assert.notInclude(decodeError.message, lastSeenAt);
228236

229237
yield* sql`DROP TABLE provider_session_runtime`;
230238
const sqlFailure = yield* Effect.flip(
Collapse file

‎apps/server/src/provider/Drivers/CodexHomeLayout.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/Drivers/CodexHomeLayout.test.ts
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
114114

115115
const sessionsTarget = yield* fileSystem.readLink(path.join(shadowHome, "sessions"));
116116
const configTarget = yield* fileSystem.readLink(path.join(shadowHome, "config.toml"));
117+
const mcpOauthLocksTarget = yield* fileSystem.readLink(
118+
path.join(shadowHome, "mcp-oauth-locks"),
119+
);
117120
const modelsCacheExists = yield* fileSystem.exists(
118121
path.join(shadowHome, "models_cache.json"),
119122
);
@@ -124,12 +127,45 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
124127

125128
expect(sessionsTarget).toBe(path.join(sharedHome, "sessions"));
126129
expect(configTarget).toBe(path.join(sharedHome, "config.toml"));
130+
expect(mcpOauthLocksTarget).toBe(path.join(sharedHome, "mcp-oauth-locks"));
127131
expect(modelsCacheExists).toBe(false);
128132
expect(authLinkResult._tag).toBe("Failure");
129133
expect(authContents).toContain("shadow");
130134
}),
131135
);
132136

137+
it.effect("replaces Codex-created local MCP OAuth locks with the shared lock directory", () =>
138+
Effect.gen(function* () {
139+
const fileSystem = yield* FileSystem.FileSystem;
140+
const path = yield* Path.Path;
141+
const sharedHome = yield* makeTempDir("t3code-codex-shared-");
142+
const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
143+
const shadowHome = path.join(shadowRoot, "shadow");
144+
const sharedLocks = path.join(sharedHome, "mcp-oauth-locks");
145+
const shadowLocks = path.join(shadowHome, "mcp-oauth-locks");
146+
147+
yield* writeTextFile(path.join(sharedLocks, "file-store.lock"), "");
148+
yield* writeTextFile(path.join(shadowLocks, "file-store.lock"), "");
149+
150+
const layout = yield* resolveCodexHomeLayout(
151+
decodeCodexSettings({
152+
homePath: sharedHome,
153+
shadowHomePath: shadowHome,
154+
}),
155+
);
156+
157+
yield* materializeCodexShadowHome(layout);
158+
159+
const locksTarget = yield* fileSystem.readLink(shadowLocks);
160+
const sharedLockExists = yield* fileSystem.exists(
161+
path.join(sharedLocks, "file-store.lock"),
162+
);
163+
164+
expect(locksTarget).toBe(sharedLocks);
165+
expect(sharedLockExists).toBe(true);
166+
}),
167+
);
168+
133169
it.effect("accepts Codex-created shadow-local runtime directories", () =>
134170
Effect.gen(function* () {
135171
const fileSystem = yield* FileSystem.FileSystem;
Collapse file

‎apps/server/src/provider/Drivers/CodexHomeLayout.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/Drivers/CodexHomeLayout.ts
+29-10Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ const KNOWN_SHARED_DIRECTORIES = [
2626
"plugins",
2727
"cache",
2828
"logs",
29+
"mcp-oauth-locks",
2930
] as const;
3031

3132
const PRIVATE_ENTRY_NAMES = new Set(["auth.json", "models_cache.json"]);
3233
const SHADOW_LOCAL_ENTRY_NAMES = new Set(["log", "memories", "tmp"]);
34+
const REPLACEABLE_SHARED_RUNTIME_DIRECTORIES = new Set(["mcp-oauth-locks"]);
3335

3436
function resolveHomePath(path: Path.Path, value: string | undefined): string {
3537
const expanded =
@@ -225,16 +227,6 @@ const ensureSymlink = Effect.fn("CodexHomeLayout.ensureSymlink")(function* (inpu
225227
linkPath: link,
226228
});
227229

228-
if (state._tag === "NotSymlink") {
229-
return yield* new CodexShadowHomeEntryConflictError({
230-
sharedHomePath: input.sharedHomePath,
231-
effectiveHomePath: input.effectiveHomePath,
232-
entryName: input.entryName,
233-
linkPath: link,
234-
targetPath: target,
235-
});
236-
}
237-
238230
const createLink = input.fileSystem.symlink(target, link).pipe(
239231
Effect.catchTags({
240232
PlatformError: (cause) =>
@@ -250,6 +242,33 @@ const ensureSymlink = Effect.fn("CodexHomeLayout.ensureSymlink")(function* (inpu
250242
}),
251243
);
252244

245+
if (state._tag === "NotSymlink") {
246+
if (!REPLACEABLE_SHARED_RUNTIME_DIRECTORIES.has(input.entryName)) {
247+
return yield* new CodexShadowHomeEntryConflictError({
248+
sharedHomePath: input.sharedHomePath,
249+
effectiveHomePath: input.effectiveHomePath,
250+
entryName: input.entryName,
251+
linkPath: link,
252+
targetPath: target,
253+
});
254+
}
255+
256+
yield* input.fileSystem.remove(link, { recursive: true }).pipe(
257+
Effect.catchTags({
258+
PlatformError: (cause) =>
259+
new CodexShadowHomeFileSystemError({
260+
sharedHomePath: input.sharedHomePath,
261+
effectiveHomePath: input.effectiveHomePath,
262+
operation: "remove",
263+
path: link,
264+
entryName: input.entryName,
265+
cause,
266+
}),
267+
}),
268+
);
269+
return yield* createLink;
270+
}
271+
253272
if (state._tag === "Missing") {
254273
return yield* createLink;
255274
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.