Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Keep stored takes when a writer re-creates a dropped takes section

garrytanc4567118f5e4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8b1d8ab6f4..716b60b28d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,18 @@ credits are retained; no result has been reassigned to another provider. Origina
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [Unreleased]
+
+**A take no longer disappears when gbrain re-creates a takes section that a page rewrite dropped.** When a page was rewritten without its takes section, its takes stayed stored, but the next `think --take --anchor <slug>` or `gbrain takes extract --from-pages` on that page built a fresh section numbered from 1: the new take replaced stored take #1 in place, with no record of the old one, and on a managed brain `takes extract --from-pages --include-covered` replaced the first stored takes and deleted the rest in the same write. These writers now render the stored takes, resolutions included, into the section they create and number their own takes after them, on repo-less, Git-backed and plain-directory brains. A take the user removed, or an explicit empty section retired, stays removed. A stored take whose resolution has no quality (recorded before takes had one) cannot be written into the section, so the write is refused (`invalid_input`) instead of clearing it. `takes extract --from-pages` skips a page whose takes markers are malformed (for example `<!-- gbrain:takes:begin -->` with two dashes) as `fence_unparsed` and goes on to the next page.
+
+### Itemized changes
+
+- `src/core/takes-write.ts`: `withStoredTakesFence` renders a page's stored takes (resolution cells included) into a new takes section when the body has no takes fence, refusing `fence_unparsed` when the body holds malformed takes markers, `invalid_input` when a stored resolution has no quality, and `invalid_input` when the render would not read back row for row. Used by `addTakeToPage` (`think --take`) and `appendTakesToPageMdFirst` (unmanaged `takes extract --from-pages`).
+- `src/core/extract-takes-from-pages.ts`: the managed `takes extract --from-pages` put composes from the same rendered section and dedupes new claims against those takes; a page the helper refuses is skipped with the refusal's code instead of ending the run.
+- `src/core/behavior-change-notice.ts`: one row for the changed behavior.
+- Docs: `docs/architecture/key-files/hindsight.md`.
+- Tests: `test/recreated-takes-section-keeps-stored-takes.test.ts` (`think --take` and `takes extract` on unmanaged brains, a plain directory and Git; managed extraction, repo-less and Git; removed takes, `takes remove` and empty sections stay removed; malformed markers skip one page; a resolution without a quality refuses; PGLite and Postgres).
+
## [0.60.627.0] - 2026-11-09
**A webhook capture can no longer drop a page's readers (GST-2112).** `POST /ingest` wrote through a trusted local path whose only check was that the sender could read the page, so a member-bound token granted a source could replace a page whose `readable_by` named it with a body that named no readers, and every caller could then read the page. The route and the `ingest_capture` job now apply the remote `put_page` readers rule: a body that drops `readable_by` from a page that names readers, or names readers that leave out the sender, is refused `readable_by_invalid` (403 at the route, nothing queued; at write time for a job already queued). The job binds its write to the revision it checked, so readers added between the check and the write refuse the write with `revision_conflict` and the retry refuses `readable_by_invalid`. A capture already queued from a member-bound credential whose write source is `default` is refused `permission_denied` at write time, as the route refuses it before queueing. Bodies that keep the readers, and pages without readers, import as before.
diff --git a/docs/architecture/key-files/hindsight.md b/docs/architecture/key-files/hindsight.md
index d9079de021..3a237363cd 100644
--- a/docs/architecture/key-files/hindsight.md
+++ b/docs/architecture/key-files/hindsight.md
@@ -35,7 +35,7 @@ unresolvable+true|false, pre-v80 NULL/NULL rows survive).
- `src/commands/calibration.ts` — CLI: `gbrain calibration` (read + print), `--regenerate`, `--undo-wave <ver>`, `ab-report`. MCP op `get_calibration_profile` (scope: read) backs the same data path. Source-scoped via `sourceScopeOpts(ctx)`.
- `src/core/owner-holder.ts` — single source of truth for "the brain owner" holder string. `DEFAULT_OWNER_HOLDER = 'self'` (matches the consolidate facts→takes writer + `docs/takes-vs-facts.md`); `resolveOwnerHolder({override, configValue})` returns override > `emotional_weight.user_holder` config > `'self'`. Consumed by the calibration_profile cycle phase, `gbrain calibration` CLI, the `get_calibration_profile` op, `think`'s calibration block, `emotional-weight`'s `DEFAULT_USER_HOLDER`, and doctor's `calibration_freshness`. Pure; unit-tested in `test/owner-holder.test.ts`. Does NOT unify owner-identity fragmentation (`self`/`brain`/`people-<owner>`) — tracked separately.
- `src/commands/takes.ts` — the full `gbrain takes` subcommand dispatcher (list/search/embed/add/update/supersede/resolve/propose/scorecard/calibration/extract/revisit). `takes list --limit N --offset N` validates integers at the CLI; the engine clamps limit (default 100, cap 500) and floors offset at 0. `takes revisit <slug>` opens $EDITOR on the source page with a `<!-- gbrain:revisit -->` cursor marker. #5167: `takes remove <slug> --row N` goes through `takes-mutation.ts` to the local-only `takes_remove` op (persistence `takes-prepare.ts`): the row leaves the takes table and its fence row becomes a reservation row (`| N | ~~(removed)~~ | take | world | 0.0 | | removed |`, W9F item 4) in one coordinated publication, other row numbers stay, and a resolved row, a row another row cites as "superseded by" it, or a row whose DB claim disagrees with the fence is refused (the last names `takes rebuild`); thin clients are refused. Reservations: `parseTakesFence` returns them in `reservedRowNums`, never in `takes`, so no reader or projection sees a take there; `renderTakesFence(takes, reservedRowNums)` puts them back in row order, and `upsertTakeRow`, `supersedeRow` and `takesPreparation.replaceFence` keep the reservations of the body they rewrite. Every new take row number comes from GBRA-54's `nextFreeRowNum` (`fence-repair/normalize.ts`): one more than every fence row on the page (facts and takes, live, struck and reserved) and, in `takes-prepare.ts`, every stored facts/takes row (`storedFenceRows`), revalidated under the publication lock; the promise holds while the reservation row exists. #6450: `takes_add` and an explicit `takes_supersede` holder override are trimmed and checked with `isValidHolder` at the write boundary (syntax before authority: `invalid_params` naming the grammar, before `assertHolderAllowed`); the inherited supersede holder is not re-validated (the existing fence already round-tripped). Every prepared takes fence is parsed again before publication and refused `invalid_params` on any warning, so no write can leave a fence the next write would refuse. Test: `test/takes-holder-validation-6450.test.ts`. `test/takes-row-reservation.test.ts` (both engines), `test/takes-reservation-callers.test.ts` (census of `parseTakesFence` callers). `takes rebuild <slug> [--source-id]` runs the local-only `takes_rebuild` op (W9F item 8; `runTakesRebuild` in `takes-mutation.ts`, delegated to a resident `gbrain serve` owner over persistence IPC, else the local engine, with the same JSON, warnings and exit 1 on a missing page or a warning), which calls `extractTakes({source:"db", slugs:[slug], sourceId, rebuild:true})`, whose rebuild now deletes only indexed rows whose (row_num, claim) left the fence, so matching rows keep resolutions and vectors. The v0_28_0 hint names `gbrain reindex --markdown` instead of the nonexistent `extract takes --rebuild`. GBRA-130 A-25: `takes propose --failed [--source <id>] [--json]` lists pages propose_takes held with a failure tombstone (`listFailedProposals`); `takes propose --retry-failed [--slug <slug>] [--source <id>] [--json]` deletes their tombstones and ledger records (`retryFailedProposals`) so the next run re-extracts them.
-- `src/core/extract-takes-from-pages.ts` — bootstrap extraction selects uncovered pages newest first. Managed pages capture their revision before classification and publish the complete appended takes fence through coordinated `put_page`, whose canonical projection commits the takes rows with the page; conflicts skip that page. Unmanaged pages take the same database path when the database is their copy of record (`sync.write_through` off, or the page in a declared `storage.db_only` directory; an unbound Postgres source skips that page `owner_unavailable`), and so does a file-backed page of a source with a canonical owner (bound before the run, or bound by the run's own first `put_page`, as PGLite does), so a mixed batch never reaches the fenced md-first writer; other unmanaged pages retain the md-first writer. A file-backed page whose file is missing is skipped as `mirror_unavailable` before the classifier runs. Pinned by `test/persistence-managed-takes-extract.test.ts`, `test/extract-takes-md-first.test.ts` and `test/pathological/d19-takes-bootstrap-db-only.test.ts`. `takes extract --before <updated_at>,<id>` (CLI-only) continues strictly below a prior run's `next_before`, an `(updated_at, id)` keyset with exact timestamptz text, so zero-claim pages no longer starve older ones; a budget stop resumes at the first unclassified page, a failed page stays uncovered for the next run without `--before`, and a malformed cursor is an exit-2 `invalid_params` refusal before any page is read. Pinned by `test/extract-takes-from-pages-progression.test.ts`, `test/takes-extract-json.test.ts` and `test/e2e/takes-extract-cursor-postgres.test.ts`.
+- `src/core/extract-takes-from-pages.ts` — bootstrap extraction selects uncovered pages newest first. Managed pages capture their revision before classification and publish the complete appended takes fence through coordinated `put_page`, whose canonical projection commits the takes rows with the page; conflicts skip that page. Unmanaged pages take the same database path when the database is their copy of record (`sync.write_through` off, or the page in a declared `storage.db_only` directory; an unbound Postgres source skips that page `owner_unavailable`), and so does a file-backed page of a source with a canonical owner (bound before the run, or bound by the run's own first `put_page`, as PGLite does), so a mixed batch never reaches the fenced md-first writer; other unmanaged pages retain the md-first writer. When the page has no takes section but still has stored takes (a rewrite dropped the section), `withStoredTakesFence` (`src/core/takes-write.ts`, also used by `think --take`) renders them, resolutions included, into the section first, so new claims are deduped against them and number after them; a page it refuses (`fence_unparsed` for malformed takes markers in the file, `invalid_input` for a stored resolution without a quality) is skipped with that reason and the run goes on. Pinned by `test/recreated-takes-section-keeps-stored-takes.test.ts`. A file-backed page whose file is missing is skipped as `mirror_unavailable` before the classifier runs. Pinned by `test/persistence-managed-takes-extract.test.ts`, `test/extract-takes-md-first.test.ts` and `test/pathological/d19-takes-bootstrap-db-only.test.ts`. `takes extract --before <updated_at>,<id>` (CLI-only) continues strictly below a prior run's `next_before`, an `(updated_at, id)` keyset with exact timestamptz text, so zero-claim pages no longer starve older ones; a budget stop resumes at the first unclassified page, a failed page stays uncovered for the next run without `--before`, and a malformed cursor is an exit-2 `invalid_params` refusal before any page is read. Pinned by `test/extract-takes-from-pages-progression.test.ts`, `test/takes-extract-json.test.ts` and `test/e2e/takes-extract-cursor-postgres.test.ts`.
- `src/core/take-proposals.ts` — owns the `take_proposals` queue's row contract. `normalizeTakeProposalRow` coerces Postgres driver BigInt/string values (`id`, `weight`, `promoted_row_num`) to numbers at the query boundary so both engines return the same numeric row shape. `acceptProposal` promotes through a coordinated `takes_add` mutation (`submitPageMutation`, the same path `gbrain takes add` uses), so accept works on a managed brain where a direct fence write is refused with `writer_coordinator_required` (`test/takes-propose-accept-managed.test.ts`). #5214: an accepted proposal's take records `take_proposals#<id>` as its source; `acceptProposal(target, id, edits)` (`takes propose --accept <id> --claim/--weight/--who/--kind`) applies the edits as a plain takes_add with source `take_proposals#<id> (edited)` while the queue row keeps the original claim text.
- `admin/src/pages/Calibration.tsx` — Calibration tab. Single-column layout. `<TrustedSVG>` wrapper handles `dangerouslySetInnerHTML` for the server-rendered SVG.
- `admin/src/index.css` — `--text-muted: #777` (WCAG AA contrast bump to ~5.5 on the #0a0a0f bg).
diff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsv
index b2e0155d34..8ad74e26c1 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: link
src/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 1693 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); +2 GST-1601 source_changed_origin_gst1601 and adopt_local_edits_gst1601 rows (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.596.0 merge: 1668 + 2; +1 GST-1623 refresh_barrier_capacity_gst1623 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.599.0 merge: 1670 + 1; +2 GBRA-224 W1 release_channel_stable_default row and its comment; +1 GST-1623 refresh_barrier_later_write_gst1623 row (#8765; rows are data and cannot move); +5 #8766 GST-1623 items 4/6-9 and #8755: the wave comment and four rows (doctor_foreign_writers_partial_gst1623, commit_push_enclosing_repo_gst1623, owner_guard_fail_closed_gst1623, adopt_local_edits_hardening_8755) and +1 managed_sync_kind_reserved_8765 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on master v0.60.608.0 plus #8798: 1674 + 6; +1 GST-1853 refresh_barrier_aborted_refresh_sync_gst1853 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.613.0 merge: 1680 + 1; +1 GST-1674 refresh_refused_merge_recovery_gst1674 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.614.0 merge: 1681 + 1; +1 #8824/#8826/#8767: adopt_local_edits_replay_markers_8824 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8837: 1682 + 1; +1 url_source_origin row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8834: 1683 + 1; +1 #8828: the refresh_replan_own_commits_8828 row (1684 + 1 at the 0.60.618.0 slot); +1 the managed commit-push unpublished-count row; +1 the refresh publish-diverged default row; +1 GST-2051 ungranted_member_writes_gst2051 row (since TBD until the merge slot; rows are data and cannot move); +1 GST-731 think_window_trajectory_gst731 row and +1 GST-1602 purge_cancels_deferred_write_gst1602 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8915 v0.60.621.0: 1688 + 2; +1 GST-2059: owner_reads_private row; +1 #8888: the record-origin checkout lock-down row (re-summed at the Q6 stack on #8934 v0.60.625.0: 1691 + 1); +1 GST-2112: ingest_keeps_readers_gst2112 row (re-summed at the Q7 v0.60.627.0 merge: 1692 + 1)
+src/core/behavior-change-notice.ts 1694 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); +2 GST-1601 source_changed_origin_gst1601 and adopt_local_edits_gst1601 rows (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.596.0 merge: 1668 + 2; +1 GST-1623 refresh_barrier_capacity_gst1623 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.599.0 merge: 1670 + 1; +2 GBRA-224 W1 release_channel_stable_default row and its comment; +1 GST-1623 refresh_barrier_later_write_gst1623 row (#8765; rows are data and cannot move); +5 #8766 GST-1623 items 4/6-9 and #8755: the wave comment and four rows (doctor_foreign_writers_partial_gst1623, commit_push_enclosing_repo_gst1623, owner_guard_fail_closed_gst1623, adopt_local_edits_hardening_8755) and +1 managed_sync_kind_reserved_8765 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on master v0.60.608.0 plus #8798: 1674 + 6; +1 GST-1853 refresh_barrier_aborted_refresh_sync_gst1853 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.613.0 merge: 1680 + 1; +1 GST-1674 refresh_refused_merge_recovery_gst1674 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the master v0.60.614.0 merge: 1681 + 1; +1 #8824/#8826/#8767: adopt_local_edits_replay_markers_8824 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8837: 1682 + 1; +1 url_source_origin row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8834: 1683 + 1; +1 #8828: the refresh_replan_own_commits_8828 row (1684 + 1 at the 0.60.618.0 slot); +1 the managed commit-push unpublished-count row; +1 the refresh publish-diverged default row; +1 GST-2051 ungranted_member_writes_gst2051 row (since TBD until the merge slot; rows are data and cannot move); +1 GST-731 think_window_trajectory_gst731 row and +1 GST-1602 purge_cancels_deferred_write_gst1602 row (since TBD until the merge slot; rows are data and cannot move), re-summed at the gate-ahead on #8915 v0.60.621.0: 1688 + 2; +1 GST-2059: owner_reads_private row; +1 #8888: the record-origin checkout lock-down row (re-summed at the Q6 stack on #8934 v0.60.625.0: 1691 + 1); +1 GST-2112: ingest_keeps_readers_gst2112 row (re-summed at the Q7 v0.60.627.0 merge: 1692 + 1); +1 GST-2228: recreated takes section row
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 6c5239af17..7e52ac4a27 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1495,6 +1495,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.623.0', id: 'owner_reads_private_gst2059', text: 'A brain can now name its owner: `gbrain access owner set <member>` (config `access.owner_member`, an enabled member). Every remote credential or stdio server bound to that member reads the whole brain, `visibility: private` pages, privacy-alias pages (`access: private`, ...), derived and pinned-question pages included, through `get_page`, `search`, `query`, `recall` and the other page reads in the sources its grant reads, and `recall` returns its private facts. `readable_by` and folder rules still bind it, and it is not relaxed when it speaks for a shared-room audience. A page the owner\'s credential creates in `default` through `put_page` is not kept to the owner (no `readable_by: [member:<id>]`). Other members, unbound and public callers are unchanged. `_meta.access.relaxation` reads `owner` for such a call, and `gbrain access check --token <name>` reports it. `gbrain repair private-labels` (named runs only) previews the `access: private` labels stamped on ordinary pages with counts per category, keeps real restrictions, and clears the rest in reviewed batches (`--apply --expect <hash>`), recording each change so `--class restore` can put it back. The bulk-ingestion page template no longer writes an `access:` line; what each designation means is in docs/guides/access-designations.md.' },
{ since: '0.60.626.0', id: 'record_origin_checkout_lockdown_8888', text: '`gbrain sources record-origin <id>... --remote --apply` now also turns git-lfs downloads and hooks off in each recorded source\'s existing checkout (its `.git/config`: `lfs.fetchexclude=*`, `core.hooksPath=/dev/null`, `lfs.locksverify=false`), not only on later reclones, in the repository\'s shared config, and refuses `write_failed` naming the key when a worktree-scoped or included setting still overrides one; a source already recorded as remote gets the lock-down on the next `--remote --apply` when its checkout lacks it, even when its files now use git-lfs, and a key that holds several values in that config is replaced by the one clone-time value. On a managed brain it takes the same worktree locks a reclone takes, refusing the id `source_busy` while a reclone, refresh or write holds them, and a reclone reads the record under its own locks. A write that fails is reported for its own id (`write_failed`) instead of ending the run. The git-lfs check reads a committed `.gitattributes` under a directory whose name holds a tab, ignores commented-out `filter=lfs` lines, says when a committed rule only declares an LFS filter, records a clone of an empty repository instead of refusing it, and names the cause of an `lfs_unknown` refusal.' },
{ since: '0.60.627.0', id: 'ingest_keeps_readers_gst2112', text: 'A webhook capture (`POST /ingest` with `X-Gbrain-Slug` and its `ingest_capture` job) is now refused `readable_by_invalid` when its body drops `readable_by` from a page that names readers, or names readers that leave out the sending token or client: the route answers 403 and queues nothing, and a job already queued refuses at write time. Before, such a capture replaced the page and its readers, and every caller could read it. Bodies that keep the readers, and pages without readers, import as before.' },
+ { since: 'TBD', id: 'recreated_takes_section_keeps_stored_takes_gst2228', text: 'A takes section that gbrain re-creates on a page whose section a rewrite dropped now starts with the takes still stored for that page. `think --take --anchor <slug>` and `gbrain takes extract --from-pages` (also with `--include-covered` on a managed brain) render the stored takes, resolutions included, into the section they create and number their own takes after them, instead of numbering from 1 over a stored take. A take the user removed, or an explicit empty section retired, stays removed. A page whose stored take has a resolution without a quality, which the section cannot carry, is refused (`invalid_input`) instead of losing it, and `takes extract --from-pages` skips a page whose takes markers are malformed (`fence_unparsed`) and goes on to the next page.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/extract-takes-from-pages.ts b/src/core/extract-takes-from-pages.ts
index b633fcf4a8..d5c84c7367 100644
--- a/src/core/extract-takes-from-pages.ts
+++ b/src/core/extract-takes-from-pages.ts
@@ -27,6 +27,7 @@ import {
resolveTakesRepoDir,
resolveTakesWritePath,
TakesWriteError,
+ withStoredTakesFence,
} from './takes-write.ts';
import { getWorktreeBinding, managedPersistenceEnabled } from './persistence/ownership.ts';
import { isWriteThroughDisabled, resolvePageWriteTarget } from './write-through.ts';
@@ -374,9 +375,16 @@ export async function extractTakesFromPages(
// Never append a claim the page's takes fence already holds (a rerun with
// includeCovered, or a hand-added take): duplicate gradeable takes skew
// calibration. The fence is canonical, so dedupe against its active rows.
- const duplicateBody = fromDatabase
- ? serializePageToMarkdown(managedSnapshot!.page, managedSnapshot!.tags)
- : readFileSync(mdPath!, 'utf-8');
+ let duplicateBody: string;
+ try {
+ duplicateBody = await withStoredTakesFence(engine, page.id, fromDatabase
+ ? serializePageToMarkdown(managedSnapshot!.page, managedSnapshot!.tags)
+ : readFileSync(mdPath!, 'utf-8'));
+ } catch (err) {
+ if (!(err instanceof TakesWriteError)) throw err;
+ skipPage(page.slug, err.code);
+ continue;
+ }
const held = new Set(parseTakesFence(duplicateBody).takes
.filter((t) => t.active).map((t) => claimKey(t.claim, t.holder)));
const safeClaims = claims.filter((c) => {
@@ -399,7 +407,7 @@ export async function extractTakesFromPages(
source: 'cli:takes-bootstrap-from-pages',
}));
if (fromDatabase) {
- const body = await materializeTakeResolutions(engine, managedSnapshot!.page.id, serializePageToMarkdown(managedSnapshot!.page, managedSnapshot!.tags));
+ const body = await materializeTakeResolutions(engine, managedSnapshot!.page.id, duplicateBody);
const composed = appendTakesToPageBody(body, rows);
const { operations } = await import('./operations.ts');
const putPage = operations.filter(operation => !operation.localOnly).find(operation => operation.name === 'put_page');
diff --git a/src/core/takes-write.ts b/src/core/takes-write.ts
index 763c151548..d1dbd6f241 100644
--- a/src/core/takes-write.ts
+++ b/src/core/takes-write.ts
@@ -503,6 +503,56 @@ export async function materializeTakeResolutions(engine: BrainEngine, pageId: nu
return next;
}
+/**
+ * Every stored take of page `pageId` as its fence row, in row order, resolution cells included. A rewrite that dropped
+ * the page's takes fence leaves exactly these rows stored (held `fence_absent` on a managed brain, kept by the takes
+ * reconcile on an unmanaged one); a take the user removed, or an empty fence retired, is no longer among them. A stored
+ * resolution with no quality, which the fence cannot carry, refuses (`invalid_input`) instead of being dropped.
+ */
+async function storedTakeRows(engine: BrainEngine, pageId: number): Promise<ParsedTake[]> {
+ const rows = await engine.executeRaw<{ row_num: number; claim: string; kind: TakeKind; holder: string; weight: number; since_date: string | null; until_date: string | null;
+ source: string | null; active: boolean; resolved_at: Date | string | null; resolved_quality: TakeQuality | null; resolved_outcome: boolean | null; resolved_source: string | null;
+ resolved_value: number | string | null; resolved_unit: string | null; resolved_by: string | null }>(`SELECT row_num, claim, kind, holder, weight, since_date, until_date, source, active,
+ resolved_at, resolved_quality, resolved_outcome, resolved_source, resolved_value, resolved_unit, resolved_by FROM takes WHERE page_id=$1 ORDER BY row_num`, [pageId]);
+ return rows.map(t => {
+ if (t.resolved_at !== null && !t.resolved_quality) {
+ throw new TakesWriteError('invalid_input', `Take row #${t.row_num} has a resolution without a quality, which the takes fence cannot carry; re-creating the takes section would clear it.`);
+ }
+ return { rowNum: Number(t.row_num), claim: t.claim, kind: t.kind, holder: t.holder, weight: Number(t.weight), active: t.active,
+ ...(t.since_date ? { sinceDate: t.since_date } : {}), ...(t.until_date ? { untilDate: t.until_date } : {}), ...(t.source ? { source: t.source } : {}),
+ ...(t.resolved_quality ? { resolvedQuality: t.resolved_quality, ...(t.resolved_at ? { resolvedAt: new Date(t.resolved_at).toISOString() } : {}),
+ ...(t.resolved_outcome !== null ? { resolvedOutcome: t.resolved_outcome } : {}), ...(t.resolved_source ? { resolvedEvidence: t.resolved_source } : {}),
+ ...(t.resolved_value !== null ? { resolvedValue: Number(t.resolved_value) } : {}), ...(t.resolved_unit ? { resolvedUnit: t.resolved_unit } : {}),
+ ...(t.resolved_by ? { resolvedBy: t.resolved_by } : {}) } : {}) };
+ });
+}
+
+/**
+ * `body` with the page's stored takes (`storedTakeRows`) rendered into a new takes section when it has no takes fence
+ * marker at all, else unchanged. The writers that create the fence (`addTakeToPage`, `appendTakesToPageMdFirst` and
+ * the managed `takes extract --from-pages` put) go through this, so their own rows number after the stored ones:
+ * otherwise they number from 1, overwrite stored takes in place, and the next projection deletes the rest. A body with
+ * a near-miss marker (`<!-- gbrain:takes:begin -->`) refuses `fence_unparsed`, as each writer refuses it without
+ * stored takes, and a render that would not read back row for row refuses (`invalid_input`) instead of dropping a take.
+ */
+export async function withStoredTakesFence(engine: BrainEngine, pageId: number, body: string): Promise<string> {
+ const { beginIdx, endIdx } = locateOutsideCode(body, TAKES_FENCE_BEGIN, TAKES_FENCE_END);
+ if (beginIdx !== -1 || endIdx !== -1) return body;
+ const rows = await storedTakeRows(engine, pageId);
+ if (!rows.length) return body;
+ assertFenceRoundTrips(parseTakesFence(body));
+ for (const row of rows) {
+ for (const [field, value] of [['claim', row.claim], ['source', row.source], ['resolved_source', row.resolvedEvidence], ['resolved_unit', row.resolvedUnit], ['resolved_by', row.resolvedBy]] as const) {
+ assertSafeCellText(field, value);
+ }
+ }
+ const next = replaceFence(upsertTakeRow(body, rows[0]!).body, rows);
+ const reparsed = parseTakesFence(next);
+ assertFenceRoundTrips(reparsed);
+ if (reparsed.takes.length !== rows.length) throw new TakesWriteError('invalid_input', 'The takes fence lost rows while carrying the stored takes of the page.');
+ return next;
+}
+
/** Compose the same append sequence used by the legacy md-first writer. */
export function appendTakesToPageBody(body: string, rows: ReadonlyArray<AddTakeInput>): { body: string; rowNums: number[] } {
for (const row of rows) {
@@ -557,7 +607,7 @@ export async function addTakeToPage(
const { path, writeRoot } = await resolveTakesFilePath(
target.engine, target.brainDir, target.slug, target.sourceId,
);
- const body = existsSync(path) ? readFileSync(path, 'utf-8') : '';
+ const body = await withStoredTakesFence(target.engine, pageId, existsSync(path) ? readFileSync(path, 'utf-8') : '');
// F1: guard only fires when a fence ALREADY exists (an empty/fence-less body
// parses to zero warnings) — a whole-fence re-render must not delete rows
// this version couldn't parse.
@@ -630,7 +680,7 @@ export async function appendTakesToPageMdFirst(
);
// Unlike addTakeToPage, a missing file REFUSES (readPageBody's
// mirror_unavailable) — see the contract note above.
- const body = readPageBody(path);
+ const body = await withStoredTakesFence(target.engine, pageId, readPageBody(path));
const { body: nextBody, rowNums } = appendTakesToPageBody(body, rows);
writePageBody(path, nextBody, writeRoot, target.slug);
// Mirror md→DB with the reconcile primitive, exactly as the fence now
diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txt
index e9e6d75f6e..0eb41cde41 100644
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@ -465,6 +465,7 @@ test/reason-trailers-gbra217.test.ts
test/recall-page-fill.test.ts
test/receipt-compaction-newest-sync-gbra130.test.ts
test/reconcile-clears-stalled-hold-7364.test.ts
+test/recreated-takes-section-keeps-stored-takes.test.ts
test/refresh-barrier-gst1623.test.ts
test/refresh-barrier-held-after-abort.test.ts
test/refresh-barrier-purge-gst1602.test.ts
diff --git a/test/recreated-takes-section-keeps-stored-takes.test.ts b/test/recreated-takes-section-keeps-stored-takes.test.ts
new file mode 100644
index 0000000000..004b365957
--- /dev/null
+++ b/test/recreated-takes-section-keeps-stored-takes.test.ts
@@ -0,0 +1,258 @@
+/**
+ * A page whose takes section was dropped keeps its takes stored: on an unmanaged brain the takes reconcile keeps a
+ * fenceless page's rows, and on a managed one the projection holds them `fence_absent` until the user decides. Three
+ * gbrain writers used to build a brand-new takes section numbered from row 1 on such a page: `think --take`
+ * (addTakeToPage) and unmanaged `takes extract --from-pages` (appendTakesToPageMdFirst) overwrote stored take #1 in
+ * place with no record, and managed `takes extract --from-pages --include-covered` overwrote takes 1..k and deleted the
+ * rest in one put. Each writer now renders the stored takes (resolutions included) into the section it creates and
+ * numbers its rows after them. A take the user removed, and takes an explicit empty section retired, stay removed.
+ * A page whose takes markers are malformed is skipped by the extraction run (which goes on to the next page), and a
+ * stored resolution without a quality, which the section cannot carry, makes the writer refuse instead of dropping it.
+ * Unmanaged brain (a plain directory and a Git repo) and managed brain (repo-less and Git); PGLite, and Postgres from
+ * test/postgres-unit-arms.txt.
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { randomUUID } from 'node:crypto';
+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import type { BrainEngine } from '../src/core/engine.ts';
+import type { OperationContext } from '../src/core/ops/contract.ts';
+import { operationsByName } from '../src/core/operations.ts';
+import { configureGateway, resetGateway, __setChatTransportForTests } from '../src/core/ai/gateway.ts';
+import { extractTakes } from '../src/core/cycle/extract-takes.ts';
+import { extractTakesFromPages } from '../src/core/extract-takes-from-pages.ts';
+import { emptyFenceBlock } from '../src/core/generations/fence.ts';
+import { importFromFile } from '../src/core/import-file.ts';
+import { parseTakesFence } from '../src/core/takes-fence.ts';
+import { persistTakeFromSynthesis } from '../src/core/think/persist-take.ts';
+import { _resetWriteThroughCacheForTest } from '../src/core/write-through.ts';
+import { durableGitRepo } from './helpers/git-publication.ts';
+import { managedBrain, settleManagedGitEffects } from './helpers/managed-brain.ts';
+import { withManagedFixtureWrite } from './helpers/managed-e2e-fixture-write.ts';
+import { isolatedSharedSkillsEngine } from './helpers/shared-skills-engine.ts';
+import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';
+import { withEnv } from './helpers/with-env.ts';
+
+const SLUG = 'concepts/acme-example-outlook';
+const PROSE = 'Acme Example sells widgets to mid-size teams and has been growing steadily across several regions. '.repeat(3);
+const PAGE = (body: string) => `---\ntype: concept\ntitle: Acme Example outlook\n---\n\n# Acme Example outlook\n\n${PROSE}\n\n${body}`;
+const TAKE_A = 'Acme Example reaches profitability in 2027';
+const TAKE_A2 = 'Acme Example opens a second office';
+const THINK_CLAIM = 'Acme Example should raise prices this year.';
+const EXTRACTED = ['Acme Example hires a finance lead', 'Acme Example doubles its sales team'];
+const FENCE = (rows: string) => `## Takes\n\n<!--- gbrain:takes:begin -->\n| # | claim | kind | who | weight | since | source |\n|---|-------|------|-----|--------|-------|--------|\n${rows}<!--- gbrain:takes:end -->\n`;
+const ROW_A = `| 1 | ${TAKE_A} | bet | world | 0.6 | | manual |\n`;
+const ROW_A2 = `| 2 | ${TAKE_A2} | bet | world | 0.6 | | manual |\n`;
+
+let extracted: string[] = EXTRACTED;
+beforeAll(() => {
+ configureGateway({ chat_model: 'anthropic:claude-haiku-4-5-20251001', env: { ANTHROPIC_API_KEY: 'test-key' } });
+ __setChatTransportForTests(async () => {
+ const text = JSON.stringify(extracted.map(claim => ({ claim, kind: 'bet', weight: 0.7 })));
+ return { text, blocks: [{ type: 'text' as const, text }], stopReason: 'end' as const,
+ usage: { input_tokens: 1, output_tokens: 1, cache_read_tokens: 0, cache_creation_tokens: 0 },
+ model: 'anthropic:claude-haiku-4-5-20251001', providerId: 'anthropic' };
+ });
+});
+afterAll(() => { __setChatTransportForTests(null); resetGateway(); });
+
+const takes = (engine: BrainEngine) => engine.executeRaw<{ row_num: number; claim: string; resolved_quality: string | null }>(
+ "SELECT t.row_num, t.claim, t.resolved_quality FROM takes t JOIN pages p ON p.id=t.page_id WHERE p.source_id='default' AND p.slug=$1 ORDER BY t.row_num", [SLUG]);
+const claims = async (engine: BrainEngine) => (await takes(engine)).map(t => [t.row_num, t.claim]);
+const fileTakes = (path: string) => parseTakesFence(readFileSync(path, 'utf8')).takes.map(t => [t.rowNum, t.claim]);
+const extractFromPages = (engine: BrainEngine, maxPages = 1) => extractTakesFromPages(engine, { bootstrapEnabled: true, sourceIdFilter: 'default', maxPages, includeCovered: true });
+const OTHER = 'concepts/beta-example-outlook';
+const otherClaims = (engine: BrainEngine) => engine.executeRaw<{ row_num: number; claim: string }>(
+ "SELECT t.row_num, t.claim FROM takes t JOIN pages p ON p.id=t.page_id WHERE p.source_id='default' AND p.slug=$1 ORDER BY t.row_num", [OTHER])
+ .then(rows => rows.map(t => [t.row_num, t.claim]));
+const nearMiss = (content: string) => content.replaceAll('<!--- gbrain:takes:', '<!-- gbrain:takes:');
+const pageId = async (engine: BrainEngine) => Number((await engine.executeRaw<{ id: number }>("SELECT id FROM pages WHERE source_id='default' AND slug=$1", [SLUG]))[0]!.id);
+const storedResolution = (engine: BrainEngine) => engine.executeRaw<{ row_num: number; claim: string; resolved: boolean; resolved_quality: string | null; resolved_outcome: boolean | null }>(
+ "SELECT t.row_num, t.claim, t.resolved_at IS NOT NULL AS resolved, t.resolved_quality, t.resolved_outcome FROM takes t JOIN pages p ON p.id=t.page_id WHERE p.source_id='default' AND p.slug=$1 ORDER BY t.row_num", [SLUG]);
+/** A resolution recorded before takes had a quality column: outcome only. A managed brain takes it as a fixture write. */
+const qualitylessResolution = async (engine: BrainEngine, managed = false) => {
+ const id = await pageId(engine);
+ const write = (tx: BrainEngine) => tx.executeRaw("UPDATE takes SET resolved_at=now(), resolved_outcome=true, resolved_quality=NULL, resolved_by='system' WHERE page_id=$1 AND row_num=1", [id]);
+ await (managed ? withManagedFixtureWrite(engine, ['default'], write) : write(engine));
+};
+
+type Storage = 'directory' | 'git' | 'repo-less';
+const gitRepo = (root: string) => { writeFileSync(join(root, '.gitignore'), '\n'); durableGitRepo(root, ['.gitignore']); };
+
+/** An unmanaged brain (no canonical owner): pages come from files through the sync import and its takes reconcile. */
+async function unmanagedBrain(databaseUrl: string | undefined, storage: Storage, run: (b: { engine: BrainEngine; path: string; sync(content: string, slug?: string): Promise<void> }) => Promise<void>) {
+ const home = mkdtempSync(join(tmpdir(), 'gbrain-recreated-takes-'));
+ try {
+ await withEnv({ GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined }, async () => {
+ _resetWriteThroughCacheForTest();
+ const { engine, close } = await isolatedSharedSkillsEngine(databaseUrl);
+ try {
+ const root = join(home, 'brain');
+ mkdirSync(join(root, 'concepts'), { recursive: true });
+ if (storage === 'git') gitRepo(root);
+ await engine.executeRaw("UPDATE sources SET local_path=$1 WHERE id='default'", [root]);
+ await engine.setConfig('sync.repo_path', root);
+ const path = join(root, `${SLUG}.md`);
+ const sync = async (content: string, slug = SLUG) => {
+ writeFileSync(join(root, `${slug}.md`), content);
+ expect((await importFromFile(engine, join(root, `${slug}.md`), `${slug}.md`, { noEmbed: true })).status).toBe('imported');
+ await extractTakes(engine, { repoPath: root });
+ };
+ await run({ engine, path, sync });
+ } finally { await close(); }
+ });
+ } finally { rmSync(home, { recursive: true, force: true }); }
+}
+
+const op = (ctx: OperationContext, name: string, params: Record<string, unknown>) =>
+ operationsByName[name]!.handler(ctx, { request_id: randomUUID(), ...params }) as Promise<Record<string, unknown>>;
+const put = async (ctx: OperationContext, content: string) => {
+ const prior = await ctx.engine.readPageSnapshot(SLUG, { sourceId: 'default' });
+ await op(ctx, 'put_page', { slug: SLUG, content, ...(prior ? { expected_revision: prior.revision } : {}) });
+};
+const held = (engine: BrainEngine) => engine.executeRaw("SELECT kind FROM derived_generations WHERE source_id='default' AND owner_key=$1 AND state='held'", [`page:${SLUG}`]);
+
+for (const backend of testBackends()) {
+ const databaseUrl = backend === 'postgres' ? requirePostgresTestDatabase() : undefined;
+
+ for (const storage of ['directory', 'git'] as const) {
+ describe(`unmanaged brain (${backend}, ${storage}): a takes section re-created by gbrain keeps the stored takes`, () => {
+ test('think --take after the section was dropped keeps the stored take and its resolution', () => unmanagedBrain(databaseUrl, storage, async ({ engine, path, sync }) => {
+ await sync(PAGE(FENCE(ROW_A)));
+ const [{ id }] = await engine.executeRaw<{ id: number }>("SELECT id FROM pages WHERE source_id='default' AND slug=$1", [SLUG]);
+ await engine.resolveTake(Number(id), 1, { quality: 'correct', source: 'grader note', resolvedBy: 'system' });
+ await sync(PAGE('Rewritten without the takes section.\n'));
+ expect(await claims(engine)).toEqual([[1, TAKE_A]]);
+ const result = await persistTakeFromSynthesis(engine, { answer: THINK_CLAIM, synthesisOk: true } as never, { anchor: SLUG, sourceId: 'default' });
+ expect({ row: result.take_row, warnings: result.warnings }).toEqual({ row: 2, warnings: [] });
+ expect(await takes(engine)).toEqual([{ row_num: 1, claim: TAKE_A, resolved_quality: 'correct' }, { row_num: 2, claim: THINK_CLAIM, resolved_quality: null }]);
+ expect(fileTakes(path)).toEqual([[1, TAKE_A], [2, THINK_CLAIM]]);
+ expect(parseTakesFence(readFileSync(path, 'utf8')).takes[0]).toMatchObject({ resolvedQuality: 'correct', resolvedEvidence: 'grader note' });
+ await sync(readFileSync(path, 'utf8'));
+ expect(await takes(engine)).toEqual([{ row_num: 1, claim: TAKE_A, resolved_quality: 'correct' }, { row_num: 2, claim: THINK_CLAIM, resolved_quality: null }]);
+ }), 180_000);
+
+ test('takes extract --from-pages after the section was dropped keeps the stored take', () => unmanagedBrain(databaseUrl, storage, async ({ engine, path, sync }) => {
+ await sync(PAGE(FENCE(ROW_A)));
+ await sync(PAGE('Rewritten without the takes section.\n'));
+ expect(await extractFromPages(engine)).toMatchObject({ claims_extracted: 2, pages_skipped: 0 });
+ expect(await claims(engine)).toEqual([[1, TAKE_A], [2, EXTRACTED[0]], [3, EXTRACTED[1]]]);
+ expect(fileTakes(path)).toEqual([[1, TAKE_A], [2, EXTRACTED[0]], [3, EXTRACTED[1]]]);
+ await sync(readFileSync(path, 'utf8'));
+ expect(await claims(engine)).toEqual([[1, TAKE_A], [2, EXTRACTED[0]], [3, EXTRACTED[1]]]);
+ }), 180_000);
+
+ test('a take the user deleted from the section stays deleted after the section is dropped and re-created', () => unmanagedBrain(databaseUrl, storage, async ({ engine, path, sync }) => {
+ await sync(PAGE(FENCE(ROW_A + ROW_A2)));
+ await sync(PAGE(FENCE(ROW_A2)));
+ expect(await claims(engine)).toEqual([[2, TAKE_A2]]);
+ await sync(PAGE('Rewritten without the takes section.\n'));
+ const result = await persistTakeFromSynthesis(engine, { answer: THINK_CLAIM, synthesisOk: true } as never, { anchor: SLUG, sourceId: 'default' });
+ expect(result.take_row).toBe(3);
+ expect(await claims(engine)).toEqual([[2, TAKE_A2], [3, THINK_CLAIM]]);
+ expect(fileTakes(path)).toEqual([[2, TAKE_A2], [3, THINK_CLAIM]]);
+ }), 180_000);
+
+ test('takes retired by an explicit empty section stay retired after the section is dropped and re-created', () => unmanagedBrain(databaseUrl, storage, async ({ engine, path, sync }) => {
+ await sync(PAGE(FENCE(ROW_A)));
+ await sync(PAGE(`Emptied.\n\n${emptyFenceBlock('takes')}\n`));
+ expect(await claims(engine)).toEqual([]);
+ await sync(PAGE('Rewritten without the takes section.\n'));
+ expect(await extractFromPages(engine)).toMatchObject({ claims_extracted: 2 });
+ expect(await claims(engine)).toEqual([[1, EXTRACTED[0]], [2, EXTRACTED[1]]]);
+ expect(fileTakes(path)).toEqual([[1, EXTRACTED[0]], [2, EXTRACTED[1]]]);
+ }), 180_000);
+
+ test('takes extract --from-pages skips a page with malformed takes markers and goes on to the next page', () => unmanagedBrain(databaseUrl, storage, async ({ engine, path, sync }) => {
+ await sync(PAGE('Another page with no takes yet.\n'), OTHER);
+ await sync(PAGE(FENCE(ROW_A)));
+ const malformed = nearMiss(PAGE(FENCE(ROW_A)));
+ writeFileSync(path, malformed);
+ expect((await importFromFile(engine, path, `${SLUG}.md`, { noEmbed: true })).fences_normalized).toMatchObject([{ fence: 'takes', class: 'marker_form' }]);
+ await extractTakes(engine, { repoPath: join(path, '..', '..') });
+ expect(await claims(engine)).toEqual([[1, TAKE_A]]);
+ expect(await extractFromPages(engine, 2)).toMatchObject({ pages_scanned: 2, claims_extracted: 2, pages_skipped: 1, skipped: [{ slug: SLUG, reason: 'fence_unparsed' }] });
+ expect(await claims(engine)).toEqual([[1, TAKE_A]]);
+ expect(readFileSync(path, 'utf8')).toBe(malformed);
+ expect(await otherClaims(engine)).toEqual([[1, EXTRACTED[0]], [2, EXTRACTED[1]]]);
+ }), 180_000);
+
+ test('think --take refuses, and keeps the stored take, when its stored resolution has no quality', () => unmanagedBrain(databaseUrl, storage, async ({ engine, path, sync }) => {
+ await sync(PAGE(FENCE(ROW_A)));
+ await qualitylessResolution(engine);
+ const rewritten = PAGE('Rewritten without the takes section.\n');
+ await sync(rewritten);
+ const stored = [{ row_num: 1, claim: TAKE_A, resolved: true, resolved_quality: null, resolved_outcome: true }];
+ expect(await storedResolution(engine)).toEqual(stored);
+ const result = await persistTakeFromSynthesis(engine, { answer: THINK_CLAIM, synthesisOk: true } as never, { anchor: SLUG, sourceId: 'default' });
+ expect(result.take_row).toBeNull();
+ expect(result.warnings).toEqual([expect.stringContaining('TAKE_WRITE_FAILED: invalid_input')]);
+ expect(await storedResolution(engine)).toEqual(stored);
+ expect(readFileSync(path, 'utf8')).toBe(rewritten);
+ }), 180_000);
+ });
+ }
+
+ for (const storage of ['repo-less', 'git'] as const) {
+ const opts = { databaseUrl, ...(storage === 'git' ? { setup: ({ root }: { root: string }) => gitRepo(root) } : {}) };
+ const fileHolds = async (engine: BrainEngine, root: string, expected: string[]) => {
+ if (storage === 'git') await settleManagedGitEffects(engine);
+ expect(fileTakes(join(root, `${SLUG}.md`)).map(([, claim]) => claim)).toEqual(expected);
+ };
+
+ describe(`managed brain (${backend}, ${storage}): takes extract --from-pages --include-covered keeps held takes`, () => {
+ test('the held takes are kept and the extracted rows are numbered after them', () => managedBrain(async ({ engine, ctx, root }) => {
+ await put(ctx, PAGE('First version.\n'));
+ await op(ctx, 'takes_add', { slug: SLUG, claim: TAKE_A, kind: 'bet', holder: 'world' });
+ await op(ctx, 'takes_add', { slug: SLUG, claim: TAKE_A2, kind: 'bet', holder: 'world' });
+ await put(ctx, PAGE('Rewritten without the takes section.\n'));
+ expect(await claims(engine)).toEqual([[1, TAKE_A], [2, TAKE_A2]]);
+ extracted = EXTRACTED.slice(0, 1);
+ try { expect(await extractFromPages(engine)).toMatchObject({ claims_extracted: 1, pages_skipped: 0 }); } finally { extracted = EXTRACTED; }
+ expect(await claims(engine)).toEqual([[1, TAKE_A], [2, TAKE_A2], [3, EXTRACTED[0]]]);
+ await op(ctx, 'add_tag', { slug: SLUG, tag: 'example' });
+ expect(await claims(engine)).toEqual([[1, TAKE_A], [2, TAKE_A2], [3, EXTRACTED[0]]]);
+ expect(await held(engine)).toEqual([]);
+ await fileHolds(engine, root, [TAKE_A, TAKE_A2, EXTRACTED[0]]);
+ }, opts), 180_000);
+
+ test('a removed take stays removed when the extraction re-creates the section', () => managedBrain(async ({ engine, ctx, root }) => {
+ await put(ctx, PAGE('First version.\n'));
+ await op(ctx, 'takes_add', { slug: SLUG, claim: TAKE_A, kind: 'bet', holder: 'world' });
+ await op(ctx, 'takes_add', { slug: SLUG, claim: TAKE_A2, kind: 'bet', holder: 'world' });
+ await op(ctx, 'takes_remove', { slug: SLUG, row_num: 1 });
+ await put(ctx, PAGE('Rewritten without the takes section.\n'));
+ expect(await claims(engine)).toEqual([[2, TAKE_A2]]);
+ expect(await extractFromPages(engine)).toMatchObject({ claims_extracted: 2 });
+ await op(ctx, 'add_tag', { slug: SLUG, tag: 'example' });
+ expect((await claims(engine)).map(([, claim]) => claim)).toEqual([TAKE_A2, ...EXTRACTED]);
+ await fileHolds(engine, root, [TAKE_A2, ...EXTRACTED]);
+ }, opts), 180_000);
+
+ test('takes retired by an explicit empty section stay retired when the extraction re-creates the section', () => managedBrain(async ({ engine, ctx, root }) => {
+ await put(ctx, PAGE('First version.\n'));
+ await op(ctx, 'takes_add', { slug: SLUG, claim: TAKE_A, kind: 'bet', holder: 'world' });
+ await put(ctx, PAGE(`Emptied.\n\n${emptyFenceBlock('takes')}\n`));
+ expect(await claims(engine)).toEqual([]);
+ await put(ctx, PAGE('Rewritten without the takes section.\n'));
+ expect(await extractFromPages(engine)).toMatchObject({ claims_extracted: 2 });
+ await op(ctx, 'add_tag', { slug: SLUG, tag: 'example' });
+ expect(await claims(engine)).toEqual([[1, EXTRACTED[0]], [2, EXTRACTED[1]]]);
+ await fileHolds(engine, root, EXTRACTED);
+ }, opts), 180_000);
+
+ test('a stored resolution without a quality skips the page instead of being dropped', () => managedBrain(async ({ engine, ctx }) => {
+ await put(ctx, PAGE('First version.\n'));
+ await op(ctx, 'takes_add', { slug: SLUG, claim: TAKE_A, kind: 'bet', holder: 'world' });
+ await qualitylessResolution(engine, true);
+ await put(ctx, PAGE('Rewritten without the takes section.\n'));
+ const stored = [{ row_num: 1, claim: TAKE_A, resolved: true, resolved_quality: null, resolved_outcome: true }];
+ expect(await storedResolution(engine)).toEqual(stored);
+ expect(await extractFromPages(engine)).toMatchObject({ claims_extracted: 0, pages_skipped: 1, skipped: [{ slug: SLUG, reason: 'invalid_input' }] });
+ await op(ctx, 'add_tag', { slug: SLUG, tag: 'example' });
+ expect(await storedResolution(engine)).toEqual(stored);
+ }, opts), 180_000);
+ });
+ }
+}