Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(sync): review round for segmented write-through and freeze holds (GBRA-287)
garrytan4ebdae1a5b11
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1f2bc20f91..04ea7f7a52 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,20 +12,22 @@ identifiers and attribution are available in the pre-removal Git revision## [Unreleased]-**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 both codes instead of reporting them as unknown.+**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 full sync's DB-only reconcile (#2426) now re-exports a page stored in segments instead of refusing it: the file is streamed from the segments in one snapshot 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. 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. 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 changes- `src/core/page-state/import-guard.ts` (`sameCanonicalImport`): a stored body left unread (over 24 MiB) differs from any parsed body, as `sameContentAnyKeyOrder` already said, instead of reading the throwing getter.- `src/core/persistence/sync-screen.ts` (`frozenImportScreenInput`): the freeze screen reads the page snapshot (and a rename's base) through `materializedSnapshot`.- `src/core/persistence/sync-entry-fault.ts` (`freezeFaultHold`): `page_body_segmented` and `page_body_rows_unreadable` thrown while freezing one entry hold that entry `page_write_failed` (origin `freeze`, `write_failure.code` the page-body code) instead of stopping the run. The item breaker still applies.-- `src/core/persistence/sync-fault-class.ts`, `public-category.ts`: rows for both codes (`page_body_segmented`: upgrade, a person; `page_body_rows_unreadable`: retry, the segment-table grant).-- `src/core/write-through.ts` (`writePageThrough`): a page stored in segments is measured and streamed from its segments inside one repeatable-read read-only transaction (`unreadPageFile`, `stageStreamedContent`), then renamed over the target after the file-changed check; frontmatter overrides on such a page are refused with an error result.+- `src/core/persistence/sync-fault-class.ts`, `public-category.ts`, `sync-status.ts` (`holdVerdict`): rows for both codes (`page_body_segmented`: upgrade, a person; `page_body_rows_unreadable`: retry, the segment-table grant), applied to a `page_write_failed` hold whose `write_failure.code` names one.+- `src/core/write-through.ts` (`writePageThrough`): a page stored in segments is measured from its segments (`unreadPageFile`) and checked against the pre-push scan cap before `source_path` is bound, then streamed (`stageStreamedContent`, which refuses bytes that changed since the measure) on the engine it was given, so a caller inside a transaction (an owner repair) works, keeping the existing file's mode, and renamed over the target after the file-changed check; frontmatter overrides on such a page are refused with an error result.+- `src/core/persistence/page-prepare.ts` (`fileMatchesSnapshot`): a segmented snapshot is compared read back whole, so the freeze drift screen no longer reads a format-only difference as drift.+- `src/core/cycle/derived-write-through.ts` (`writeDerivedFile`): a generated page stored in segments is skipped (`segmented_page`), since the batch rollback compares file strings.- `src/commands/sync/full.ts`: the DB-only re-export no longer refuses segmented pages, and each failed re-export is returned in `reexport_failures` (slug, path, code, message, fix).- `src/core/page-body/body-tiling.ts` (`readTiledManifest`), `ingest.ts`, `read-range.ts`, `projection.ts`, `segment-rewrite.ts`: a live read names its generation first and checks that generation's rows against that generation's size; a live read whose generation a publish retired meanwhile reads the new live generation (up to 3 attempts).-- Tests: `test/large-pages/managed-sync-segmented-freeze.test.ts` (the live-checkout freeze, with its inline twin, and a page whose rows don't tile held while the rest of the commit imports), `test/sync-reconcile-db-only-segmented.test.ts` (2 MiB and over-24 MiB re-exports byte-equal to `gbrain export`, one failing page listed while the run advances, a plain-directory source), `test/segmented-read-concurrent-publish.test.ts` (a forced publish between a reader's statements). Every case but the plain-directory one fails on master.+- Tests: `test/large-pages/managed-sync-segmented-freeze.test.ts` (the live-checkout freeze, with its inline twin, and a page whose rows don't tile held while the rest of the commit imports), `test/sync-reconcile-db-only-segmented.test.ts` (2 MiB and over-24 MiB re-exports byte-equal to `gbrain export`, one failing page listed while the run advances, a plain-directory source, a write inside a transaction keeping the file's mode, a file over the scan cap left unbound, the derived skip), `test/segmented-read-concurrent-publish.test.ts` (a forced publish between a reader's statements). Every case but the plain-directory one fails on master.## [0.60.558.0] - 2026-11-03diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 028670a38d..7fb99b915c 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1414,8 +1414,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.553.0', id: 'empty_nonstring_args_gst927', text: 'Read tools now treat an optional argument as not provided when its own schema rules the value out: 0 where the range starts above zero (limit: 0, around_chunk_id: 0, schema_version: 0 and others), [] where the list must not be empty (types, only, traverse_graph hops), {} where the object needs a field (get_page lines and bytes), false on get_versions diff, and get_page context without grep. These calls used to refuse with invalid_params; now they answer as if the argument were left out. get_page known_as_of beside window or view arguments still refuses, and the refusal names the arguments to drop.' },// GBRA-283 Wave A (supersedes #8454): per-engine caches; release:restamp stamps since at the merge slot.{ since: '0.60.556.0', id: 'engine_keyed_caches_gbra283', text: 'A process serving several brains (mounts) now keeps each brain\'s search telemetry in that brain\'s own database and reads each brain\'s own search.track_retrieval, admission quotas, mcp.strict_params fallback, publication ceiling, capacity-notice throttle and the two vector-search rollback settings. Before, the first brain to be read decided these for every brain in the process, and every brain\'s search telemetry was written into the first brain\'s database. A process with one brain behaves as before.' },- { since: 'TBD', id: 'segmented_freeze_hold_gbra287', text: 'A managed sync whose freeze compares a Git-tracked page stored in segments with working-tree bytes that differ from the pinned commit now reads a page up to 24 MiB back whole, as its publication does, instead of refusing with `page_body_segmented` and stopping the source (`sync_blocked`) on every later sync. A page whose stored body cannot be read while it is frozen (`page_body_segmented` or `page_body_rows_unreadable`) is held `page_write_failed` with that code named, and the rest of the source syncs; `gbrain sync status` classifies both codes (`page_body_segmented`: public category `defect`, upgrade; `page_body_rows_unreadable`: `storage`, retry) instead of reporting an unknown code.' },- { since: 'TBD', id: 'segmented_reexport_gbra287', text: 'A full sync re-exports a DB-only page (#2426) stored in segments, streaming its file with the bytes `gbrain export` writes, instead of listing it as a `page_body_segmented` failure; a page whose re-export fails is returned in the result\'s `reexport_failures` and the run completes. Write-through of a page stored in segments with frontmatter overrides returns an error result instead of a `page_body_segmented` one. A segmented read whose page published a new body between its reads reads one generation (or the new live one) instead of refusing `page_body_rows_unreadable`.' },+ { since: 'TBD', id: 'segmented_freeze_hold_gbra287', text: 'A managed sync whose freeze compares a Git-tracked page stored in segments with working-tree bytes that differ from the pinned commit now reads a page up to 24 MiB back whole, as its publication does, instead of refusing with `page_body_segmented` and stopping the source (`sync_blocked`) on every later sync. A page whose stored body cannot be read while it is frozen (`page_body_segmented` or `page_body_rows_unreadable`) is held `page_write_failed` with that code named, and the rest of the source syncs; `gbrain sync status` classifies such a hold by that code (`page_body_segmented`: upgrade, a person; `page_body_rows_unreadable`: retry, no person needed) instead of as an unplaced `page_write_failed`.' },+ { since: 'TBD', id: 'segmented_reexport_gbra287', text: 'A full sync re-exports a DB-only page (#2426) stored in segments, streaming its file with the bytes `gbrain export` writes, instead of listing it as a `page_body_segmented` failure; a page whose re-export fails is returned in the result\'s `reexport_failures` and the run completes. Write-through of a page stored in segments keeps the existing file\'s mode, skips a file over the pre-push scan cap before binding `source_path`, and with frontmatter overrides returns an error result instead of a `page_body_segmented` one; the derived (generated-page) writer skips such a page (`segmented_page`). A segmented read whose page published a new body between its reads reads one generation (or the new live one) instead of refusing `page_body_rows_unreadable`.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/cycle/derived-write-through.ts b/src/core/cycle/derived-write-through.tsindex 6cd9f3f8fa..9b170a9363 100644--- a/src/core/cycle/derived-write-through.ts+++ b/src/core/cycle/derived-write-through.ts@@ -116,8 +116,10 @@ async function writeDerivedFile(engine: BrainEngine, slug: string, sourceId: strif (!file.ok) return { written: false, skipped: 'file_database_drift' };expectedFileBytes = file.expectedFileBytes;}- const [row] = await engine.executeRaw<{ source_path: string | null }>(- 'SELECT source_path FROM pages WHERE source_id = $1 AND slug = $2 AND deleted_at IS NULL', [sourceId, slug]);+ const [row] = await engine.executeRaw<{ source_path: string | null; body_storage: string }>(+ 'SELECT source_path, body_storage FROM pages WHERE source_id = $1 AND slug = $2 AND deleted_at IS NULL', [sourceId, slug]);+ // A page stored in segments has its file streamed without a string the batch rollback could compare (`after`).+ if (row?.body_storage === 'segmented') return { written: false, skipped: 'segmented_page' };const result = await writePageThrough(engine, slug, { sourceId, expectedFileBytes, deferCommit: true });if (result.error) console.error(`[write-through] ${slug}: ${result.error}`);if (!result.written || !result.path) return result;diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.tsindex d84e0c1765..a9edd1c45c 100644--- a/src/core/persistence/page-prepare.ts+++ b/src/core/persistence/page-prepare.ts@@ -217,6 +217,7 @@ export function readCanonicalAsImported(bytes: string, sourcePath: string): { co*/export async function fileMatchesSnapshot(engine: BrainEngine, slug: string, bytes: string, snapshot: PageSnapshot,sourcePath: string | (() => Promise<string>), activePack?: ParseOpts['activePack']): Promise<boolean> {+ snapshot = (await materializedSnapshot(engine, snapshot))!;const expected = digest(canonical({ ...snapshot.page, frontmatter: withoutSafetyAssessments(snapshot.page.frontmatter ?? {}) }, snapshot.tags));const matches = async (content: string, inferred: boolean) => {const parsed = parseMarkdown(content, slug, { activePack });diff --git a/src/core/persistence/sync-entry-fault.ts b/src/core/persistence/sync-entry-fault.tsindex 15a2b2a6dd..d934354a53 100644--- a/src/core/persistence/sync-entry-fault.ts+++ b/src/core/persistence/sync-entry-fault.ts@@ -27,6 +27,7 @@ import { LockStolenError } from '../db-lock.ts';import { RECOVERY_VERSION } from '../markdown.ts';import { VERSION } from '../../version.ts';import { isWriteCapacityWait } from './admission-retry.ts';+import { PAGE_BODY_FAULT_CODES } from './sync-fault-class.ts';import { gitBlobOid } from './digest.ts';import { readBlobBytes, type TreeBlob } from './sync-blobs.ts';import { readSyncFile, type SyncEntry } from './sync-discovery.ts';@@ -96,12 +97,6 @@ function runScoped(error: unknown): boolean {|| isRetryableConnError(error) || isStatementTimeoutError(error) || classifyItemFailure(error).scope !== 'item';}-/**- * GBRA-287: a stored page body this freeze could not read (`page_body_segmented`: a whole-body read of a page stored in- * segments; `page_body_rows_unreadable`: segment rows that do not tile the body) is that page's fault, never the run's.- */-const PAGE_BODY_FAULT_CODES: ReadonlySet<string> = new Set(['page_body_segmented', 'page_body_rows_unreadable']);-/*** S-63/S-64/S-33/S-7: the hold a throw while freezing one entry earns when holds are on, or null to rethrow it. A* `git_object_missing` or `path_not_utf8` refusal is held under its code; a page-body fault (`PAGE_BODY_FAULT_CODES`) is helddiff --git a/src/core/persistence/sync-fault-class.ts b/src/core/persistence/sync-fault-class.tsindex fe0a3bb232..e6c61858e6 100644--- a/src/core/persistence/sync-fault-class.ts+++ b/src/core/persistence/sync-fault-class.ts@@ -51,6 +51,13 @@ export const HOLD_ESCALATE_MS = 24 * 60 * 60 * 1000;export const STORAGE_ERROR_REPEATS = 2;const ESCALATE_AFTER = `${HOLD_ATTEMPTS_NEEDS_HUMAN} failed attempts over ${HOLD_ESCALATE_MS / 3_600_000} h`;+/**+ * GBRA-287: a stored page body a freeze could not read (`page_body_segmented`: a whole-body read of a page stored in+ * segments; `page_body_rows_unreadable`: segment rows that do not tile the body) is that page's fault, never the run's.+ * It is held `page_write_failed` (origin `freeze`) with this code in `meta.write_failure.code`, which classifies the hold.+ */+export const PAGE_BODY_FAULT_CODES: ReadonlySet<string> = new Set(['page_body_segmented', 'page_body_rows_unreadable']);+export const SYNC_FAULT_TABLE: ReadonlyArray<SyncFaultRule> = [// Page class: one entry, held; the run finished.{ code: 'worktree_dirty', class: 'page', safe_actions: ['retry_when_clean'], needs_human: false,diff --git a/src/core/persistence/sync-status.ts b/src/core/persistence/sync-status.tsindex 59553beea3..d4bf0555af 100644--- a/src/core/persistence/sync-status.ts+++ b/src/core/persistence/sync-status.ts@@ -29,7 +29,7 @@ import { managedSyncResumeArgs } from '../sync-reconcile.ts';import { readManagedSyncFailures, type ManagedSyncFailure } from './sync-failures.ts';import { outOfAttemptsHold, fenceAutoRepairFor, fileDriftSide, gitHoldFix, holdEscalation, noteHoldEdit, readGitSourceHolds, recordHoldAttempt, requestGitHoldRetry, type GitHoldRecord } from './sync-holds.ts';import type { FenceAutoRepair } from '../fence-repair/hold-fix.ts';-import { classifySyncFault, HOLD_ATTEMPTS_NEEDS_HUMAN, type SyncFaultVerdict } from './sync-fault-class.ts';+import { classifySyncFault, HOLD_ATTEMPTS_NEEDS_HUMAN, PAGE_BODY_FAULT_CODES, type SyncFaultVerdict } from './sync-fault-class.ts';import { CONTENT_REPAIR_KINDS, contentHoldDisposition, runContentLane, type ContentHoldDisposition } from '../repair/content-lane.ts';import { resolveRepairScope, type RepairKind, type RepairResult } from '../repair/core.ts';import type { RepairKindSpec } from '../repair/registry.ts';@@ -304,6 +304,8 @@ export function holdVerdict(record: GitHoldRecord, auto: FenceAutoRepair | undefif (record.code === 'origin_conflict' && record.meta.reason) return classifySyncFault({ code: record.code, detail: 'origin_conflict_decision', ...escalation });if (record.code === 'page_identity_changed') return classifySyncFault({ code: record.code, detail: 'page_identity_decision', ...escalation });if (record.code === 'file_drift' && fileDriftSide(record.meta) === 'unknown') return classifySyncFault({ code: record.code, detail: 'file_drift_unknown', ...escalation });+ const bodyFault = record.code === 'page_write_failed' ? record.meta.write_failure?.code : undefined;+ if (bodyFault && PAGE_BODY_FAULT_CODES.has(bodyFault)) return classifySyncFault({ code: record.code, detail: bodyFault, ...escalation });const disposition = contentHoldDisposition(record, auto);if (disposition.action !== 'listed' || disposition.state === 'owner') return classifySyncFault({ code: record.code, ...escalation, ...content });const verdict = classifySyncFault({ code: record.code, ...escalation, detail: disposition.reason, ...content });diff --git a/src/core/write-through.ts b/src/core/write-through.tsindex 7ed2e2180b..0f6aa8f38f 100644--- a/src/core/write-through.ts+++ b/src/core/write-through.ts@@ -28,6 +28,7 @@ import { atomicStagingPath, atomicWriteFileSync } from './atomic-write.ts';import { flushDirectory } from './fs-durable.ts';import { isSegmentedPage } from './page-body/page-shape.ts';import type { BrainEngine } from './engine.ts';+import type { StreamedFileContent } from './persistence/large-file.ts';import { isRelativeFileUri, serializePageToMarkdown, resolvePageFilePath, resolveSourceLocalFilePath } from './markdown.ts';import { isWriteTargetContained, msysToNativePath } from './path-confine.ts';import { readSlugRootMode, resolveSlugRootMode, type SlugRootMode } from './sync-anchor.ts';@@ -474,9 +475,11 @@ 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' };// 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') > PUSH_SCAN_MAX_FILE_BYTES) {+ if ((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' };}@@ -522,13 +525,7 @@ export async function writePageThrough(const verify = () => { assertSourceFilesystemActive(); if (fileChanged()) throw changedWhileStaging; };try {if (md !== null) atomicWriteFileSync(filePath, md, { verify });- else {- const streamed = await writeSegmentedPageFile(engine, slug, sourceId, filePath, verify);- if (streamed === 'over_push_scan_cap') {- 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)`);- }- if (streamed !== 'written') return { written: false, skipped: streamed };- }+ else await writeStreamedFile(engine, filePath, streamed!, verify);} catch (error) {if (error === changedWhileStaging) return { written: false, skipped: 'file_changed' };throw error;@@ -568,32 +565,37 @@ export async function writePageThrough(}/**- * The file of a page stored in segments, with the bytes `gbrain export` writes for it: measured and streamed from its- * segments in one repeatable-read snapshot, so a body published meanwhile is never mixed in, through the streamed staging- * writer the withdrawal mirror and restore_page use (stageStreamedContent: an in-progress name, renamed once whole), then- * renamed over `filePath` after `verify`. Never held as one string, whatever its size.+ * The file of a page stored in segments, with the bytes `gbrain export` writes for it: measured from the segments of+ * the generation its snapshot names (unreadPageFile), as a segmented publication prepares its file, so it is sized+ * before anything is bound or written. Null when the page is gone. Read on `engine` as given, so a caller inside a+ * transaction (an owner repair) reads the rows it just wrote.*/-async function writeSegmentedPageFile(engine: BrainEngine, slug: string, sourceId: string, filePath: string,- verify: () => void): Promise<'written' | 'over_push_scan_cap' | 'page_not_found_after_write'> {- const [{ unreadPageFile }, { stageStreamedContent }] = await Promise.all([import('./persistence/page-prepare.ts'), import('./persistence/large-file.ts')]);- return engine.transaction(async tx => {- await tx.executeRaw('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY');- const snapshot = await tx.readPageSnapshot(slug, { sourceId });- if (!snapshot) return 'page_not_found_after_write';- const content = await unreadPageFile(tx, snapshot);- if (content.bytes > PUSH_SCAN_MAX_FILE_BYTES) return 'over_push_scan_cap';- const stage = { path: atomicStagingPath(filePath), bytes: content.bytes, hash: content.hash };- await stageStreamedContent(tx, filePath, content, stage, null);- try {- verify();- renameSync(stage.path, filePath);- } catch (error) {- rmSync(stage.path, { force: true });- throw error;- }- flushDirectory(dirname(filePath));- return 'written';- });+async function segmentedPageFile(engine: BrainEngine, slug: string, sourceId: string): Promise<StreamedFileContent | null> {+ const { unreadPageFile } = await import('./persistence/page-prepare.ts');+ const snapshot = await engine.readPageSnapshot(slug, { sourceId });+ return snapshot ? unreadPageFile(engine, snapshot) : null;+}++/**+ * Streams measured file content to `filePath` through the staging writer the withdrawal mirror and restore_page use+ * (stageStreamedContent: an in-progress name, renamed once whole; bytes that are not the measured ones refuse as+ * `revision_conflict`), keeping an existing file's mode as atomicWriteFileSync does, then renames it over `filePath`+ * after `verify`. Never held as one string, whatever its size.+ */+async function writeStreamedFile(engine: BrainEngine, filePath: string, content: StreamedFileContent, verify: () => void): Promise<void> {+ const { stageStreamedContent } = await import('./persistence/large-file.ts');+ let mode: number | null = null;+ try { if (existsSync(filePath)) mode = statSync(filePath).mode & 0o7777; } catch { /* stat raced a delete: default mode */ }+ const stage = { path: atomicStagingPath(filePath), bytes: content.bytes, hash: content.hash };+ await stageStreamedContent(engine, filePath, content, stage, mode);+ try {+ verify();+ renameSync(stage.path, filePath);+ } catch (error) {+ rmSync(stage.path, { force: true });+ throw error;+ }+ flushDirectory(dirname(filePath));}export interface DeleteThroughResult {diff --git a/test/large-pages/managed-sync-segmented-freeze.test.ts b/test/large-pages/managed-sync-segmented-freeze.test.tsindex d15dac2832..d0f0d54222 100644--- a/test/large-pages/managed-sync-segmented-freeze.test.ts+++ b/test/large-pages/managed-sync-segmented-freeze.test.ts@@ -88,6 +88,9 @@ test('a segmented page whose rows do not tile its body is held at the freeze; thexpect(result.failures).toBeUndefined();expect((result.held ?? []).map(hold => [hold.path, hold.code])).toEqual([['people/person-example.md', 'page_write_failed']]);expect(result.held![0]!.message).toContain('page_body_rows_unreadable');+ const { readSyncStatus } = await import('../../src/core/persistence/sync-status.ts');+ expect((await readSyncStatus(engine, f.sourceId, { detail: false })).holds).toEqual([expect.objectContaining({ code: 'page_write_failed',+ path: 'people/person-example.md', needs_human: false, safe_actions: ['retry'] })]);const [other] = await engine.executeRaw<{ compiled_truth: string }>("SELECT compiled_truth FROM pages WHERE source_id=$1 AND slug='people/other-example'", [f.sourceId]);expect(other!.compiled_truth).toContain('second');expect(await engine.executeRaw('SELECT last_commit FROM sources WHERE id=$1', [f.sourceId])).toEqual([{ last_commit: git(f.root, 'rev-parse', 'HEAD') }]);diff --git a/test/sync-reconcile-db-only-segmented.test.ts b/test/sync-reconcile-db-only-segmented.test.tsindex c6e3bfe722..0a5bb10d79 100644--- a/test/sync-reconcile-db-only-segmented.test.ts+++ b/test/sync-reconcile-db-only-segmented.test.ts@@ -12,7 +12,7 @@* 3. PGLite.*/import { afterAll, beforeAll, beforeEach, afterEach, describe, expect, test } from 'bun:test';-import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import { PGLiteEngine } from '../src/core/pglite-engine.ts';@@ -21,8 +21,11 @@ import { gitExec } from './helpers/git-exec.ts';import { importFromFile } from '../src/core/import-file.ts';import { readPageBodyPolicy, SEGMENT_MAX_BYTES } from '../src/core/page-body/limits.ts';import { largeFileWork } from '../src/core/persistence/large-file.ts';-import { PAGE_MAX_BYTES } from '../src/core/page-size-policy.ts';+import { PAGE_MAX_BYTES, PUSH_SCAN_MAX_FILE_BYTES } from '../src/core/page-size-policy.ts';import { parseMarkdown, serializePageToMarkdown } from '../src/core/markdown.ts';+import { writePageThrough } from '../src/core/write-through.ts';+import { fileMatchesSnapshot } from '../src/core/persistence/page-prepare.ts';+import { writeDerivedPageThrough } from '../src/core/cycle/derived-write-through.ts';let engine: PGLiteEngine;let dir: string;@@ -133,6 +136,43 @@ describe('GBRA-287: full-sync re-export of a DB-only page stored in segments', (expect(stagingLeft(repoPath)).toEqual([]);}, 300_000);+ test('a caller inside a transaction (an owner repair) writes the file of a segmented page, keeping its mode', async () => {+ expect(['first_sync', 'synced']).toContain((await fullSync()).status);+ await dbOnlySegmented('memories/big', 2 * 1024 * 1024);+ await fullSync();+ const file = join(repoPath, 'memories/big.md');+ chmodSync(file, 0o600);+ const result = await engine.transaction(async tx => {+ await tx.executeRaw('SELECT 1');+ return writePageThrough(tx, 'memories/big', { sourceId: 'default' });+ });+ expect(result).toMatchObject({ written: true });+ expect(statSync(file).mode & 0o777).toBe(0o600);+ expect(readFileSync(file).equals(await exportedBytes('memories/big'))).toBe(true);+ const snapshot = await engine.readPageSnapshot('memories/big', { sourceId: 'default' });+ expect(await fileMatchesSnapshot(engine, 'memories/big', readFileSync(file, 'utf8'), snapshot!, 'memories/big.md')).toBe(true);+ expect(stagingLeft(repoPath)).toEqual([]);+ }, 180_000);++ test('a segmented page whose file would pass the pre-push scan cap is skipped before its source_path is bound', async () => {+ expect(['first_sync', 'synced']).toContain((await fullSync()).status);+ await dbOnlySegmented('memories/huger', PUSH_SCAN_MAX_FILE_BYTES + 256 * 1024);+ await engine.executeRaw("UPDATE pages SET source_path=NULL WHERE slug='memories/huger'");+ expect(await writePageThrough(engine, 'memories/huger', { sourceId: 'default' })).toEqual({ written: false, skipped: 'over_push_scan_cap' });+ const [row] = await engine.executeRaw<{ source_path: string | null }>("SELECT source_path FROM pages WHERE slug='memories/huger'");+ expect(row!.source_path).toBeNull();+ expect(existsSync(join(repoPath, 'memories/huger.md'))).toBe(false);+ expect(stagingLeft(repoPath)).toEqual([]);+ }, 600_000);++ test('the derived writer skips a generated page stored in segments instead of writing a file its rollback cannot compare', async () => {+ expect(['first_sync', 'synced']).toContain((await fullSync()).status);+ await dbOnlySegmented('concepts/big', 2 * 1024 * 1024);+ await engine.executeRaw("UPDATE pages SET source_path=NULL WHERE slug='concepts/big'");+ expect(await writeDerivedPageThrough(engine, 'concepts/big', 'default')).toEqual({ written: false, skipped: 'segmented_page' });+ expect(existsSync(join(repoPath, 'concepts/big.md'))).toBe(false);+ }, 180_000);+test('a repo-less (plain directory) source re-exports nothing and keeps the page', async () => {const plain = join(dir, 'plain');mkdirSync(join(plain, 'topics'), { recursive: true });