Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(sync): an over-cap segmented re-export is reported as over_push_scan_cap without a looping fix (GBRA-287 /ship review pass 2)
garrytandb43b1a93f10
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e6233aec75..623f7654d2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,7 +14,7 @@ identifiers and attribution are available in the pre-removal Git revision**A page stored in segments no longer stops a source's sync.** A managed sync re-importing a Git-tracked page stored in segments (`pages.segmented_storage`) whose working-tree bytes differ from the pinned commit, as on a live checkout, compared the file against the stored page with a whole-body read. That read refused with `page_body_segmented`, recorded as a run failure in the freeze phase, and every later sync stopped `sync_blocked` at the same file, with a retry command that could not help. The freeze now compares a segmented page up to 24 MiB read back whole, as its publication already did, so the page gets the outcome an inline page gets. A page whose stored body can't be read at the freeze (`page_body_segmented`, or `page_body_rows_unreadable`) is held `page_write_failed`, naming its code, and the rest of the source syncs. `gbrain sync status` classifies such a hold by that code (`page_body_rows_unreadable`: retry, no person needed), not as an unplaced `page_write_failed`. A run that does stop before any write request is admitted (discovery, freeze or admission) now shows `last_error.request_id: null` in `gbrain sync status --json` instead of leaving the field out: there is no receipt, root request or `write_error_detail` to look for, and the phase, code and message name the error.-A full sync's DB-only reconcile (#2426) now re-exports a page stored in segments instead of refusing it: the file is measured from the segments of one generation, then streamed through the staging writer the withdrawal mirror and restore_page use, written under an in-progress name and renamed once whole, with the bytes `gbrain export` writes and the existing file's mode. A file over the pre-push secret-scan cap is skipped before the page's `source_path` is bound. Pages whose re-export fails are listed in the result's `reexport_failures`, and the run completes. A segmented read no longer refuses a healthy page `page_body_rows_unreadable` because a new body published between its reads.+A full sync's DB-only reconcile (#2426) now re-exports a page stored in segments instead of refusing it: the file is measured from the segments of one generation, then streamed through the staging writer the withdrawal mirror and restore_page use, written under an in-progress name and renamed once whole, with the bytes `gbrain export` writes and the existing file's mode. A file over the pre-push secret-scan cap is skipped before the page's `source_path` is bound (a body already over the cap is not streamed to measure it) and listed as `over_push_scan_cap`, with a fix that does not send the agent back into the same full sync. Pages whose re-export fails are listed in the result's `reexport_failures`, and the run completes. A segmented read no longer refuses a healthy page `page_body_rows_unreadable` because a new body published between its reads.### Itemized changesdiff --git a/src/commands/sync/full.ts b/src/commands/sync/full.tsindex 49a5e3001d..8a139a6792 100644--- a/src/commands/sync/full.ts+++ b/src/commands/sync/full.ts@@ -530,6 +530,13 @@ async function reconcileFullSyncDeletes(if (r.skipped === 'disabled_by_config' || r.skipped === 'url_clone') continue;if (r.skipped === 'file_changed') throw new OperationError('file_database_drift', 'The checkout file exists; re-export only restores absent files.', `If the file holds the newer edit, run gbrain sync --source ${sid} to import it; otherwise ask the user which version to keep.`);if (r.error) throw new Error(r.error);+ if (r.skipped === 'over_push_scan_cap') {+ reExportFailures++;+ const fix = 'Kept the database page. Its file would pass the pre-push secret-scan cap, so it stays database-only and no sync re-exports it; read it with gbrain get.';+ reexportFailures.push({ slug, path: pathBySlug.get(slug)!, code: 'over_push_scan_cap', message: 'The rendered file is over the pre-push secret-scan cap.', fix });+ serr(` ${slug} (over_push_scan_cap) ${fix}`);+ continue;+ }throw new OperationError('storage_error', `The page was not re-exported (${r.skipped}).`, 'Run gbrain doctor --json for the write-through target, then sync again.');} catch (error) {const failure = classifyItemFailure(error);diff --git a/src/core/write-through.ts b/src/core/write-through.tsindex 1203cd0c42..54057cb934 100644--- a/src/core/write-through.ts+++ b/src/core/write-through.ts@@ -478,11 +478,13 @@ export async function writePageThrough(const md = segmented ? null : serializePageToMarkdown(writtenPage, await engine.getTags(slug, { sourceId }), {frontmatterOverrides: opts.frontmatterOverrides,});- const streamed = segmented ? await segmentedPageFile(engine, slug, sourceId) : null;- if (segmented && !streamed) return { written: false, skipped: 'page_not_found_after_write' };+ // A segmented body alone over the cap is refused before its segments are streamed to measure the file.+ const overByBody = segmented && Number((writtenPage as { body_bytes?: number | string | null }).body_bytes ?? 0) > PUSH_SCAN_MAX_FILE_BYTES;+ const streamed = segmented && !overByBody ? await segmentedPageFile(engine, slug, sourceId) : null;+ if (segmented && !overByBody && !streamed) return { written: false, skipped: 'page_not_found_after_write' };// The pre-push secret scan refuses to push any file it cannot scan, so a// file over its cap would block every later push of the brain repo.- if ((md !== null ? Buffer.byteLength(md, 'utf-8') : streamed!.bytes) > PUSH_SCAN_MAX_FILE_BYTES) {+ if (overByBody || (md !== null ? Buffer.byteLength(md, 'utf-8') : streamed!.bytes) > PUSH_SCAN_MAX_FILE_BYTES) {opts.logger?.warn(`[write-through] ${slug}: the rendered file is over the ${PUSH_SCAN_MAX_FILE_BYTES}-byte pre-push secret-scan cap — file not written (DB row is intact)`);return { written: false, skipped: 'over_push_scan_cap' };}diff --git a/test/sync-reconcile-db-only-segmented.test.ts b/test/sync-reconcile-db-only-segmented.test.tsindex 8151a19658..96cf18e817 100644--- a/test/sync-reconcile-db-only-segmented.test.ts+++ b/test/sync-reconcile-db-only-segmented.test.ts@@ -173,6 +173,11 @@ describe('GBRA-287: full-sync re-export of a DB-only page stored in segments', (expect(row!.source_path).toBeNull();expect(existsSync(join(repoPath, 'memories/huger.md'))).toBe(false);expect(stagingLeft(repoPath)).toEqual([]);+ await engine.executeRaw("UPDATE pages SET source_path='memories/huger.md' WHERE slug='memories/huger'");+ const result = await fullSync();+ expect(result.reexport_failures).toEqual([expect.objectContaining({ slug: 'memories/huger', code: 'over_push_scan_cap' })]);+ expect(result.reexport_failures![0]!.fix).not.toContain('--full');+ expect(existsSync(join(repoPath, 'memories/huger.md'))).toBe(false);}, 600_000);test('the derived writer skips a generated page stored in segments instead of writing a file its rollback cannot compare', async () => {