Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: reconcile accepted replays under a refresh fence; partial remember batches are MCP errors (#8621)
garrytan6dc7303356be
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex dea782f0aa..bdc760491d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,10 +16,10 @@ identifiers and attribution are available in the pre-removal Git revision### Itemized changes-- `src/core/error-registry.ts`: registers `worktree_refreshing` (class retryable, actor provider). `src/core/persistence/journal.ts`: the fence refusal carries `retryable: true` and a read-only `gbrain sources writer status --source <id> --json` fix, so the envelope renders `next: wait`.+- `src/core/error-registry.ts`: registers `worktree_refreshing` (class retryable, actor provider). `src/core/persistence/journal.ts`: the fence refusal carries `retryable: true` and a read-only `gbrain sources writer status --source <id> --json` fix, so the envelope renders `next: wait`. A retried admission whose request was already accepted (its acknowledgement lost before the fence) reconciles to that receipt instead of being refused as not recorded.- `src/core/persistence/admission-retry.ts`: `waitOutRefreshFence` re-runs an interactive write's whole admission (250 ms to 2 s backoff, 10 s cap shared by every item of a `remember` batch); nothing is held across a pause and a refused attempt journals nothing. Past the cap the refusal is returned with how long the call waited. Background writes and the managed sync keep their own retries; database-only sources are never fenced. Wired into `admitWrite`, `admitBatch` (`put-pages`) and `forget`.- `src/core/persistence/verb-errors.ts`: `remember` and the other memory verbs keep their frozen `unavailable` code for the fence and add `canonical: worktree_refreshing`, its `detail`, `fix` and `retryable`.-- `src/core/remember-batch.ts`: a batch whose every item failed throws the first item's error (`items[<i>]: ... None of the <n> item(s) was saved.`); a batch with any failed item adds `status: "error"`. `src/cli/remember-format.ts` prints a batch as `saved X of N fact(s)` with one line per item.+- `src/core/remember-batch.ts`: a batch whose every item failed throws the first item's error (`items[<i>]: ... None of the <n> item(s) was saved.`); a batch with any failed item (or an item whose outcome is unknown, which keeps its child `request_id`) adds `status: "error"` and the first failed `code`, so the CLI exits 1 and MCP returns `isError` with every item's receipt (`src/mcp/dispatch.ts`). `src/cli/remember-format.ts` prints a batch as `saved X of N fact(s)` with one line per item.- `test/write-refusal-refresh-fence-8621.test.ts` (new) pauses a real refresh at its drained boundary on PGLite and Postgres and covers MCP, the wait, the cap, background writes, a database-only source and the CLI exit codes.## [0.60.574.0] - 2026-11-04diff --git a/docs/protocol/MEMORY_VERBS_v1.md b/docs/protocol/MEMORY_VERBS_v1.mdindex 1d6de27fd2..c97001de8b 100644--- a/docs/protocol/MEMORY_VERBS_v1.md+++ b/docs/protocol/MEMORY_VERBS_v1.md@@ -420,9 +420,9 @@ hints?, next? }`. Each `items[]` entry is a compact receipt `{ index,request_id, status, id?, entity_slug?, superseded_fact_id?, warnings?, valid_until?, state? }`(`state` and `retry_after_ms` only when the write is not yet committed), or`{ index, request_id, status: "failed", error: { code, message, suggestion? } }`. Per-item hints-appear once in `hints`. `partial: true`: some items saved; resend-only the failed ones under a new `request_id`. Any failed item adds `status: "error"` (CLI exit 1,-MCP `isError`); if none saved, the call fails with the first item's error.+appear once in `hints`. `partial: true`: some saved; resend+only the failed ones with a new `request_id`. Any failed item adds `status: "error"` (CLI exit 1,+MCP `isError`); if all were refused unaccepted, it fails with the first item's error.### entity(name) — read, zero LLM, p99 < 100msdiff --git a/llms-full.txt b/llms-full.txtindex 953f27939b..a1276381b3 100644--- a/llms-full.txt+++ b/llms-full.txt@@ -8880,9 +8880,9 @@ hints?, next? }`. Each `items[]` entry is a compact receipt `{ index,request_id, status, id?, entity_slug?, superseded_fact_id?, warnings?, valid_until?, state? }`(`state` and `retry_after_ms` only when the write is not yet committed), or`{ index, request_id, status: "failed", error: { code, message, suggestion? } }`. Per-item hints-appear once in `hints`. `partial: true`: some items saved; resend-only the failed ones under a new `request_id`. Any failed item adds `status: "error"` (CLI exit 1,-MCP `isError`); if none saved, the call fails with the first item's error.+appear once in `hints`. `partial: true`: some saved; resend+only the failed ones with a new `request_id`. Any failed item adds `status: "error"` (CLI exit 1,+MCP `isError`); if all were refused unaccepted, it fails with the first item's error.### entity(name) — read, zero LLM, p99 < 100msdiff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsvindex 7c4336882b..6898137e2a 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 1759 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); +4 GST-687: page evidence and the extractive fallback quote below-owner-tier text for untrusted readers (untrusted flag; logic in search/transcript-quote.ts)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 1623 ratchet +3 GBRA-200 comment, write-grant refusal and degraded-stamp rows (re-summed at the 0.60.562.0 merge: 1615 + 3); +2 GBRA-280 get_page selector-precedence row and comment (re-summed at the 0.60.569.0 merge: 1619 + 2); 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 row; +1 #7974 file_drift_followups_7974 row; +1 #8059 quoted_fence_marker_8059 row; +2 GBRA-247 #8009 provenance_repair_held_8009 and #7982 pass_transient_streak_7982 rows; +4 GBRA-247 #7973 plain_directory_sync_7973, #7988 managed_marker_own_directory_7988, #7985 former_binding_parked_group_7985 and settle_effects_retire_7985 rows Train S merge: 1570 base + 5 (master since the #8077 base) + 13 (#8077) = 1588.; +2 GST-687 remote_quotes_unverified_text_gst687 row and its comment (re-summed at the gate-ahead on train S 0.60.534.0: 1588 + 2); +2 #8377: the quote fence follow-ups row and its comment; +2 #8384: the quote fence follow-ups 2 row and its comment; +2 #8384 wave 3: the quote fence follow-ups 3 row and its comment; +5 GBRA-218 train M rows (A1 member_read_access_gbra218 and member_access_hatch_scope_gbra218, B shared_agent_audience_gbra231, A2 folder_access_rules_gbra218, folder_access_scoped_role_gbra218), re-summed at the train M merge of master v0.60.541.0: 1596 + 5 = 1601 measured; +3 GST-359 train C rows (C1 qm_attested_actor_gst359, C2 member_facts_gst359, D qm_memory_provider_gst359), re-summed at the train C merge of master v0.60.543.0: 1601 + 3 = 1604 measured; +2 #8424: hook_launcher_8424 row and its comment (rows are data and cannot move), re-summed at the #8418 v0.60.546.0 merge: 1604 + 2 = 1606 measured; +2 #8426: mcp_lane_launcher_8426 row and its comment (rows are data and cannot move); +2 GST-927: empty_nonstring_args_gst927 row and its comment, re-summed at the gate-ahead on master v0.60.550.0 plus #8420: 1610 measured; +2 GBRA-283 Wave A (#8460): engine_keyed_caches_gbra283 row and its comment (rows are data and cannot move); +2 GBRA-287: segmented_freeze_hold_gbra287 and segmented_reexport_gbra287 rows (rows are data and cannot move); +1 GST-1209: segmented_tiling_gst1209 row (rows are data and cannot move); +1 GST-1251: skillopt_loop_deprecated_gst1251 row (rows are data and cannot move); +1 GST-1209 follow-up: untiled_hold_repair_gst1209 row (rows are data and cannot move); +1 GBRA-283 B3a: embedded_scope_required_gbra283 row (rows are data and cannot move)+src/core/behavior-change-notice.ts 1625 ratchet +3 GBRA-200 comment, write-grant refusal and degraded-stamp rows (re-summed at the 0.60.562.0 merge: 1615 + 3); +2 GBRA-280 get_page selector-precedence row and comment (re-summed at the 0.60.569.0 merge: 1619 + 2); 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 row; +1 #7974 file_drift_followups_7974 row; +1 #8059 quoted_fence_marker_8059 row; +2 GBRA-247 #8009 provenance_repair_held_8009 and #7982 pass_transient_streak_7982 rows; +4 GBRA-247 #7973 plain_directory_sync_7973, #7988 managed_marker_own_directory_7988, #7985 former_binding_parked_group_7985 and settle_effects_retire_7985 rows Train S merge: 1570 base + 5 (master since the #8077 base) + 13 (#8077) = 1588.; +2 GST-687 remote_quotes_unverified_text_gst687 row and its comment (re-summed at the gate-ahead on train S 0.60.534.0: 1588 + 2); +2 #8377: the quote fence follow-ups row and its comment; +2 #8384: the quote fence follow-ups 2 row and its comment; +2 #8384 wave 3: the quote fence follow-ups 3 row and its comment; +5 GBRA-218 train M rows (A1 member_read_access_gbra218 and member_access_hatch_scope_gbra218, B shared_agent_audience_gbra231, A2 folder_access_rules_gbra218, folder_access_scoped_role_gbra218), re-summed at the train M merge of master v0.60.541.0: 1596 + 5 = 1601 measured; +3 GST-359 train C rows (C1 qm_attested_actor_gst359, C2 member_facts_gst359, D qm_memory_provider_gst359), re-summed at the train C merge of master v0.60.543.0: 1601 + 3 = 1604 measured; +2 #8424: hook_launcher_8424 row and its comment (rows are data and cannot move), re-summed at the #8418 v0.60.546.0 merge: 1604 + 2 = 1606 measured; +2 #8426: mcp_lane_launcher_8426 row and its comment (rows are data and cannot move); +2 GST-927: empty_nonstring_args_gst927 row and its comment, re-summed at the gate-ahead on master v0.60.550.0 plus #8420: 1610 measured; +2 GBRA-283 Wave A (#8460): engine_keyed_caches_gbra283 row and its comment (rows are data and cannot move); +2 GBRA-287: segmented_freeze_hold_gbra287 and segmented_reexport_gbra287 rows (rows are data and cannot move); +1 GST-1209: segmented_tiling_gst1209 row (rows are data and cannot move); +1 GST-1251: skillopt_loop_deprecated_gst1251 row (rows are data and cannot move); +1 GST-1209 follow-up: untiled_hold_repair_gst1209 row (rows are data and cannot move); +1 GBRA-283 B3a: embedded_scope_required_gbra283 row (rows are data and cannot move); +2 GST-1387: refresh_fence_refusal_gst1387 row and its comment (rows are data and cannot move)diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 256c3fac09..34210697a5 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1426,7 +1426,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.570.0', id: 'get_page_selector_precedence_gbra280', text: 'get_page given several window selectors now reads one window instead of refusing with invalid_params: cursor, then around_chunk_id, then lines, then bytes, and a cursor that cannot read the page or an around_chunk_id no longer on it gives way to the next. body full, include_content and content_only beside a selector are set aside, so the read stays a window and never returns the whole page. The response\'s window_selector names what applied and what was ignored; a call with one selector is unchanged.' },{ since: '0.60.574.0', id: 'embedded_scope_required_gbra283', text: 'Experimental embedded engines (`openEngine` with `embedded_core: true`) only; the CLI, `gbrain serve` and mounts are unchanged. While such an engine is open, an embed, chat, expansion or rerank call that entered no scope now refuses `engine_scope_required` (new code) even when the host configured a process gateway with `configureGateway`; before, that configuration let unscoped calls use the process keys, and the refusal was `engine_scope_missing`, which now only means a provider the engine lacks or a closed engine. Wrap such calls in `withEngineScope(engine, fn)`, or `withLocalScope(fn)` for calls that belong to the process gateway (both from `gbrain/engine-open`); `hybridSearch`, the import paths, minion jobs and `POST /mcp` enter their engine\'s scope themselves. `openEngine` also refuses an unknown settings key, top-level or nested, with `engine_settings_invalid` naming the key, where it used to ignore it. An embedded engine\'s chat usage is no longer on the process usage stack and survives `reconnect()`. See docs/ENGINES.md "Upgrading an embedded host".' },// GST-1387 (#8621) refresh-fence refusals; release:restamp stamps since at the merge slot.- { since: '0.60.574.0', id: 'refresh_fence_refusal_gst1387', text: 'A write refused because `gbrain sources refresh` is fast-forwarding its checkout (`worktree_refreshing`) is now a registered retryable refusal whose fix is `next: wait` with `retry_after_ms`, instead of class server with `fix: gbrain doctor`; the memory verbs keep `unavailable` and add `canonical: worktree_refreshing`. An interactive CLI or MCP write waits out the fence for up to 10 s before that refusal; a background write is refused at once as before. `remember` with `items` whose every item failed is now refused with the first item\'s error (CLI exit 1, MCP isError) instead of a success envelope with `failed`, and a batch with any failed item adds `status: "error"`, so the CLI exits 1.' },+ { since: '0.60.574.0', id: 'refresh_fence_refusal_gst1387', text: 'A write refused because `gbrain sources refresh` is fast-forwarding its checkout (`worktree_refreshing`) is now a registered retryable refusal whose fix is `next: wait` with `retry_after_ms`, instead of class server with `fix: gbrain doctor`; the memory verbs keep `unavailable` and add `canonical: worktree_refreshing`. An interactive CLI or MCP write waits out the fence for up to 10 s before that refusal; a background write is refused at once as before. `remember` with `items` whose every item failed is now refused with the first item\'s error (CLI exit 1, MCP isError) instead of a success envelope with `failed`, and a batch with any failed item adds `status: "error"` and the first failed `code`, so the CLI exits 1 and MCP returns isError with every item\'s receipt.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/persistence/journal.ts b/src/core/persistence/journal.tsindex 332eed8a20..8e7d1972f3 100644--- a/src/core/persistence/journal.ts+++ b/src/core/persistence/journal.ts@@ -624,6 +624,8 @@ async function assertWorktreeNotRefreshing(tx: BrainEngine, input: WriteAdmissioconst error = catalogueError('worktree_refreshing',`Source ${input.sourceId}'s checkout is being fast-forwarded by refresh ${refresh.id} (${refresh.state}); this write was not journaled.`,`Retry the same request_id after retry_after_ms: 1000. Check progress with gbrain sources writer status ${input.sourceId}.`);+ // A replay of a request already accepted (its acknowledgement lost before the fence) reconciles to its receipt instead.+ if (input.requestId && await getWriteRequest(tx, input.principal, input.requestId)) return;error.detail = 'retry_after_ms=1000';error.retryable = true;// GST-1387: nothing was recorded, so the same call is retried after the delay (actor provider renders next: wait).diff --git a/src/core/remember-batch.ts b/src/core/remember-batch.tsindex 84d68e4aed..be807ebf93 100644--- a/src/core/remember-batch.ts+++ b/src/core/remember-batch.ts@@ -115,20 +115,22 @@ export async function runRememberBatch(ctx: OperationContext, p: Record<string,continue;}failures.push({ index, error: e });- results.push({ index, request_id: child, status: 'failed', error: { code: e.code, message: e.message, ...(e.detail ? { detail: e.detail } : {}), ...(e.suggestion ? { suggestion: e.suggestion } : {}), ...(e.withdrawn ? { withdrawn: e.withdrawn } : {}) } });+ results.push({ index, request_id: child, status: 'failed', error: { code: e.code, message: e.message, ...(e.writeError ? { write_error: e.writeError } : {}), ...(e.detail ? { detail: e.detail } : {}), ...(e.suggestion ? { suggestion: e.suggestion } : {}), ...(e.withdrawn ? { withdrawn: e.withdrawn } : {}) } });}} });const failed = results.filter(r => r.status === 'failed').length;const pending = results.filter(r => r.status === 'pending').length;// GST-1387: a batch that saved nothing is a refusal on every surface (CLI exit non-zero, MCP isError), never a success- // envelope; its first item's error keeps that item's code and fix.- if (failures.length && failed === results.length) {+ // envelope; its first item's error keeps that item's code and fix. An item with a receipt (accepted, or its outcome+ // unknown) keeps the per-item envelope so its child request_id is never lost.+ if (failures.length && failed === results.length && failures.every(f => !f.error.writeRequest)) {const [{ index, error }] = failures as [{ index: number; error: OperationError }];error.message = `items[${index}]: ${error.message} None of the ${results.length} item(s) was saved.`;throw error;}return {- ...(failed > 0 ? { status: 'error', error: `${failed} of ${results.length} item(s) failed; see items[].error.` } : {}),+ ...(failures.length ? { status: 'error', error: failures[0]!.error.code, code: failures[0]!.error.code,+ message: `${failed} of ${results.length} item(s) failed (first: items[${failures[0]!.index}] ${failures[0]!.error.code}); see items[].error. Items not marked failed are stored.` } : {}),protocol_version: 1,request_id: requestId,...(clientRequestId ? { client_request_id: clientRequestId } : {}),diff --git a/src/mcp/dispatch.ts b/src/mcp/dispatch.tsindex a239c9ed2a..09400eed1f 100644--- a/src/mcp/dispatch.ts+++ b/src/mcp/dispatch.ts@@ -1300,7 +1300,9 @@ async function dispatchResolvedCall(if (opts.transport === 'stdio' && opts.remote !== false) { const drain = takeFactsDrainNotice(); if (drain) notices.push(drain); } // Lane D facts drainnotices.push(...await sessionSafetyNotices(engine, opts, ctx.config));notices.push(...await grantBlockedNotices(engine, opts, false));- const out: ToolResult = toolResultWithNotices(result, admitNotices(notices, opts), dispatchRenderContext(opts));+ // GST-1387: a remember batch with a failed item is an MCP error; its body keeps every item's receipt.+ const batchError = name === 'remember' && typeof result === 'object' && result !== null && (result as { status?: unknown }).status === 'error' && Array.isArray((result as { items?: unknown }).items);+ const out: ToolResult = batchError ? toolErrorResult(result as never) : toolResultWithNotices(result, admitNotices(notices, opts), dispatchRenderContext(opts));if (evidenceBlocks.length > 0) out.content.splice(1, 0, ...evidenceBlocks.map(text => ({ type: 'text' as const, text })));if (opts.transport === 'stdio') {maybeRefreshBackupStatusInProcess(engine);diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txtindex 57339e0555..78f32a3a4a 100644--- a/test/postgres-unit-arms.txt+++ b/test/postgres-unit-arms.txt@@ -583,6 +583,7 @@ test/withdrawal-overlay-concurrency.test.tstest/withdrawal-publication-file.test.tstest/worktree-refresh-recovery-row-gbra130.test.tstest/worktree-refresh-unexpected-throw.test.ts+test/write-refusal-refresh-fence-8621.test.tstest/write-roundtrips-gbra156.test.tstest/write-through-leak-guard-alias-7203.test.tstest/writer-admin-state-embed-lease.test.tsdiff --git a/test/remember-batch.test.ts b/test/remember-batch.test.tsindex 3700a45df4..3cccb2ccd4 100644--- a/test/remember-batch.test.ts+++ b/test/remember-batch.test.ts@@ -103,7 +103,21 @@ describe('remember items[] batch', () => {expect(out.items[1].status).toBe('failed');expect(out.next).toContain('new request_id');// #8621: a partial failure is an in-band error (the CLI exits 1), not a clean success.- expect(out).toMatchObject({ status: 'error', saved: 1, failed: 1 });+ expect(out).toMatchObject({ status: 'error', code: 'internal_error', saved: 1, failed: 1 });+ });++ test('#8621: an item whose outcome is unknown keeps the per-item envelope and its child request_id, never "none saved"', async () => {+ const { handler: base } = fakeSingle({ failWrite: p => p.fact === 'fenced' });+ const handler = async (c: OperationContext, p: Record<string, unknown>) => {+ if (p.fact !== 'lost' || c.dryRun) return base(c, p);+ const e = ve('unavailable', 'The write outcome is unknown.', 'Poll get_write_request.');+ Object.assign(e, { writeError: 'write_outcome_unknown', writeRequest: { request_id: p.request_id, state: 'unknown' } });+ throw e;+ };+ const root = '22222222-2222-4222-8222-222222222222';+ const out = await runRememberBatch(ctx, { provenance: 'p', request_id: root, items: [{ fact: 'fenced' }, { fact: 'lost' }] }, handler, ve) as Record<string, any>;+ expect(out).toMatchObject({ status: 'error', code: 'internal_error', saved: 0, failed: 2 });+ expect(out.items[1]).toMatchObject({ request_id: childRequestId(root, 1), status: 'failed', error: { write_error: 'write_outcome_unknown' } });});test('#8621: a batch whose every item failed throws the first item error instead of returning a success envelope', async () => {diff --git a/test/remember-withdrawn-claim.test.ts b/test/remember-withdrawn-claim.test.tsindex a485998eb9..c4f797d56e 100644--- a/test/remember-withdrawn-claim.test.ts+++ b/test/remember-withdrawn-claim.test.ts@@ -71,6 +71,14 @@ describe('remember after forget of the same claim', () => {// #8621: a batch that saved nothing is refused with its item's error, never a success envelope.expect(batch.isError).toBe(true);expect(batch.body).toMatchObject({ code: 'invalid_params', message: `items[0]: ${FACT_WITHDRAWN_MESSAGE} None of the 1 item(s) was saved.`, suggestion: FACT_WITHDRAWN_SUGGESTION });++ // #8621: a partial batch is an MCP error too, and its body keeps the saved item's receipt.+ const partial = await call('remember', { items: [{ fact: CLAIM, entity: 'crm/acme-example', provenance: 'team update' },+ { fact: 'acme-example opened a second office', entity: 'crm/acme-example', provenance: 'team update' }] });+ expect(partial.isError).toBe(true);+ expect(partial.body).toMatchObject({ status: 'error', code: 'invalid_params', saved: 1, failed: 1, partial: true });+ expect(partial.body.items[0].status).toBe('failed');+ expect(partial.body.items[1].id).toBeDefined();});test('a withdrawal that lands after admission fails the receipt with fact_withdrawn, readable through get_write_request', async () => {diff --git a/test/write-refusal-refresh-fence-8621.test.ts b/test/write-refusal-refresh-fence-8621.test.tsindex 2a2bdcb6d0..606d08923a 100644--- a/test/write-refusal-refresh-fence-8621.test.ts+++ b/test/write-refusal-refresh-fence-8621.test.ts@@ -22,6 +22,7 @@ import { dispatchToolCall } from '../src/mcp/dispatch.ts';import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';import { refreshWorktree } from '../src/core/persistence/worktree-refresh.ts';import { submitPageMutation } from '../src/core/persistence/page-mutations.ts';+import { admitWrite, type WriteAdmission } from '../src/core/persistence/journal.ts';import { _setRefreshFenceWaitForTests } from '../src/core/persistence/admission-retry.ts';import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';import { testBackends } from './helpers/test-backends.ts';@@ -116,6 +117,26 @@ test('put_page past the wait cap is refused retryable with fix.next wait and ret}));}), 120_000);+test('an admission retried after its accepted commit lost its ack reconciles to the receipt under a fence, never "not recorded"', () => each(async f => {+ _setRefreshFenceWaitForTests(0);+ const requestId = crypto.randomUUID();+ const content = page('Accepted', 'accepted before the fence');+ await f.put(f.alpha, 'notes/accepted', content, requestId);+ const [row] = await f.engine.executeRaw<Record<string, any>>('SELECT * FROM persistence_requests WHERE request_id=$1::uuid', [requestId]);+ const [src] = await f.engine.executeRaw<{ incarnation: string }>('SELECT incarnation FROM sources WHERE id=$1', [f.alpha]);+ const [bind] = await f.engine.executeRaw<{ g: string }>('SELECT topology_generation::text AS g FROM persistence_source_bindings WHERE source_id=$1', [f.alpha]);+ // The same admission the accepted write made, re-run as retryWriteAdmission does after a lost COMMIT acknowledgement.+ const again: WriteAdmission = { principal: { kind: row!.principal_kind, id: row!.principal_id }, operation: 'put_page', sourceId: f.alpha,+ sourceIncarnation: src!.incarnation, slug: row!.slug, worktreeId: f.worktreeId, topologyGeneration: bind!.g, requestId,+ callerIntent: { slug: 'notes/accepted', content }, intent: row!.intent, authority: row!.authority, origin: 'interactive' };+ await (await duringRefresh(f, async () => {+ const before = await f.requestCount();+ const replay = await admitWrite(f.engine, again);+ expect(replay.id).toBe(row!.id);+ expect(await f.requestCount()).toBe(before);+ }));+}), 120_000);+test('an interactive write waits out a short refresh fence and commits once the refresh finishes', () => each(async f => {let write: Promise<Record<string, unknown>> | undefined;const refresh = await duringRefresh(f, async release => {