Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge remote-tracking branch 'origin/master' into capy/gbra60-memory-quality

garrytan8432e69dd345
diff --cc CHANGELOG.md
index d6d991e23f,a39c9f7694..01a11dac19
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -10,71 -10,23 +10,88 @@@ credits are retained; no result has bee
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [Unreleased]
+
+**Hot memory is injected once per session in Claude Code: assistant-attributed and external facts no longer come back on every prompt, and the first prompt no longer repeats the session-start block.** The per-prompt block wrote its own fact line, which dropped the `(assistant said)` prefix, so an assistant suggestion read as your own claim and never matched the dedupe key built from the shared line; an external fact's `<external-data>` wrapper broke the match the same way. Separately, Claude Code records `gbrain hook session-start` output as a SessionStart `hook_success` entry, which the user-prompt hook did not read, so every fact the session-start block showed came back on the first prompt. And `gbrain facts relink` attached the assistant's own report about a page, which the SessionEnd corpus sweep saves as an assistant-attributed fact, to that page as an entity fact on every run, core pages included.
+
+### What changed
+
+| Situation | Before | Now |
+|---|---|---|
+| An assistant-attributed hot fact in the per-prompt block | rendered without `(assistant said)`, and injected again on every prompt | rendered with `(assistant said)`, injected once per session |
+| An `external_untrusted` hot fact | injected again on every prompt | injected once per session |
+| The first prompt after session start in Claude Code | repeated every hot fact the session-start block showed | skips them; core memory printed before the gbrain envelope does not hide page pointers |
+| Another tool's SessionStart output | ignored | still ignored |
+| A fact the assistant or a third party said that names a page, at `gbrain facts relink` (plain or `--conversation`) | attached to that page as an entity fact, core pages included, on every run | left where it was saved and counted as `not_user_attributed`; recall still finds it |
+| Doctor `unlinked_facts` | counted those facts as waiting for a link | does not count them |
+
+### What to watch for after you upgrade
+
+- Nothing runs on upgrade. A session already open when you upgrade sees each assistant fact once more, because its earlier blocks were rendered without the prefix.
+- Assistant or third-party facts a relink already attached to a page stay attached. Remove one with `gbrain forget <fact-id>`.
+
+### Itemized changes
+
+- `render()` in `src/core/context/turn-context.ts` uses `renderFactLine`, and the cross-turn dedupe key is that rendered line (or its unlabeled form) without the confidence.
+- `entryToInjectedBlock` in `src/core/transcripts/claude-code-jsonl.ts` accepts a SessionStart `hook_success` attachment whose `content` holds the gbrain envelope, keeping the text from the envelope on.
+- `entityLinkable` / `ENTITY_LINKABLE_SQL` in `src/core/facts/attribution.ts` gate `gbrain facts relink` (new skip reason `not_user_attributed`), `gbrain facts relink --conversation` (page pick, plan and the locked update) and doctor `unlinked_facts`.
+
+### Duplicate facts
+
+**Recall stops returning the same fact many times, and conversation extraction stops saving it again.** A standing prompt or instruction repeated in every session was extracted and stored once per session, and recall, the entity card and search `saved_facts` returned every copy, so a few copies could fill the whole `limit` and push distinct facts out.
+
+#### What changed
+
+| Situation | Before | Now |
+|---|---|---|
+| Recall, entity card, search `saved_facts` over stored copies of one claim | one row per copy; copies counted against `limit` | one row per claim (newest copy) with `collapsed_count`, and `entity_slugs` when the merged copies sit on several entities; collapsed before `limit` and after visibility filters |
+| Conversation extraction of a claim the source already holds | stored again for every page or session | skipped (`skipped N fact(s) an active fact of the source already states`); re-extracting a page still replaces its own facts |
+| Copies already stored | no way to retire them | `gbrain repair duplicate-facts` (explicit, preview-bound) supersedes every copy with the oldest row; cross-entity groups only with `--include-cross-entity` |
+| One source the backfill should leave alone | turn the whole phase off | `cycle.conversation_facts_backfill.exclude_sources` |
+
+#### What to watch for after you upgrade
+
+- Nothing runs on upgrade and nothing stored changes. Recall output adds two optional fields; every existing field keeps its meaning.
+- Preview with `gbrain repair duplicate-facts`, then run the printed `--apply --expect <hash> --yes` after you agree. Retired copies get `expired_at` and `superseded_by`; they are never deleted or withdrawn.
+- Near duplicates (different wording) are never merged or retired.
+
+### Opt-in session-only hot memory and chronicle diagnostics
+
+**Two small fixes: hot memory can stay inside the current session, and a refused chronicle answer says which check failed (#7026, #7234).**
+
+#### What changed
+
+| Situation | Before | Now |
+|---|---|---|
+| A session with no facts of its own asks for hot memory (turn hook, session-start pack) | it gets the source's newest facts from the last 24 hours, which can come from other sessions | unchanged by default; with `gbrain config set context.hot_memory.session_only true` it gets none, and a session with facts of its own gets only those |
+| The chronicle phase refuses a judge answer as `malformed_proposal` | only the reason code, so nobody could tell which check failed without the proposal itself | one warning line and a `malformed` field on the outcome name a fixed code (`missing_field`, `wrong_type`, `when_unparseable`, ...), the schema field, the JSON type found and counts; never a value, the prompt or the raw response |
+
+**Spend effect:** none. No new model calls, no default or cap changes. Nothing is rewritten on upgrade.
+
+#### Itemized changes
+
+- New DB-plane key `context.hot_memory.session_only` (default false), read per request by the `turn_context` and `context_pack` IPC handlers and passed to both hot-fact reads; it is part of the hot-memory cache key, so the fallback and session-only answers never share an entry. MCP `_meta.brain_hot_memory` and the IPC wire format are unchanged. Guide: [ambient writeback](docs/guides/ambient-writeback.md#hot-memory-and-other-sessions). Reported by @benswinney in #7026.
+- Chronicle `malformed_proposal` refusals carry bounded diagnostics (`src/core/chronicle/proposal-diagnostics.ts`): at most 50 proposals, 50 `who` entries and 256 characters per string are inspected, nested values are typed and never walked, and a defect past those bounds reads `beyond_bounds`. Refusal, retry/backoff, writes and admission are unchanged. Reported by @Masashi-Ono0611 in #7234.
+
+Duplicate facts reported by @mikez93 (#7043). Hot-memory dedupe reported by @benswinney (#7023). Session-start re-injection reported by @benswinney (#7026). Assistant facts relinked onto core pages reported by @andrew-agents-bot (#7270).
+
+ ## [0.60.397.0] - 2026-10-23
+
+ **A managed sync on a large, remote brain no longer loses its own drain lease while it writes holds, so new commits become searchable instead of waiting behind a pass that ends `drain_lease_held` (GBRA-133).** In a 600k-page synthetic soak at 65 ms round trips, a pass wrote a round's holds in one transaction that first locked the lease row. That transaction stayed open for 14 minutes. The lease's own renewal waited on the same row, timed out three times, and the lease lapsed under the pass, which then applied nothing. Its release waited on that row until the connection was killed. Those writes now commit in slices of at most 5 seconds, so a renewal waits for one slice at most. The same soak showed two smaller faults, fixed here: a pass told to stop (a 30-second first slice) kept reading its level for minutes, and a file whose history read did not finish was reported as one Git never committed.
+
+ ### What changed
+
+ | Situation | Before | Now |
+ |---|---|---|
+ | A pass writes many holds (or retires many deletion markers) under its drain lease | one transaction held the lease row locked for the whole batch, blocking the lease's renewal and release | the writes commit in slices of at most 5 s, each re-checking the lease; a lapsed lease stops them at the next slice |
+ | A pass's job deadline passes, or its lease lapses, while its level is read | the read and the Git history walk ran to the end before the pass looked | the read checks the pass at every pause and while the history walk runs, and stops there; the walk keeps running for the next pass to reuse |
+ | A file is missing and the read of its Git history did not finish | held with `meta.reason` `never_committed`, saying "Git never committed it" | held with `meta.reason` `origin_unknown`, saying Git could not show whether a commit held it; the page is still kept |
+
+ ### What to watch for after you upgrade
+
+ - Nothing runs on upgrade, and there's no migration. Holds written before this release keep their reason until a pass re-writes them.
+ - `gbrain repair file-drift --held --side deleted --state file_gone` still reads the whole history and names each file's provenance, whatever the hold's reason.
+
## [0.60.396.0] - 2026-10-23
**A fact you replace now stops being current at the moment its replacement starts, and facts imported from a dated page take the page's date instead of the day you imported it (#7214, #7247).** Before this release, telling the brain "my address changed" saved the new fact but left the old one open-ended, so a question about any date after the change could still get the old answer. Facts read from a page's facts table with no date of their own were dated the day sync or import ran, so a meeting note from last March imported today looked like it happened today.
diff --cc src/core/behavior-change-notice.ts
index 8c49952336,0c1e8a906c..6ce7c5b7dd
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@@ -1157,15 -1152,8 +1157,17 @@@ export const BEHAVIOR_CHANGES: Readonly
{ since: '0.60.395.0', text: 'A dream synthesis re-run of a transcript now retires the earlier outputs it replaced (GBRA-161 PR 4, #7065): after a complete re-synthesis (every chunk completed), an earlier reflection or original is versioned and soft-deleted (`retired_by: synthesis-resynthesis`, restorable for `generations.restore_days`, 30 by default) only when a new page is an exact duplicate of it, or has the same subject and covers every sentence, verbatim quote and citation it held. Every other earlier output stays live and `gbrain repair generations --kind synthesis --mode cleanup --since 30d` lists it with what it holds alone; its `--apply --expect <hash> --yes` retires exactly the previewed ones. A failed chunk or `gbrain config set generations.synthesis.retire_previous false` retires nothing, outputs written before this release are never retired, and `--mode restore` brings a retired output back. Separately, changing `models.dream.synthesize` no longer rewrites every deterministic (T3) concept page (#7269, reported by @p3ob7o).' },
{ since: '0.60.396.0', text: 'A fact that replaces another (`remember` with `replaces`, a near-duplicate supersession, or a published facts batch that supersedes) now also closes the retired fact\'s `valid_until` at the new fact\'s `valid_from`, in the database row and in its struck facts-fence row, so as-of reads no longer see the retired fact as current for the time between (#7214). A backdated replacement, starting on or before the retired fact, leaves the retired interval as it was.' },
{ since: '0.60.396.0', text: 'A facts-fence row with no `valid_from` cell now takes the page\'s stated date (frontmatter `event_date`, `date` or `published`, or a dated filename) on every write path: `put_page`, sync and import used to store the write time, and `extract_facts` used the page\'s creation or import time when the page stated no date (#7247). A page that states no date leaves such rows at the time they were recorded. Rows already stored keep their dates.' },
+ // GBRA-133 (soak: an unread origin was reported as never committed). `since` is restamped at the merge slot.
+ { since: '0.60.397.0', text: 'A `file_drift` hold (side `deleted`, state `file_gone`) for a missing file whose Git history read did not finish now carries `meta.reason` `origin_unknown` and says Git could not show whether a commit held the file, instead of `never_committed` and "Git never committed it". The page is still kept, and the `--held` preview still reads the whole history and names the provenance.' },
+ // GBRA-60 small-items wave (#7026 part 2, #7234). `since` is stamped at the merge slot.
+ { since: 'TBD', text: 'New opt-in `context.hot_memory.session_only`, off by default (#7026): with `gbrain config set context.hot_memory.session_only true`, the hot facts the turn hook and the session-start pack inject come from the current session only, so a session with no facts of its own gets none instead of the source\'s newest facts from the last 24 hours, which can belong to other sessions. MCP `_meta.brain_hot_memory` is unchanged.' },
+ { since: 'TBD', text: 'When the chronicle phase refuses a judge answer as `malformed_proposal`, it now prints one warning line naming the check that failed (a fixed code such as `when_unparseable`, the field, the JSON type found there and counts, never a value), and the direct extractor result carries the same fields under `malformed` (#7234). The refusal, its retry with backoff and the ledger row are unchanged.' },
+ // #7023 (GBRA-60). `since` is restamped at the merge slot.
+ { since: 'TBD', text: 'The per-prompt context block now renders each hot-memory fact the same way the session-start pack does: a fact the assistant said keeps its `(assistant said)` prefix instead of reading as your own claim, and a fact injected once in a session is not injected again on later prompts, whatever its trust label or speaker. Before, assistant-attributed and external (`<external-data>`) facts came back on every prompt; a session already open when you upgrade sees each assistant fact once more (#7023, reported by @benswinney).' },
+ // #7026 (GBRA-60). `since` is restamped at the merge slot.
+ { since: 'TBD', text: 'In Claude Code, the first prompt of a session no longer repeats the hot-memory facts the session-start block already showed: the user-prompt hook now reads the `gbrain hook session-start` output Claude Code records as a SessionStart `hook_success` entry, from the gbrain context envelope on, so core memory printed before it does not hide page pointers. SessionStart output from other tools is still ignored (#7026, reported by @benswinney).' },
+ // #7270 (GBRA-60). `since` is restamped at the merge slot.
+ { since: 'TBD', text: '`gbrain facts relink` and `gbrain facts relink --conversation` no longer attach a fact the assistant or a named third party said (`attributed_to` assistant or other) to an entity page, core pages included: such a fact is left where it was saved, recall still finds it, and the run counts it as `not_user_attributed`. Before, the SessionEnd corpus sweep saved the assistant\'s own report about a page, and every relink pinned it onto that page. Doctor `unlinked_facts` no longer counts these facts. Rows linked before this release stay linked; `gbrain forget <fact-id>` removes one (#7270, reported by @andrew-agents-bot).' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */