Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
persistence: writes waiting behind an import never hold their importer's capacity; expiry rechecks the hold; a held capture names what it replaced (GST-1623)
garrytan31bfe917bafe
diff --git a/docs/designs/REFRESH_WRITE_BARRIER.md b/docs/designs/REFRESH_WRITE_BARRIER.mdindex 08a3bfe35f..5d92431e65 100644--- a/docs/designs/REFRESH_WRITE_BARRIER.md+++ b/docs/designs/REFRESH_WRITE_BARRIER.md@@ -200,13 +200,13 @@ barrier exists to keep, and with the flag on each now waits instead (with it offimported is never awaited), and the consumer moves its own claim back to `deferred` with`deferred_import_from` set to that commit (`''` when the source had never imported). The row isreleased when `sources.last_commit` differs from it (and any refresh it also names is released),- then claimed and prepared from scratch, as if it had queued behind the import: a `remember`,- `capture` or `add_timeline_entry` applies on top; a `put_page` with `expected_revision` meets the moved page and ends- `revision_conflict`; a blind (`force`) `put_page` lands. An import that lands without covering+ then claimed and prepared from scratch, as if it had queued behind the import: a `remember` or+ `add_timeline_entry` applies on top; a `put_page` with `expected_revision` meets the moved page and ends+ `revision_conflict`; a blind (`force`) `put_page` or a `capture` lands over it. An import that lands without coveringthe file only re-arms the hold at the new commit. The receipt reads `queued` with`deferred: { pending_import: true }`, and the caller's wait returns pending at once.-**What a blind write replaced.** A held `put_page` that replaces content an import brought in names+**What a blind write replaced.** A held `put_page` or `capture` that replaces content an import brought in namesit in three places, so the replacement is auditable and recoverable without digging: the receipt's`supersedes` (`slug`, `path`, the replaced `revision`, the imported `commit`: the newest commitafter the held-at commit that touched the file), a `gbrain-supersedes: <path>: revision <id> fromdiff --git a/docs/guides/write-refusals.md b/docs/guides/write-refusals.mdindex a79fd6a884..2b0b73f3cc 100644--- a/docs/guides/write-refusals.md+++ b/docs/guides/write-refusals.md@@ -620,9 +620,9 @@ syncing it is accepted and waits for the refresh instead of being refused `workt- <a id="pending_import_expired"></a>A `put_page`, `capture`, `remember` or `add_timeline_entry` whose page file holds acommitted change managed sync has not imported yet ([`pending_import`](#pending_import)) also waitsinstead of being refused: the receipt stays pending with `deferred: { pending_import: true }`, and- once the import lands the write is prepared again against the imported page. A `remember`,- `capture` or `add_timeline_entry` applies on top; a `put_page` with `expected_revision` ends `revision_conflict` when the- import moved the page; a blind (`force`) `put_page` lands, and its receipt (`supersedes`), its+ once the import lands the write is prepared again against the imported page. A `remember` or+ `add_timeline_entry` applies on top; a `put_page` with `expected_revision` ends `revision_conflict` when the+ import moved the page; a blind (`force`) `put_page` or a `capture` lands over it, and its receipt (`supersedes`), itscommit trailer (`gbrain-supersedes: <path>: revision <id> from <commit>`) and the commit ledgername the imported revision and commit it replaced, both still in page history and Git. A writewhose import has not landed within the wait limit of its hold ends `failed` with `pending_import_expired`,diff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsvindex 7ef6d2f383..8269115cea 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 1526 ratchet +1 GBRA-216: recall.* config set value refusal (facts/recall-config.ts); +1 GBRA-216: config set refuses a dream.claim_conflicts.mode other than propose|off (refusal in facts/claim-conflicts.ts); 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 1668 ratchet +4 train R: #7491/#7492 keyword_identifier_probe and keyword_slug_handles rows and their comment, #7175 keyword phrase row; 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); +1 GBRA-156 #7593: private_pages_granted_sources row (re-summed at the 0.60.527.0 merge: 1574 + 1); +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); re-summed at the train R merge with v0.60.574.0: 1623 + 4; +2 GST-1387: refresh_fence_refusal_gst1387 row and its comment (rows are data and cannot move); re-summed at the memory train #8481 merge with v0.60.578.0 (1643 measured); +3 GBRA-253 #8109 rows (frontmatter_drift_write_8109, contacts_activity_advance_8109, contact_rows_dedupe_8109; rows are data and cannot move), re-summed at the master v0.60.581.0 merge: 1643 + 3 = 1646 measured; +3 #8123 part C rows: sync_write_through_off_writeback_7084, managed_sync_dry_run_counts_7087, frontmatter_missing_source_dir_7889 (since TBD until the merge slot; re-summed at the 0.60.583.0 merge: 1646 + 3); +4 PR B commit_ledger_prb, doctor_foreign_writers_prb and sources_guard_prb rows and their comment (rows are data and cannot move; since TBD until the merge slot); +1 PR B #8615: file_drift_held_needs_prefer_8615 row; +1 PR B #8617: refresh_source_changed_retry_8617 row; +1 PR B #8662: commit_push_checkout_not_a_source_8662 row (since TBD until the merge slot; rows are data and cannot move); +2 PR B refresh_barrier_prb and commit_push_base_prb rows (re-summed: 1658 measured); +3 convergence PR A: the wave comment and two rows (conversion_content_evidence_pr_a, git_gap_live_pages_pr_a; since TBD until the merge slot; rows are data and cannot move); re-summed at the gate-ahead on master v0.60.592.0 plus #8711: 1658 + 3 = 1661 measured; +4 GST-1094/GST-900 rows (memory_recall scope-read, member-bound acting_user, recall max_chars, unknown_param _meta-only) and +1 qm_scope_writes_gst1113 and +1 recall_question_terms_gst1304 rows (rows are data and cannot move), re-summed at the 0.60.595.0 slot merge: 1661 + 6; +1 GST-1582 refresh_barrier_import_gst1582 row (since TBD until the merge slot; rows are data and cannot move)+src/core/behavior-change-notice.ts 1669 ratchet +4 train R: #7491/#7492 keyword_identifier_probe and keyword_slug_handles rows and their comment, #7175 keyword phrase row; 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); +1 GBRA-156 #7593: private_pages_granted_sources row (re-summed at the 0.60.527.0 merge: 1574 + 1); +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); re-summed at the train R merge with v0.60.574.0: 1623 + 4; +2 GST-1387: refresh_fence_refusal_gst1387 row and its comment (rows are data and cannot move); re-summed at the memory train #8481 merge with v0.60.578.0 (1643 measured); +3 GBRA-253 #8109 rows (frontmatter_drift_write_8109, contacts_activity_advance_8109, contact_rows_dedupe_8109; rows are data and cannot move), re-summed at the master v0.60.581.0 merge: 1643 + 3 = 1646 measured; +3 #8123 part C rows: sync_write_through_off_writeback_7084, managed_sync_dry_run_counts_7087, frontmatter_missing_source_dir_7889 (since TBD until the merge slot; re-summed at the 0.60.583.0 merge: 1646 + 3); +4 PR B commit_ledger_prb, doctor_foreign_writers_prb and sources_guard_prb rows and their comment (rows are data and cannot move; since TBD until the merge slot); +1 PR B #8615: file_drift_held_needs_prefer_8615 row; +1 PR B #8617: refresh_source_changed_retry_8617 row; +1 PR B #8662: commit_push_checkout_not_a_source_8662 row (since TBD until the merge slot; rows are data and cannot move); +2 PR B refresh_barrier_prb and commit_push_base_prb rows (re-summed: 1658 measured); +3 convergence PR A: the wave comment and two rows (conversion_content_evidence_pr_a, git_gap_live_pages_pr_a; since TBD until the merge slot; rows are data and cannot move); re-summed at the gate-ahead on master v0.60.592.0 plus #8711: 1658 + 3 = 1661 measured; +4 GST-1094/GST-900 rows (memory_recall scope-read, member-bound acting_user, recall max_chars, unknown_param _meta-only) and +1 qm_scope_writes_gst1113 and +1 recall_question_terms_gst1304 rows (rows are data and cannot move), re-summed at the 0.60.595.0 slot merge: 1661 + 6; +1 GST-1582 refresh_barrier_import_gst1582 row (since TBD until the merge slot; rows are data and cannot move); +1 GST-1623 refresh_barrier_capacity_gst1623 row (since TBD until the merge slot; rows are data and cannot move)diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex a49669ba9d..3ba7d8154c 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1465,7 +1465,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.594.0', id: 'doctor_foreign_writers_prb', text: 'New doctor check `foreign_writers`: in every source checkout on this host, managed worktrees included, a commit gbrain\'s commit ledger does not name fails the check with the newest such commit and a fix that asks who makes it; an unconfirmed commit (a crash between `git commit` and the ledger line) and page files left uncommitted for over 30 minutes warn. Commits before the ledger started are reported as uncovered, not foreign. A repo-less brain reports not_applicable.' },{ since: '0.60.594.0', id: 'sources_guard_prb', text: 'New `gbrain sources guard <source> --install|--uninstall|--status [--mode enforce]`: the commit guard on a managed source\'s worktree, from its owner host only, installed in a hooks directory private to that worktree. `--mode enforce` also refuses cherry-pick, revert, rebase and sequencer commits. `gbrain git guard` is unchanged.' },{ since: '0.60.594.0', id: 'refresh_barrier_prb', text: 'New setting `persistence.refresh_barrier` (off by default): with it on, a single page write (`put_page`, `remember` and the other single-page verbs) that reaches a checkout while `gbrain sources refresh` drains or merges it is journaled and answered `pending` at once (MCP `isError: false`, CLI exit 10) instead of refused `worktree_refreshing`. It commits after the refresh, or ends `revision_conflict` when the refresh changed its file, or `refresh_barrier_expired` after `persistence.refresh_barrier_max_wait_ms` (15 minutes). Syncs, jobs and batches keep the refusal. `gbrain upgrade --check-downgrade` exits 3 `downgrade_blocked_deferred_writes` while such writes wait.' },- { since: '0.60.596.0', id: 'refresh_barrier_import_gst1582', text: 'With `persistence.refresh_barrier` on, no page write bounces because a sync is running: a `put_page`, `capture`, `remember` or `add_timeline_entry` whose page file holds a committed change managed sync has not imported yet is answered `pending` (receipt `deferred: { pending_import: true }`) instead of refused `pending_import`, and is prepared again once the import lands (a `put_page` with `expected_revision` then ends `revision_conflict` if the import moved the page; a blind one lands and names the revision and commit it replaced in `supersedes`, a `gbrain-supersedes:` commit trailer and the commit ledger), or ends `pending_import_expired` once held past the wait limit (a `remember` ends as its `pending_import` refusal did and is replayed after the import). A write during a refresh in `recovery_required` waits too, and `persistence.refresh_barrier_max_deferred` is no longer read: no write past it is refused. With the barrier off those refusals are unchanged. Wherever `worktree_refreshing` still refuses, `retry_after_ms` is estimated from the refresh (its typical duration minus how long it has run, at least 15 s while syncing and 2 s otherwise) instead of a fixed 1000, the message says the write was not saved and when to retry, and the CLI\'s human output ends with one line saying the same.' },+ { since: 'TBD', id: 'refresh_barrier_capacity_gst1623', text: 'With `persistence.refresh_barrier` on, writes waiting behind an import or a refresh no longer hold the outstanding-request and intent-byte capacity a managed sync job needs, so a full cap no longer stalls the import until the waits expire (the import can pass a cap by at most what the waiting writes hold). A held `capture` that replaces an imported page names what it replaced (`supersedes`, the `gbrain-supersedes:` trailer and the commit ledger) like a blind `put_page`. An import and a new hold that race the owner\'s expiry never expire the new hold.' },+{ since: '0.60.596.0', id: 'refresh_barrier_import_gst1582', text: 'With `persistence.refresh_barrier` on, no page write bounces because a sync is running: a `put_page`, `capture`, `remember` or `add_timeline_entry` whose page file holds a committed change managed sync has not imported yet is answered `pending` (receipt `deferred: { pending_import: true }`) instead of refused `pending_import`, and is prepared again once the import lands (a `put_page` with `expected_revision` then ends `revision_conflict` if the import moved the page; a blind one lands and names the revision and commit it replaced in `supersedes`, a `gbrain-supersedes:` commit trailer and the commit ledger), or ends `pending_import_expired` once held past the wait limit (a `remember` ends as its `pending_import` refusal did and is replayed after the import). A write during a refresh in `recovery_required` waits too, and `persistence.refresh_barrier_max_deferred` is no longer read: no write past it is refused. With the barrier off those refusals are unchanged. Wherever `worktree_refreshing` still refuses, `retry_after_ms` is estimated from the refresh (its typical duration minus how long it has run, at least 15 s while syncing and 2 s otherwise) instead of a fixed 1000, the message says the write was not saved and when to retry, and the CLI\'s human output ends with one line saying the same.' },{ since: '0.60.594.0', id: 'commit_push_base_prb', text: '`gbrain git commit-push` takes `--base <path>=<blob>|absent` (repeatable, each path one the command commits): it refuses `commit_base_moved`, committing nothing, when the file at HEAD is no longer the blob the caller read. Without `--base` nothing changes.' },{ since: '0.60.594.0', id: 'file_drift_held_needs_prefer_8615', text: '`gbrain repair file-drift` with `--held`, `--side`, `--state`, `--cursor` or `--provenance` and no `--prefer` now refuses with the usage line (`invalid_params`, and `file_drift_state_required` for a deleted side without `--state`) instead of silently running the all-drifted survey, which counted a different set of pages (#8615).' },{ since: '0.60.594.0', id: 'refresh_source_changed_retry_8617', text: 'A `gbrain sources refresh` run refused `refresh_source_changed` because the checkout HEAD moved (a writer committing) or work reached the checkout after the drain check now retries once from a fresh precheck in the same run, so the tick is not lost (#8617). When the retry is refused too, the run returns the first `refresh_source_changed` refusal with the retry\'s cause appended; ownership or source-membership changes are not retried.' },diff --git a/src/core/persistence/import-deferral.ts b/src/core/persistence/import-deferral.tsindex 831909e889..598a3e2b74 100644--- a/src/core/persistence/import-deferral.ts+++ b/src/core/persistence/import-deferral.ts@@ -3,9 +3,9 @@* put_page, capture, remember or add_timeline_entry whose page file holds a committed change managed sync has not imported yet is not refused* `pending_import`. The consumer moves its own claim back to `deferred`, naming the source's last imported commit, and the* row waits (invisible to claims, journal.ts RELEASED_DEFERRED) until `sources.last_commit` moves past it. It is then- * prepared again from scratch, as if it had queued behind the import: a remember, capture or add_timeline_entry applies on top, a put_page- * with expected_revision ends revision_conflict when the import moved the page, and a blind put_page lands. A blind- * put_page that replaces content the import brought in names what it replaced (`supersedes`) on its receipt, in a+ * prepared again from scratch, as if it had queued behind the import: a remember or add_timeline_entry applies on top, a put_page+ * with expected_revision ends revision_conflict when the import moved the page, and a blind put_page or a capture lands. A blind+ * put_page or a capture that replaces content the import brought in names what it replaced (`supersedes`) on its receipt, in a* `gbrain-supersedes:` commit trailer and on the commit ledger line; the replaced revision stays in page history and* the imported commit in git. A held write whose import never lands ends `pending_import_expired` (refresh-barrier.ts).*/@@ -19,6 +19,8 @@ import { PERSISTENCE_PROTOCOL_PREDICATE } from './protocol.ts';import { writeSwitchOn } from './switches.ts';const IMPORT_HELD_OPERATIONS = ['put_page', 'capture', 'remember', 'add_timeline_entry'];+/** A held write that renders the caller's whole body over the imported page, so it names what it replaced. */+const REPLACING_OPERATIONS = ['put_page', 'capture'];export const SUPERSEDES_TRAILER_KEY = 'gbrain-supersedes';/**@@ -48,11 +50,11 @@ export function supersededBy(trailers: Iterable<string>): string[] {}/**- * A put_page that was held for an import and replaces the page the import wrote: its outcome carries `supersedes`+ * A put_page or capture that was held for an import and replaces the page the import wrote: its outcome carries `supersedes`* (slug, path, the replaced revision, the imported commit) and its commit the matching trailer.*/export async function withSupersedes(row: WriteRequest, prepared: PreparedMutation): Promise<PreparedMutation> {- if (row.deferred_import_from == null || row.operation !== 'put_page' || !prepared.file || prepared.noop || !prepared.observedRevision) return prepared;+ if (row.deferred_import_from == null || !REPLACING_OPERATIONS.includes(row.operation) || !prepared.file || prepared.noop || !prepared.observedRevision) return prepared;const { root, path } = prepared.file;const commit = await landedCommit(root, row.deferred_import_from || null, path);if (!commit) return prepared;diff --git a/src/core/persistence/journal.ts b/src/core/persistence/journal.tsindex d0ad2c6878..0851250a21 100644--- a/src/core/persistence/journal.ts+++ b/src/core/persistence/journal.ts@@ -119,11 +119,12 @@ export function capacityError(resource: string, outstanding?: { used: number; li* divided by the sources holding outstanding requests on the principal, this one included) is still admitted; the brain* cap and every other principal's cap stay hard. The share is checked before the admission, so a sync publication group* larger than the share is admitted whole and a source passes its share by at most one group. A refusal names the source- * holding the most slots.+ * holding the most slots. GST-1623: a managed sync job passes `held`, the counter's writes waiting in `deferred` (heldBehindImport).*/-async function outstandingRefusal(tx: SqlEngine, row: Counter, principal: Principal, sourceId: string, need: number, limit: number): Promise<OperationError | null> {+async function outstandingRefusal(tx: SqlEngine, row: Counter, principal: Principal, sourceId: string, need: number, limit: number,+ held = 0): Promise<OperationError | null> {const used = Number(row.outstanding_count);- if (used + need <= limit) return null;+ if (used - held + need <= limit) return null;if (row.key === 'brain' || principal.kind !== 'local_cli') return capacityError(`${row.key === 'brain' ? 'brain' : 'principal'} outstanding requests`, { used, limit });const holders = await tx.executeRaw<{ source_id: string; n: number | string }>(`SELECT source_id,count(*) AS n FROM persistence_requestsWHERE principal_kind=$1 AND principal_id=$2 AND state IN ('queued','running','recovering') GROUP BY source_id ORDER BY count(*) DESC,source_id`, [principal.kind, principal.id]);@@ -133,6 +134,18 @@ async function outstandingRefusal(tx: SqlEngine, row: Counter, principal: Princiconst top = holders[0];return capacityError(`principal outstanding requests${top ? ` (source ${top.source_id} holds ${Number(top.n)})` : ''}`, { used, limit });}+/**+ * GST-1623: the writes counted on `principal`'s counter (the brain's when null) that wait in `deferred` behind an import or+ * a refresh, and their intent bytes. They cannot settle before managed sync imports, so a managed sync job is admitted as+ * if they held no slot; the importer can pass a cap by at most what they hold.+ */+async function heldBehindImport(tx: SqlEngine, principal: Principal | null): Promise<{ count: number; bytes: number }> {+ const [row] = await tx.executeRaw<{ count: number | string; bytes: number | string }>(`SELECT count(*) AS count,COALESCE(sum(intent_bytes),0) AS bytes+ FROM persistence_requests WHERE state='deferred'${principal ? ' AND principal_kind=$1 AND principal_id=$2' : ''}`, principal ? [principal.kind, principal.id] : []);+ return { count: Number(row?.count ?? 0), bytes: Number(row?.bytes ?? 0) };+}+/** A managed sync job: the import itself, never deferred or refused behind a refresh that waits on it. */+const managedSyncJob = (input: Pick<WriteAdmission, 'operation' | 'intent'>) => input.operation === 'submit_job' && String(input.intent.kind ?? '').startsWith('managed_sync_');/*** #6696 (A6): a cumulative cap refusal is `write_quota_exhausted` (host only;* waiting does not free a permanent id, and receipt bytes free only as@@ -335,9 +348,10 @@ async function prepareAdmission(engine: BrainEngine, input: WriteAdmission, overif (input.targetKind === 'skill_bundle') await assertSharedSkillPersistence(tx, input.sourceId);for (const row of counters) {const brain = row.key === 'brain';- const outstanding = await outstandingRefusal(tx, row, input.principal, input.sourceId, 1, brain ? limits.brainOutstanding : limits.principalOutstanding);+ const held = managedSyncJob(input) ? await heldBehindImport(tx, brain ? null : input.principal) : { count: 0, bytes: 0 };+ const outstanding = await outstandingRefusal(tx, row, input.principal, input.sourceId, 1, brain ? limits.brainOutstanding : limits.principalOutstanding, held.count);if (outstanding) throw outstanding;- if (Number(row.intent_bytes) + bytes > (brain ? limits.brainIntentBytes : limits.principalIntentBytes)) throw capacityError(`${brain ? 'brain' : 'principal'} intent bytes`);+ if (Number(row.intent_bytes) - held.bytes + bytes > (brain ? limits.brainIntentBytes : limits.principalIntentBytes)) throw capacityError(`${brain ? 'brain' : 'principal'} intent bytes`);const scope = brain ? 'brain' : 'principal';if (Number(row.lifetime_ids) + 1 > limits[`${scope}LifetimeIds`]) throw await cumulativeCapacityError(tx, `${scope} permanent request IDs`,row.key, `${scope}LifetimeIds`, Number(row.lifetime_ids), limits[`${scope}LifetimeIds`]);@@ -644,8 +658,7 @@ export async function deferralRoom(tx: SqlEngine, worktreeId: string, capability/** The refresh to defer this write behind, or null when it is admitted normally; otherwise refuses. */async function assertWorktreeNotRefreshing(tx: BrainEngine, input: WriteAdmission, refresh: { id: string; state: string; source_ids: string[] }, replayable: boolean,barrier: boolean): Promise<string | null> {- const managedSync = input.operation === 'submit_job' && String(input.intent.kind ?? '').startsWith('managed_sync_');- if (refresh.state === 'syncing' && managedSync) return null;+ if (refresh.state === 'syncing' && managedSyncJob(input)) return null;if (refresh.state === 'syncing') {const completed = await tx.executeRaw(`UPDATE persistence_worktree_refreshes f SET state='completed',completed_at=now(),updated_at=now()WHERE f.id=$1::uuid AND f.state='syncing' AND NOT EXISTS (SELECT 1 FROM sources s WHERE s.id=ANY(f.source_ids)diff --git a/src/core/persistence/refresh-barrier.ts b/src/core/persistence/refresh-barrier.tsindex 20e09a71bf..8052fe4ec2 100644--- a/src/core/persistence/refresh-barrier.ts+++ b/src/core/persistence/refresh-barrier.ts@@ -99,7 +99,8 @@ export const overdueDeferredWorkSql = (host: string) => `(EXISTS (SELECT 1 FROM* `pending_import`), so the first sync that imports the file replays the fact. Its claim and its expiry both move the row,* so the expiry checks the row is still unclaimed and its import still pending with the sources row locked FOR SHARE* (after the protocol's brain lock, the order a fence takes them in), so an import that is landing makes the check wait- * and then see it landed.+ * and then see it landed. GST-1623: it also rechecks the hold it scanned (the same import and an age past the limit), so an+ * import and a new hold between the scan and the lock never expire the new hold.*/export async function expireDeferredWrites(engine: BrainEngine, hostId: string, signal?: AbortSignal): Promise<WriteRequest[]> {const [config] = await engine.executeRaw<{ ms: number }>(`SELECT ${MAX_WAIT_SQL} AS ms`, undefined, { signal });@@ -119,11 +120,13 @@ export async function expireDeferredWrites(engine: BrainEngine, hostId: string,}const imports = await engine.executeRaw<WriteRequest>(`SELECT r.* FROM persistence_requests r ${overdueImportFrom('$1', '$2::double precision')}ORDER BY r.sequence LIMIT 100`, [hostId, maxWaitMs], { signal });+ await afterImportScan?.(imports);for (const row of imports) {const done = await engine.transaction(async tx => {await declarePersistenceProtocol(tx);const [held] = await tx.executeRaw(`SELECT 1 FROM persistence_requests r JOIN sources s ON s.id=r.source_id- WHERE r.id=$1::uuid AND r.state='deferred' AND COALESCE(s.last_commit,'')=r.deferred_import_from FOR SHARE OF s`, [row.id]);+ WHERE r.id=$1::uuid AND r.state='deferred' AND r.deferred_import_from=$2 AND COALESCE(s.last_commit,'')=r.deferred_import_from+ AND r.updated_at<now()-($3::double precision*interval '1 millisecond') FOR SHARE OF s`, [row.id, row.deferred_import_from, maxWaitMs]);if (!held) return null;if (row.operation === 'remember') return completeWrite(tx, row, 'conflict', {}, { code: 'source_changed', detail: { origin: PENDING_IMPORT },message: `Request ${row.request_id} waited more than ${Math.round(maxWaitMs / 1000)} s for managed sync to import a committed change to the file of ${row.slug}, and the import has not landed, so the fact is not saved yet. It is kept: the first managed sync that imports the file replays it once. Do not save it again; check the source with gbrain sync status --source ${row.source_id} --json.` });@@ -155,5 +158,9 @@ export async function deferredBacklog(engine: SqlEngine): Promise<{ count: numbereturn { count: Number(row?.count ?? 0), oldest_age_ms: Number(row?.oldest_age_ms ?? 0) };}+let afterImportScan: ((rows: WriteRequest[]) => Promise<void>) | null = null;+/** Test seam: runs between the expiry's scan of import holds and their transactions. */+export function _setAfterImportExpiryScanForTests(fn: typeof afterImportScan): void { afterImportScan = fn; }+/** Test seam: forget every cached refresh diff. */export function _resetRefreshBarrierCacheForTests(): void { changed.clear(); }diff --git a/test/import-write-barrier.test.ts b/test/import-write-barrier.test.tsindex 1fdbcee37e..222300e329 100644--- a/test/import-write-barrier.test.ts+++ b/test/import-write-barrier.test.ts@@ -24,7 +24,7 @@ import { PersistenceConsumer } from '../src/core/persistence/consumer.ts';import { getWriteRequestById } from '../src/core/persistence/journal.ts';import { resetWriteSwitches } from '../src/core/persistence/switches.ts';import { _setRefreshFenceWaitForTests } from '../src/core/persistence/admission-retry.ts';-import { _resetRefreshBarrierCacheForTests, deferredBacklog, expireDeferredWrites } from '../src/core/persistence/refresh-barrier.ts';+import { _resetRefreshBarrierCacheForTests, _setAfterImportExpiryScanForTests, deferredBacklog, expireDeferredWrites } from '../src/core/persistence/refresh-barrier.ts';import { submitPageMutation } from '../src/core/persistence/page-mutations.ts';import { runPersistenceEffects } from '../src/core/persistence/effects.ts';import { localHostId } from '../src/core/persistence/identity.ts';@@ -33,7 +33,9 @@ import { refreshWorktree, resumeWorktreeRefreshes } from '../src/core/persistencimport { readLedger } from '../src/core/git/commit-ledger.ts';import type { WriteRequest } from '../src/core/persistence/model.ts';import { replayImportedRemembers } from '../src/core/repair/failed-writes.ts';+import { withCoordinatedWrite } from '../src/core/persistence/context.ts';import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';+import { TEST_WRITE_ATTRIBUTION } from './helpers/write-attribution.ts';import { testBackends } from './helpers/test-backends.ts';import { withEnv } from './helpers/with-env.ts';import { commitFile, git, page, withRefreshFixture, type RefreshFixture } from './helpers/worktree-refresh-fixture.ts';@@ -137,15 +139,19 @@ test('a blind put_page onto a file awaiting import is held pending, lands afterexpect((await deferredBacklog(f.engine)).count).toBe(0);}), 180_000);-test('a capture onto a file awaiting import lands after the import', () => each(async f => {- foreignCommit(f, 'one.md', page('Alpha one', IMPORTED));+test('a capture onto a file awaiting import lands after the import and names the imported revision it replaced', () => each(async f => {+ const imported = foreignCommit(f, 'one.md', page('Alpha one', IMPORTED));const out = await local(f, 'capture', { slug: 'one', content: 'Captured while the import waited.' });expect(out.pending).toBe(true);const held = await requestRow(f, out.receipt.request_id);expect(held.state).toBe('deferred');await importNow(f);- expect((await settle(f, held)).state).toBe('committed');+ const done = await settle(f, held);+ expect(done.state).toBe('committed');expect(file(f, 'one.md')).toContain('Captured while the import waited.');+ const supersedes = (done.outcome as { supersedes?: { slug: string; revision: unknown; commit: string } }).supersedes;+ expect(supersedes).toMatchObject({ slug: 'one', commit: imported });+ expect(supersedes!.revision).toBeTruthy();}), 180_000);const PERSON = '---\ntitle: Alice Example\ntype: person\n---\nAlice is a person.\n';@@ -397,3 +403,44 @@ test.skipIf(!backends.includes('postgres'))('a held write whose import lands whiexpect(file(f, 'one.md')).toContain('Held, then released by the import.');}), 180_000);++test('a write held for an import never takes the capacity the import needs', () => each(async f => {+ await f.engine.setConfig('persistence.limits.principal_outstanding', '1');+ try {+ foreignCommit(f, 'one.md', page('Alpha one', IMPORTED));+ const out = await local(f, 'put_page', { slug: 'one', content: page('Alpha one', 'Mine, held while the cap is full.') });+ expect(out.pending).toBe(true);+ const held = await requestRow(f, out.receipt.request_id);+ expect(held.state).toBe('deferred');+ await importNow(f);+ expect(await f.lastCommit(f.alpha)).toBe(git(f.root, 'rev-parse', 'HEAD'));+ expect((await settle(f, held)).state).toBe('committed');+ expect(file(f, 'one.md')).toContain('Mine, held while the cap is full.');+ } finally {+ await f.engine.executeRaw("DELETE FROM config WHERE key='persistence.limits.principal_outstanding'");+ }+}), 180_000);+++test('GST-1623: an import and a new hold between the expiry scan and its lock never expire the new hold', () => each(async f => {+ foreignCommit(f, 'one.md', page('Alpha one', IMPORTED));+ const out = await local(f, 'put_page', { slug: 'one', content: page('Alpha one', 'Mine, held again after an import.') });+ const held = await requestRow(f, out.receipt.request_id);+ expect(held.state).toBe('deferred');+ await maxWait(f, 1);+ await new Promise(resolve => setTimeout(resolve, 20));+ const next = foreignCommit(f, 'one.md', page('Alpha one', 'A second commit, not imported yet.'));+ _setAfterImportExpiryScanForTests(async rows => {+ expect(rows.map(row => row.id)).toEqual([held.id]);+ await f.engine.transaction(tx => withCoordinatedWrite(tx, [f.alpha], () => tx.executeRaw('UPDATE sources SET last_commit=$2 WHERE id=$1', [f.alpha, next]), TEST_WRITE_ATTRIBUTION));+ await f.engine.executeRaw("UPDATE persistence_requests SET deferred_import_from=$2,updated_at=now() WHERE id=$1::uuid", [held.id, next]);+ });+ try {+ expect(await expireDeferredWrites(f.engine, await ownerHost(f))).toEqual([]);+ } finally {+ _setAfterImportExpiryScanForTests(null);+ await f.engine.executeRaw("DELETE FROM config WHERE key='persistence.refresh_barrier_max_wait_ms'");+ }+ expect(await getWriteRequestById(f.engine, held.id)).toMatchObject({ state: 'deferred', deferred_import_from: next });+}), 180_000);+diff --git a/test/refresh-write-barrier.test.ts b/test/refresh-write-barrier.test.tsindex ba26ef2d1d..11d722d64c 100644--- a/test/refresh-write-barrier.test.ts+++ b/test/refresh-write-barrier.test.ts@@ -613,3 +613,21 @@ test('GST-1674: a refresh killed after its merge, with a commit landed on the taexpect((await settle(f, deferred)).state).toBe('committed');}), 180_000);++test('GST-1623: a write deferred behind a refresh never takes the capacity its refresh sync needs', () => each(async f => {+ try {+ let deferred!: WriteRequest;+ const refresh = await duringRefresh(f, async () => {+ await f.engine.setConfig('persistence.limits.brain_outstanding', String(await outstanding(f) + 1));+ const out = await call(f, 'put_page', { slug: 'notes/held-at-cap', content: page('Held', 'written while the cap is full') });+ expect(out.body).toMatchObject({ status: 'pending' });+ deferred = await requestRow(f, out.body.request_id);+ expect(deferred.state).toBe('deferred');+ });+ expect((await refresh).status).toBe('completed');+ expect((await settle(f, deferred)).state).toBe('committed');+ } finally {+ await f.engine.executeRaw("DELETE FROM config WHERE key='persistence.limits.brain_outstanding'");+ }+}), 180_000);+