Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(repair): release a held file that agrees from a --slug preview; an empty preview's apply applies nothing (#7950)
garrytan8a25399fa5df
diff --git a/docs/guides/repair.md b/docs/guides/repair.mdindex 0e1d85f964..7be483b047 100644--- a/docs/guides/repair.md+++ b/docs/guides/repair.md@@ -2524,8 +2524,12 @@ file lacks and database-only timeline rows, and refuseswould change anything else.A held page whose page and file agree now is listed `release_hold` under-either `--prefer`: its apply writes nothing to the page or the file, and only-asks the next sync to re-screen the file, which releases the hold. Page and+either `--prefer`, whether `--held` or `--slug` selected it: its apply writes+nothing to the page or the file, and only asks the next sync to re-screen the+file, which releases the hold. The apply rechecks the page, the file and the+hold the preview observed, and answers `changed_since_preview` when any of+them changed. A preview that finds nothing still prints an apply command; it+applies nothing. Page andfile agree when they differ only in formatting sync does not import (frontmatterkey order or quoting). An apply refused before it published reserves no requestid, so the apply a fresh preview prints goes through. A page withdiff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsvindex fb65ec3db2..35a3a3a3dd 100644--- a/scripts/module-size-limits.tsv+++ b/scripts/module-size-limits.tsv@@ -47,4 +47,4 @@ src/commands/doctor/checks/extraction-sync.ts 1500 ratchet +7 GBRA-130 A-1: linksrc/core/search/evidence-delivery.ts 1755 ratchet +5 W5: EvidencePlan.rankCut resolved with the plan (logic in search/page-rank-cut.ts); +20 W5 whole_pages: wholeCost prices a block as delivery would emit it whole (needs the private Block/enrichBlock internals) and the cut is wired before allocate (cutWholePages lives in search/page-rank-cut.ts); new row: crossed the 1500 unlisted cap at the #6367 merge (master 1479, its explicit-budget cap) by the C1 date header threaded through every block path, cap included; pagePlanHits (search/page-plan-hits.ts) and the header loader (evidence-date.ts blockDateHeaders) were peeled first; peel candidate: allocateCapped; +8 at the #6396 merge: page evidence text cut through the fence-chunk trust overlay and the caller minTrust floor (re-summed: our 1504 + master +8); +119 Cat 40 next wave F2: the search.long_page_unit policy (withLongPagePolicy, selectLongPages size preflight with page/byte/deadline limits) and the long-page fetch and fallback in deliverEvidence, kept in the shared seam the plan names (gbrain-evals docs/plans/2026-10-11-cat40-next-wave, F2); +17 F2 rework to the frozen-comparison policy: search.long_page_min_chars (rendered-body characters, default 20,000) read in withLongPagePolicy, a character count in the preflight, the rendered-body confirmation in deliverEvidence, and the long-page row exemption in capDeliveredSnippets (re-summed at the 0.60.225.0 merge: master 1537 + F2 136); +39 Wave B PR 2 lane 2b: planSegmentedBlock joins the windows search/segmented-evidence.ts reads around a segmented page's hits into one run-marked document (needs the private Doc/Piece/buildDoc/locateAnchor internals), planBlock's unit cut split into blockFromDoc for both, sections bounded by their run, selectionCost counts a gap between runs, and the fetch skips the whole-body fence overlay for a segmented page; +4 segmented pages read at once before planning (segmentedReads; the read is search/segmented-evidence.ts, the statements page-body/read-range.ts); +17 GBRA-156: tail trim plan flag, DeliverOptions.query, DeliveryMeta.tail_trim, the trim call and the frozen-hit score/query library fields (logic in search/evidence-tail-trim.ts; interface fields cannot move); +7 GBRA-205: EvidencePlan.titleHeader and DeliveryMeta.title_header (interface fields cannot move) and the titles option on the header loader (logic in search/evidence-date.ts; the query budget key lives in search/evidence-packing.ts); +11 #7600: assemble_evidence quotes conversation rows and capEvidenceToBudget counts the quote fence (logic in search/transcript-quote.ts); +2 GBRA-156 /ship review: the cut-path admission and title room count the quote fence; +2 GBRA-156 /ship review pass 2: capEvidenceToBudget counts the fence only for the paths that fence (quote flag; recall counts the text as returned)src/commands/config.ts 1524 ratchet new row: crossed the 1500 unlisted cap in wave 15 P7.4 #5461: set-time validation of think.pages_budget_chars / think.excerpt_ceiling_chars (range + parser live in core/think/pages-budget.ts), mirroring the cycle.consolidate.cluster_threshold hook; +1 wave 16 G5.1 (#6495): set-time refusal hook for search.keyword_statement_timeout_ms (check lives in commands/config/keyword-timeout-value.ts); +1 wave 18b lane 5 (#5012 item 6): search.contextual_retrieval prints the existing-pages hint after the write (text lives in commands/config/contextual-mode-hint.ts); +1 #6712 PR 2: retired/rollback sync key dispatch line (logic in core/sync-config-keys.ts handleSyncKeyConfig); +1 #6865: sync.slug_conflicts.auto_remove boolean validation at set time (refusal text in repair/slug-autoheal.ts); +1 #6948: sync.origin_twins.auto_resolve boolean validation at set time (refusal text in repair/origin-twins-heal.ts); +2 #6795: config set chat_model/expansion_model help line and the model-pin import (shadow report and file-pin unset live in commands/config/model-pin-shadow.ts); +1 #6712 PR 4b: sync.admission set-time hook (value logic in commands/config/sync-admission-value.ts); +4 #7130: set-time refusal hook for sync.max_deletes / sync.max_delete_ratio (and .source.<id>) / purge.retention_hours (check lives in core/sync-reconcile.ts deleteSafetyConfigRefusal); +1 GBRA-150: sync.metafile_pages set-time route (body in config/sync-metafile-pages-value.ts); re-summed at the v0.60.330.0 merge (1520 measured); +2 #7242 minions.terminal_hook file-plane key and its set branch (logic in minions/terminal-hook.ts); +1 GBRA-161: generations.* set-time route (refusal in commands/config/generations-values.ts); +1 GBRA-207 #7630: sync.repo_path set-time refusal hook (refusal in core/sync-config-keys.ts syncRepoPathRefusal)src/commands/mcp-expose.ts 1519 ratchet hosted_option: Session carries the gbrain.io coaching notice on the first-receipt run and Tailscale/service friction exits (copy, refs and gating live in core/onboard/hosted-option.ts); +7 GBRA-199: --surface help lines, surfaceChosen option field and the advertise pass-through (registrationAdvertise in core/mcp-registration.ts)-src/core/behavior-change-notice.ts 1574 ratchet the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +2 GBRA-205 saved_facts_stems row and its comment (re-summed at the #7901 0.60.492.0 merge: 1541 + 2); +2 GBRA-205 search.query_facts_block default-on row and its approval comment (re-summed at the #7610 0.60.490.0 merge: 1539 + 2); +2 the #7900 content checkpoint host-move row (since TBD until the merge slot), +2 the #7897 private-hold sweep row (since TBD until the merge slot), +2 the #7880 ingest_capture and company-brain private-hold row (since TBD until the merge slot), +5 the frozen-source wave comment and four rows (#7868, #7850, #7869/#7870, #7871), +2 the #7848 visibility_noncanonical hold row (since TBD until the merge slot), +2 the #7846 extract_atoms session-source row (re-summed at the 0.60.481.0 merge: master 1524 + 2), +2 the #7805 synthesize session-source and #7841 visibility_not_applied rows (re-summed at the 0.60.480.0 merge: master 1522 + 2), +2 strict door planned-state row (#7705, re-summed at the 0.60.470.0 merge: master 1514 + 2), +2 Bun floor 1.4.4 row (#7644), the GBRA-95 RLS backfill row (+2), +3 rows for #7596 pass_interrupted, #7599 read-only serve and the --access=read-only ceiling, +1 G5 lane C trust_release row, +1 #7619 cli_flag_equals, +3 GBRA-207 #7630 relative-anchor and stalled-write rows, +2 the #7632 function search_path disclosure row and +2 the #7679 orphaned worktree refresh row (re-summed at the 0.60.471.0 merge: master 1516 + 2), +2 the #7814 retired v0.13.1 grandfather row, +2 the #7618 conversion withhold/progress/push row (master 1520 + 2); the behavior-change table split (#7607) retires this row; +4 GBRA-188 #7489: the wave comment and three rows (brain-first instructions, starter surface default, per-turn rule); +1 GBRA-188 plugin_turn_hook_gbra188 row; +1 GBRA-242 provider_key_rules_7959 row (#7959), +2 the GBRA-199 registration_lists_verbs row (since TBD until the merge slot); +2 GBRA-133 #7652: the #7611 pass_abandoned reader row and the lean read-only serve socket row (re-summed at the 0.60.503.0 merge: master 1555 + 2); +1 GBRA-243: the per-turn hook disclosure row (rows are data and cannot move); +4 GBRA-156 #7598 harness wave comment and rows (remote page cap, sources_not_readable refusal, sources add next step); +4 GBRA-156 #7601 search_quotes_transcript_rows comment and row; +1 GBRA-175 #7475 autopilot_restarts_serve_7475 row (re-summed at the #8012 merge: 1566 + 1); +3 #7997/#8014/#8015 rows (redaction markers, company db_only keep, ignored supabase_only scope); +2 #7199 (re-port of #7228) classic_drift_rescreen_7199 comment and row; +2 #7931 file_drift_agrees_7931 comment and row+src/core/behavior-change-notice.ts 1575 ratchet the BEHAVIOR_CHANGES table grows by one row per disclosed change: +4 the #7891 provenance-drift and #7917/#7918 maintenance-lowering rows and their comments (re-summed at the 0.60.495.0 merge: 1547 + 4); +2 GBRA-205 saved_facts_stems row and its comment (re-summed at the #7901 0.60.492.0 merge: 1541 + 2); +2 GBRA-205 search.query_facts_block default-on row and its approval comment (re-summed at the #7610 0.60.490.0 merge: 1539 + 2); +2 the #7900 content checkpoint host-move row (since TBD until the merge slot), +2 the #7897 private-hold sweep row (since TBD until the merge slot), +2 the #7880 ingest_capture and company-brain private-hold row (since TBD until the merge slot), +5 the frozen-source wave comment and four rows (#7868, #7850, #7869/#7870, #7871), +2 the #7848 visibility_noncanonical hold row (since TBD until the merge slot), +2 the #7846 extract_atoms session-source row (re-summed at the 0.60.481.0 merge: master 1524 + 2), +2 the #7805 synthesize session-source and #7841 visibility_not_applied rows (re-summed at the 0.60.480.0 merge: master 1522 + 2), +2 strict door planned-state row (#7705, re-summed at the 0.60.470.0 merge: master 1514 + 2), +2 Bun floor 1.4.4 row (#7644), the GBRA-95 RLS backfill row (+2), +3 rows for #7596 pass_interrupted, #7599 read-only serve and the --access=read-only ceiling, +1 G5 lane C trust_release row, +1 #7619 cli_flag_equals, +3 GBRA-207 #7630 relative-anchor and stalled-write rows, +2 the #7632 function search_path disclosure row and +2 the #7679 orphaned worktree refresh row (re-summed at the 0.60.471.0 merge: master 1516 + 2), +2 the #7814 retired v0.13.1 grandfather row, +2 the #7618 conversion withhold/progress/push row (master 1520 + 2); the behavior-change table split (#7607) retires this row; +4 GBRA-188 #7489: the wave comment and three rows (brain-first instructions, starter surface default, per-turn rule); +1 GBRA-188 plugin_turn_hook_gbra188 row; +1 GBRA-242 provider_key_rules_7959 row (#7959), +2 the GBRA-199 registration_lists_verbs row (since TBD until the merge slot); +2 GBRA-133 #7652: the #7611 pass_abandoned reader row and the lean read-only serve socket row (re-summed at the 0.60.503.0 merge: master 1555 + 2); +1 GBRA-243: the per-turn hook disclosure row (rows are data and cannot move); +4 GBRA-156 #7598 harness wave comment and rows (remote page cap, sources_not_readable refusal, sources add next step); +4 GBRA-156 #7601 search_quotes_transcript_rows comment and row; +1 GBRA-175 #7475 autopilot_restarts_serve_7475 row (re-summed at the #8012 merge: 1566 + 1); +3 #7997/#8014/#8015 rows (redaction markers, company db_only keep, ignored supabase_only scope); +2 #7199 (re-port of #7228) classic_drift_rescreen_7199 comment and row; +2 #7931 file_drift_agrees_7931 comment and row; +1 #7950 file_drift_slug_release_7950 rowdiff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex a726cf5636..0250848b7f 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1376,6 +1376,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.516.0', id: 'classic_drift_rescreen_7199', text: 'A `file_drift` hold with side `unknown` that an older gbrain wrote before sync compared a record-less page with its file at the last synced commit is now compared once more, also with the file\'s last three earlier committed versions, and imports when the page equals one of them; otherwise it stays held and is not re-screened again. Such a hold now names what the page was compared with, and `gbrain sync status` lists it under its own verdict (`file_drift_unknown`, needs a person). A managed sync that holds files a person must decide now reports `reason: held_needs_human` with `held_needs_human: <count>` (JSON) and prints `Synced; N file(s) held for a person (gbrain sync status --source <id>).`; the source still syncs and its status stays `synced`.' },// #7931 parts 2 and 3. since is stamped at the merge slot.{ since: '0.60.516.0', id: 'file_drift_agrees_7931', text: 'A managed sync no longer holds a file as `file_drift` when its page agrees with it as `gbrain repair file-drift` reads them (they differ only in how the file writes the page, such as YAML quoting, or in a reserved key an older import kept in the database copy): the file imports. A held file someone asks to re-screen (`gbrain sources retry-held`, or the apply of a `release_hold` preview) whose page has no import record is now screened again instead of staying held, so an agreeing page is released. A `gbrain repair file-drift --apply` refused before it published no longer makes the apply after a fresh preview with the same `--expect` answer `idempotency_conflict`.' },+ { since: '0.60.516.0', id: 'file_drift_slug_release_7950', text: '`gbrain repair file-drift --slug <s>` now lists a held page whose file agrees with it as `release_hold` (it was `no_drift`, and its printed apply always refused `preview_changed`); the apply releases only the hold the preview observed and answers `changed_since_preview` when that hold was replaced. A preview that finds nothing to apply prints an apply command that now applies nothing instead of refusing `preview_changed`.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/repair/file-drift.ts b/src/core/repair/file-drift.tsindex cb7df52a88..f89e941fd5 100644--- a/src/core/repair/file-drift.ts+++ b/src/core/repair/file-drift.ts@@ -74,7 +74,7 @@ import { protectedReconcileKey, reconcileCanonical, RECONCILE_SCAN_KEYS, type Reimport { fileWinsContent } from '../persistence/file-wins-content.ts';import { ABSENT_FILE_HASH, canonicalDeletionState, missingFileRoute, readCanonicalFileText, readDeletedDriftTarget, readReconcileState, type DeletedDriftChange, type DeletedDriftTarget, type ReconcileArtifact } from '../persistence/reconcile-state.ts';import { sourceDbOnlyVerdict } from '../persistence/source-storage.ts';-import { clearGitHold, fileDriftActionVerb, fileDriftSide, FILE_DRIFT_DELETED_STATES, FILE_DRIFT_SIDES, GIT_HOLD_OP, heldDriftPreviewArgv, requestGitHoldRetry, type FileDriftDeletedState, type FileDriftSide, type GitHoldRecord } from '../persistence/sync-holds.ts';+import { clearGitHold, readGitHold, fileDriftActionVerb, fileDriftSide, FILE_DRIFT_DELETED_STATES, FILE_DRIFT_SIDES, GIT_HOLD_OP, heldDriftPreviewArgv, requestGitHoldRetry, type FileDriftDeletedState, type FileDriftSide, type GitHoldRecord } from '../persistence/sync-holds.ts';import { prepareRepairPublication, repairScreenConfig, submitManagedFileRepair } from '../persistence/file-repair.ts';import { maintenancePreflight, submitDatabaseMaintenanceIntent, submitMaintenanceIntent } from '../persistence/prepared-maintenance.ts';import type { PreparedMutation } from '../persistence/coordinator.ts';@@ -125,8 +125,11 @@ export interface ImportFilePage { slug: string; prefer: 'file'; exceptions: Drif*/export interface DetachPin { path: string; page_id: number; revision: string; observed_at: string }export interface DetachPage { slug: string; prefer: 'database'; exceptions: DriftException[]; detach_page: DetachPin }-/** GBRA-133: a held page whose page and file agree now; the apply asks the next sync to re-screen (and so release) its hold. */-export interface ReleasePin { path: string; incarnation: string; revision: string; file_hash: string | null }+/**+ * GBRA-133: a held page whose page and file agree now; the apply asks the next sync to re-screen (and so release) its hold.+ * #7950: bound to the hold the preview observed (`observed_at`), whichever selection (`--held` or `--slug`) found it.+ */+export interface ReleasePin { path: string; incarnation: string; revision: string; file_hash: string | null; observed_at: string }export interface ReleasePage { slug: string; prefer: DriftSide; exceptions: DriftException[]; release_hold: ReleasePin }type PlannedPage = ArtifactPage | SoftDeletePage | RemoveFilePage | ImportFilePage | DetachPage | ReleasePage;/** #6712 PR 4b: one held `file_drift` page a `--held` selection resolves. */@@ -683,6 +686,11 @@ async function applyDeletedSide(ctx: OperationContext, page: ApprovedPage, artif/** GBRA-133: re-checks a held page whose page and file agreed at the preview and schedules its re-screen (`sources retry-held` for one path). */async function releaseAgreedHold(engine: BrainEngine, page: ApprovedPage, pin: ReleasePin, requestId: string): Promise<RepairItemOutcome> {+ const hold = await readGitHold(engine, page.source_id, pin.incarnation, pin.path);+ if (hold?.observed_at !== pin.observed_at) {+ return { applied: false, outcome: 'changed_since_preview', reason: 'hold_changed',+ detail: { request_id: requestId, action: 'release_hold', message: `The hold on ${pin.path} changed since the preview; preview it again.` } };+ }const live = await liveFileDrift(engine, page.source_id, page.slug);if (live.reason !== 'agrees' || live.db_revision !== pin.revision || (live.file_hash ?? null) !== pin.file_hash) {return { applied: false, outcome: 'changed_since_preview', reason: 'revision_conflict',@@ -719,7 +727,8 @@ export const fileDriftRepair: RepairHandler = {if (opts.apply) {if (!opts.expect) throw new OperationError('invalid_params', 'gbrain repair file-drift --apply applies only the set a preview printed.',`Preview first: ${command} — then run the apply command it prints with --expect <preview-hash>.`, 'docs/guides/repair.md#explicit-only-repair-kinds');- const approved = await loadApprovedSet<ApprovedPage>(engine, { command: 'file-drift', hash: opts.expect, previewCommand: command });+ const approved = await loadApprovedSet<ApprovedPage>(engine, { command: 'file-drift', hash: opts.expect, previewCommand: command,+ emptyHash: async () => previewHash({ kind: 'file-drift-v1', brain_id: scope.brain_id, source_id: sourceId, selection, pages: [] }) });if (approved.items.some(page => page.selection !== selection || page.source_id !== sourceId)) throw previewChangedError(opts.expect, command);// #6712 wave: soft deletes of pages whose file is gone honor the sync mass-delete valve, as `repair ghost-pages` does.if (opts.prefer === 'file' && approved.items.length > MASS_RECONCILE_MIN_PAGES * MASS_RECONCILE_RATIO) {@@ -756,6 +765,7 @@ export const fileDriftRepair: RepairHandler = {const targets: Array<{ slug: string | null; held?: HeldTarget }> = held ? held.targets.slice(0, HELD_WINDOW_PAGES).map(target => ({ slug: target.hold.slug, held: target })) : slugs.map(slug => ({ slug }));const windowEnd = Math.min(Date.now() + HELD_WINDOW_BUDGET_MS, opts.deadline ?? Infinity);let previewed = 0;+ const [source] = held ? [] : await engine.executeRaw<{ incarnation: string }>('SELECT incarnation::text AS incarnation FROM sources WHERE id=$1', [sourceId]);opts.progress?.start('repair.file_drift.preview', targets.length);await asLocalCli(engine, async () => {for (const { slug: targetSlug, held: target } of targets) {@@ -793,8 +803,11 @@ export const fileDriftRepair: RepairHandler = {continue;}if (!opts.allDrifted && !opts.held && !selectedByGlobs(live.path, opts)) { count('not_selected'); continue; }- if (target && live.reason === 'agrees' && live.db_revision) {- pages.push({ slug, prefer: opts.prefer, exceptions: [], release_hold: { path: target.hold.path, incarnation: target.hold.incarnation, revision: live.db_revision, file_hash: live.file_hash ?? null } });+ const agreedHold = live.reason !== 'agrees' || !live.db_revision ? null : target?.hold+ ?? (source && live.path ? await readGitHold(engine, sourceId, source.incarnation, live.path) : null);+ if (agreedHold?.code === 'file_drift' && live.db_revision) {+ pages.push({ slug, prefer: opts.prefer, exceptions: [], release_hold: { path: agreedHold.path, incarnation: agreedHold.incarnation, revision: live.db_revision,+ file_hash: live.file_hash ?? null, observed_at: agreedHold.observed_at } });listing.push({ item: `${sourceId}:${slug}`, class: 'release_hold', detail: 'the page and its file agree now; the apply asks the next sync to re-screen the file, which releases the hold' });continue;}@@ -821,7 +834,7 @@ export const fileDriftRepair: RepairHandler = {const nextCommand = nextCursor ? previewCommand(sourceId, { ...opts, cursor: nextCursor }) : undefined;if (remaining > 0) residuals.after_window = remaining;const hash = previewHash({ kind: 'file-drift-v1', brain_id: scope.brain_id, source_id: sourceId, selection,- pages: pages.map(page => 'release_hold' in page ? [page.slug, page.release_hold.revision, page.release_hold.file_hash, 'release_hold', page.release_hold.path]+ pages: pages.map(page => 'release_hold' in page ? [page.slug, page.release_hold.revision, page.release_hold.file_hash, 'release_hold', page.release_hold.path, page.release_hold.observed_at]: 'soft_delete' in page ? [page.slug, page.soft_delete.ghost.revision, ABSENT_FILE_HASH, 'soft_delete']: 'detach_page' in page ? [page.slug, page.detach_page.revision, ABSENT_FILE_HASH, 'detach_page', page.detach_page.page_id, page.detach_page.observed_at]: 'remove_file' in page ? [page.slug, page.remove_file.revision, page.remove_file.raw_file_hash, 'remove_file', page.remove_file.state, page.remove_file.marker_digest]diff --git a/test/repair-file-drift-held-6712.test.ts b/test/repair-file-drift-held-6712.test.tsindex 2474a3c8d7..37d9591bdd 100644--- a/test/repair-file-drift-held-6712.test.ts+++ b/test/repair-file-drift-held-6712.test.ts@@ -28,6 +28,7 @@ import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';import { gitBlobOid } from '../src/core/persistence/digest.ts';import { SYNC_ORIGIN_DELETED_OP } from '../src/core/persistence/sync-pass-row.ts';import { gitHoldItem, readGitHold, writeGitHold, type FileDriftDeletedState, type FileDriftSide } from '../src/core/persistence/sync-holds.ts';+import { performManagedSync } from '../src/core/persistence/sync-run.ts';import { repairRunner } from '../src/core/repair/registry.ts';import { resolveRepairScope } from '../src/core/repair/core.ts';import { withEnv } from './helpers/with-env.ts';@@ -97,6 +98,9 @@ for (const backend of testBackends()) describe(`#6712 PR 4b: repair file-drift -(await repairRunner(engine, { apply: opts.expect !== undefined, logger })).run('file-drift', await resolveRepairScope(engine, sourceId),{ explicit: true, sourceFlag: sourceId, held: true, prefer: opts.prefer, ...(opts.side ? { side: opts.side } : {}), ...(opts.state ? { state: opts.state } : {}),...(opts.only ? { only: opts.only } : {}), ...(opts.expect ? { expect: opts.expect } : {}) });+ const runSlug = async (sourceId: string, slug: string, expectHash?: string) =>+ (await repairRunner(engine, { apply: expectHash !== undefined, logger })).run('file-drift', await resolveRepairScope(engine, sourceId),+ { explicit: true, sourceFlag: sourceId, slugs: [slug], prefer: 'file', ...(expectHash ? { expect: expectHash } : {}) });const refusal = async (promise: Promise<unknown>) => { try { await promise; } catch (error) { return error as OperationError; } throw new Error('expected a refusal'); };/** A soft-deleted page whose file then changed: the tombstone_edited Decision. */@@ -139,6 +143,43 @@ for (const backend of testBackends()) describe(`#6712 PR 4b: repair file-drift -const marker = async (f: Fixture, path: string) => (await engine.executeRaw('SELECT 1 FROM op_checkpoints WHERE op=$1 AND fingerprint=$2',[SYNC_ORIGIN_DELETED_OP, `${f.sourceId}:${f.incarnation}:${path}`])).length > 0;+ // #7950: a held page whose file agrees was listed no_drift by a --slug preview, whose printed apply always refused as+ // "preview changed": the preview hashed a set the apply could never load. It now enters the approval set as release_hold, and+ // the apply rechecks the page revision, the file and the observed hold before it schedules the re-screen that releases it.+ test('#7950: a --slug preview of a held page whose file agrees approves release_hold, and its apply makes the next sync release the hold', () => fixture(async f => {+ await put(f.ctx, 'notes/agrees', 'Same content on both sides.');+ commitAll(f.root, 'page');+ const path = 'notes/agrees.md';+ const live = (await snapshot(f.sourceId, 'notes/agrees'))!;+ await hold(f, { path, slug: 'notes/agrees', pageId: Number(live.page.id), side: 'unknown', revision: live.revision });+ const preview = await runSlug(f.sourceId, 'notes/agrees');+ expect(preview).toMatchObject({ mode: 'dry_run', affected: 1 });+ expect(preview.details!.pages).toEqual([expect.objectContaining({ slug: 'notes/agrees', action: 'release_hold', path })]);+ expect((await runSlug(f.sourceId, 'notes/agrees', preview.preview_hash!)).outcomes).toEqual({ repaired: 1 });+ await performManagedSync(engine, { sourceId: f.sourceId, noPull: true, noEmbed: true, noExtract: true });+ expect(await readGitHold(engine, f.sourceId, f.incarnation, path)).toBeNull();+ }), 240_000);++ test('#7950: a --slug preview with nothing to apply prints an apply command its apply accepts as an empty set', () => fixture(async f => {+ await put(f.ctx, 'notes/plain', 'No hold, no drift.');+ commitAll(f.root, 'page');+ const preview = await runSlug(f.sourceId, 'notes/plain');+ expect(preview).toMatchObject({ mode: 'dry_run', affected: 0, residuals: { no_drift: 1 } });+ expect(await runSlug(f.sourceId, 'notes/plain', preview.preview_hash!)).toMatchObject({ mode: 'apply', affected: 0, complete: true });+ }), 240_000);++ test('#7950: the release_hold apply refuses when the hold it observed was replaced after the preview', () => fixture(async f => {+ await put(f.ctx, 'notes/again', 'Same content on both sides.');+ commitAll(f.root, 'page');+ const path = 'notes/again.md';+ const live = (await snapshot(f.sourceId, 'notes/again'))!;+ await hold(f, { path, slug: 'notes/again', pageId: Number(live.page.id), side: 'unknown', revision: live.revision });+ const preview = await runSlug(f.sourceId, 'notes/again');+ await Bun.sleep(5);+ await hold(f, { path, slug: 'notes/again', pageId: Number(live.page.id), side: 'unknown', revision: live.revision });+ expect((await runSlug(f.sourceId, 'notes/again', preview.preview_hash!)).outcomes).toEqual({ changed_since_preview: 1 });+ }), 240_000);+test('--side deleted without --state is refused before anything is read, naming each state with its verb', () => fixture(async f => {const refused = await refusal(run(f.sourceId, { side: 'deleted', prefer: 'database' }));expect(refused.code).toBe('file_drift_state_required');