Skip to content

Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA

TypeScript

/sync-gbrain's read check works when the first page is over 64 KB (#4396) (#4497)

Garry Tand789dd965b55
diff --git a/bin/gstack-gbrain-read-capability.ts b/bin/gstack-gbrain-read-capability.ts
index 8126b0827..587ab7068 100644
--- a/bin/gstack-gbrain-read-capability.ts
+++ b/bin/gstack-gbrain-read-capability.ts
@@ -76,7 +76,8 @@ function readCapability(): Verdict {
|| /[\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]/u.test(slug)
|| slug.split('/').some(segment => !segment || segment === '.' || segment === '..'))
return unknown('listed page has an invalid slug');
- const fetched = run(['get', slug, '--source', pin, '--json']);
+ const fetched = run(['get', slug, '--source', pin, '--json', '--body', 'window', '--max-bytes', '4096'])
+ ?? run(['get', slug, '--source', pin, '--json']);
if (!fetched) return unknown('source-scoped get unavailable; retry later');
try {
const page = JSON.parse(fetched);
diff --git a/changelog.d/fix-sync-gbrain-large-page-probe.md b/changelog.d/fix-sync-gbrain-large-page-probe.md
new file mode 100644
index 000000000..2c777fe68
--- /dev/null
+++ b/changelog.d/fix-sync-gbrain-large-page-probe.md
@@ -0,0 +1 @@
+- **/sync-gbrain's read check now works when the first page in your code source is over 64 KB.** The check read the whole page just to confirm its source and slug, and a large first page (a lockfile is the usual one) hit its 64 KiB output limit, so every run reported the read as `unknown`. It now asks gbrain for a 4 KB window of the page (`--body window --max-bytes 4096`), which keeps the response small however big the page is. A gbrain from before body windows (0.60.231.0) gets the old whole-page read with the same limit, and output cut off at the limit still counts as `unknown`, never `ready`. Thanks to @nfitzsimmons for the report and the fix (#4396).
diff --git a/docs/evals/detector-inventory.md b/docs/evals/detector-inventory.md
index 0e38df97e..83f277bff 100644
--- a/docs/evals/detector-inventory.md
+++ b/docs/evals/detector-inventory.md
@@ -283,7 +283,7 @@ The plan-design-review-plan-mode-smoke verdicts are S1-S10, and the plan-design-
| setup-gbrain-remote | test/skill-e2e-setup-gbrain-remote.test.ts:326-328 | serialized transcript must not contain `"error_class": NETWORK/AUTH/MALFORMED` | verify JSON in the Bash result | no | (b) |
| setup-gbrain-remote | test/skill-e2e-setup-gbrain-remote.test.ts:352 | CLAUDE.md ~ `Mode: remote-http` | the persisted config block | yes | (c) |
| setup-gbrain-path4-local-pglite | test/skill-e2e-setup-gbrain-path4-local-pglite.test.ts:72-73; test/helpers/setup-gbrain-fixture.ts:122-169 | question ~ code search/pglite/symbol; scripted actor classifies option labels and throws on unknown sets | AUQ labels only, no option ids | yes | (c) |
-| sync-gbrain-read-ready, sync-gbrain-read-unknown | test/helpers/sync-gbrain-readiness-verdict.ts:4-25 | Capability row OK/WARN, YELLOW verdict, no unnegated ready claim | bin/gstack-gbrain-read-capability.ts:87 status JSON (status only; row and verdict are rendered) | yes | (c) |
+| sync-gbrain-read-ready, sync-gbrain-read-unknown | test/helpers/sync-gbrain-readiness-verdict.ts:4-25 | Capability row OK/WARN, YELLOW verdict, no unnegated ready claim | bin/gstack-gbrain-read-capability.ts:88 status JSON (status only; row and verdict are rendered) | yes | (c) |
| codex-discover-skill | test/helpers/codex-eval.ts:43 | output ~ review/gstack/skill | none | partly | (d) |
| codex-review-findings | test/helpers/codex-eval.ts:66-67; lib/outside-review-result.ts:88 | output ~ finding/issue/…/no issues; refusal phrases → unavailable | executed commands read first; no review-log step in the fixture | partly | (d) |
| outside-voice-codex-to-claude-code, outside-voice-claude-code-to-codex | test/helpers/outside-voice-evidence.ts:214-216 | outside stdout ~ invoice and authorization defect; no refusal | dispatch and receipts are structural; the review-log row holds status only | no | (d) |
diff --git a/test/gbrain-read-capability.test.ts b/test/gbrain-read-capability.test.ts
index c3e5b4df4..70438b61b 100644
--- a/test/gbrain-read-capability.test.ts
+++ b/test/gbrain-read-capability.test.ts
@@ -7,7 +7,9 @@ import { spawnSync } from 'node:child_process';
const roots: string[] = [];
afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }); });
-function fixture(opts: { state?: unknown; pin?: string; registration?: unknown | ((repo: string) => unknown); slug?: string; list?: string; get?: unknown; fail?: string; gitExecutable?: string } = {}) {
+const WINDOW = '--body window --max-bytes 4096';
+
+function fixture(opts: { state?: unknown; pin?: string; registration?: unknown | ((repo: string) => unknown); slug?: string; list?: string; get?: unknown; window?: unknown; pageBytes?: number; legacy?: boolean; fail?: string; gitExecutable?: string } = {}) {
const root = mkdtempSync(join(tmpdir(), 'gbrain-read-'));
roots.push(root);
const repo = join(root, 'repo');
@@ -31,10 +33,11 @@ function fixture(opts: { state?: unknown; pin?: string; registration?: unknown |
import { appendFileSync } from 'node:fs';
appendFileSync(${JSON.stringify(log)}, process.argv.slice(2).join(' ') + '\\n');
const args = process.argv.slice(2).join(' ');
-if (args === ${JSON.stringify(opts.fail)}) process.exit(2);
+if (${JSON.stringify(opts.fail ?? null)} !== null && args.startsWith(${JSON.stringify(opts.fail ?? '')})) process.exit(2);
if (args === 'sources list --json') console.log(${JSON.stringify(JSON.stringify(registration ?? { sources: [{ id: source, local_path: repo }] }))});
else if (args === 'list --source client-repo --limit 1') console.log(${JSON.stringify(opts.list ?? `${slug}\tcode\t2026-09-24\tReadme`)});
-else if (args === ${JSON.stringify(`get ${slug} --source client-repo --json`)}) console.log(${JSON.stringify(JSON.stringify(opts.get ?? { source_id: source, slug }))});
+else if (args === ${JSON.stringify(`get ${slug} --source client-repo --json ${WINDOW}`)} && ${!opts.legacy}) console.log(${JSON.stringify(JSON.stringify(opts.window ?? opts.get ?? { source_id: source, slug, body: 'x'.repeat(Math.min(opts.pageBytes ?? 8, 4096)) }))});
+else if (args === ${JSON.stringify(`get ${slug} --source client-repo --json`)}) console.log(${JSON.stringify(JSON.stringify(opts.get ?? { source_id: source, slug, compiled_truth: 'x'.repeat(opts.pageBytes ?? 8) }))});
else process.exit(3);
`);
chmodSync(join(bin, 'gbrain'), 0o755);
@@ -53,7 +56,7 @@ test('source-scoped read validates a pretty sync state, registration, and matchi
const result = f.run();
expect(result.result.status).toBe(0);
expect(result.value.status).toBe('ready');
- expect(result.calls).toEqual(['sources list --json', 'list --source client-repo --limit 1', 'get code/repo/readme --source client-repo --json']);
+ expect(result.calls).toEqual(['sources list --json', 'list --source client-repo --limit 1', `get code/repo/readme --source client-repo --json ${WINDOW}`]);
});
test('symlink-equivalent registered worktree passes but another source path fails closed', () => {
@@ -70,7 +73,7 @@ test('symlink-equivalent registered worktree passes but another source path fail
writeFileSync(join(f.repo, '.gbrain-source'), 'other-source\n');
const result = f.run();
expect(result.value.status).toBe('unknown');
- expect(result.calls).toEqual(['sources list --json', 'list --source client-repo --limit 1', 'get code/repo/readme --source client-repo --json']);
+ expect(result.calls).toEqual(['sources list --json', 'list --source client-repo --limit 1', `get code/repo/readme --source client-repo --json ${WINDOW}`]);
});
test('rejects the former header-only and multi-row TSV response before get', () => {
@@ -95,7 +98,7 @@ test('accepts a bounded literal-Unicode code slug', () => {
const slug = 'code/路径/mañana🌳.ts';
const result = fixture({ slug }).run();
expect(result.value.status).toBe('ready');
- expect(result.calls.at(-1)).toBe(`get ${slug} --source client-repo --json`);
+ expect(result.calls.at(-1)).toBe(`get ${slug} --source client-repo --json ${WINDOW}`);
});
test.each(['--help', 'code/a/../b', 'code/./b', 'code/\u0007bad', 'a'.repeat(513)])('rejects unsafe slug %j before get', slug => {
@@ -104,6 +107,25 @@ test.each(['--help', 'code/a/../b', 'code/./b', 'code/\u0007bad', 'a'.repeat(513
expect(result.calls).toEqual(['sources list --json', 'list --source client-repo --limit 1']);
});
+test('a first page over 64 KB reads ready through a bounded window', () => {
+ const result = fixture({ pageBytes: 300_000 }).run();
+ expect(result.value.status).toBe('ready');
+ expect(result.calls).toEqual(['sources list --json', 'list --source client-repo --limit 1', `get code/repo/readme --source client-repo --json ${WINDOW}`]);
+});
+
+test('a window response over the read limit is unknown, never a truncated ready', () => {
+ const result = fixture({ pageBytes: 300_000, window: { source_id: 'client-repo', slug: 'code/repo/readme', body: 'x'.repeat(300_000) } }).run();
+ expect(result.value.status).toBe('unknown');
+ expect(result.calls).toHaveLength(4);
+});
+
+test('a gbrain without body windows falls back to the whole-page read under the same limit', () => {
+ const small = fixture({ legacy: true }).run();
+ expect(small.value.status).toBe('ready');
+ expect(small.calls.slice(2)).toEqual([`get code/repo/readme --source client-repo --json ${WINDOW}`, 'get code/repo/readme --source client-repo --json']);
+ expect(fixture({ legacy: true, pageBytes: 300_000 }).run().value.status).toBe('unknown');
+});
+
test('rejects a JSON error envelope with matching source and slug', () => {
const result = fixture({ get: { source_id: 'client-repo', slug: 'code/repo/readme', content: '# Readme', error: { code: 'not_found' } } }).run();
expect(result.value.status).toBe('unknown');
diff --git a/test/helpers/sync-gbrain-readiness-fixture.ts b/test/helpers/sync-gbrain-readiness-fixture.ts
index b818b50b8..379aa8190 100644
--- a/test/helpers/sync-gbrain-readiness-fixture.ts
+++ b/test/helpers/sync-gbrain-readiness-fixture.ts
@@ -37,7 +37,7 @@ const args = process.argv.slice(2).join(' ');
appendFileSync(${JSON.stringify(log)}, args + '\\n');
if (args === 'sources list --json') console.log(${JSON.stringify(JSON.stringify({ sources: [{ id: 'client-fixture', local_path: workDir }] }))});
else if (args === 'list --source client-fixture --limit 1') console.log('code/fixture/readme\\tcode\\t2026-09-24\\tReadme');
-else if (args === 'get code/fixture/readme --source client-fixture --json') ${kind === 'ready'
+else if (args.startsWith('get code/fixture/readme --source client-fixture --json')) ${kind === 'ready'
? `console.log(${JSON.stringify(JSON.stringify({ source_id: 'client-fixture', slug: 'code/fixture/readme', content: '# Readme' }))});`
: "{ console.error('temporary read failure'); process.exit(2); }"}
else { console.error('unsupported operation'); process.exit(3); }
diff --git a/test/skill-e2e-sync-gbrain-readiness.test.ts b/test/skill-e2e-sync-gbrain-readiness.test.ts
index b8b89853b..39775cb6d 100644
--- a/test/skill-e2e-sync-gbrain-readiness.test.ts
+++ b/test/skill-e2e-sync-gbrain-readiness.test.ts
@@ -24,7 +24,8 @@ async function runReadiness(kind: 'ready' | 'unknown', name: string) {
expect(fixture.calls()).toEqual([
'sources list --json',
'list --source client-fixture --limit 1',
- 'get code/fixture/readme --source client-fixture --json',
+ 'get code/fixture/readme --source client-fixture --json --body window --max-bytes 4096',
+ ...(kind === 'unknown' ? ['get code/fixture/readme --source client-fixture --json'] : []),
]);
const content = fixture.content();
expect(fixture.sourceIntact()).toBe(true);
diff --git a/test/sync-gbrain-readiness-fixture.test.ts b/test/sync-gbrain-readiness-fixture.test.ts
index dca1af274..3bdd0e06b 100644
--- a/test/sync-gbrain-readiness-fixture.test.ts
+++ b/test/sync-gbrain-readiness-fixture.test.ts
@@ -14,7 +14,8 @@ for (const kind of ['ready', 'unknown'] as const) {
expect(JSON.parse(check.stdout).status).toBe(kind);
expect(fixture.calls()).toEqual([
'sources list --json', 'list --source client-fixture --limit 1',
- 'get code/fixture/readme --source client-fixture --json',
+ 'get code/fixture/readme --source client-fixture --json --body window --max-bytes 4096',
+ ...(kind === 'unknown' ? ['get code/fixture/readme --source client-fixture --json'] : []),
]);
expect(fixture.sourceIntact()).toBe(true);
} finally { fixture.cleanup(); }