Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(facts): register the conversation relink writer with the core-guard and attribution censuses (#6764)

garrytan5aa8709abeb8
diff --git a/docs/.wave18-fragments/lane3.md b/docs/.wave18-fragments/lane3.md
index 0c8f65cb3c..c92b271ff9 100644
--- a/docs/.wave18-fragments/lane3.md
+++ b/docs/.wave18-fragments/lane3.md
@@ -114,3 +114,9 @@ Lane 3 branch: capy/wave18-lane3. Each section names the target file, the place
- New maintenance intent kind `managed_maintenance_conversation_relink`, dispatched in `src/core/persistence/prepared-maintenance.ts` (one line, not a listed registry). New canonical-writer census row for `src/core/facts/conversation-relink.ts` in `docs/architecture/canonical-writers.tsv` (ceiling 1, boundary coordinator).
- Module sizes: `src/commands/facts.ts` 201 lines, `src/core/facts/conversation-relink.ts` 187 (new), `src/core/persistence/prepared-maintenance.ts` 590; none is listed in the TSV and all are under the new-file cap. No TSV change.
- Dropping this commit (d1a) restores the commit before it exactly: doctor prescribes the paid re-extraction for every unlinked conversation row. The commit also edits that commit's own tests (seeding a `conversation_unresolved` memo so they still exercise the paid envelope).
+
+## Gate follow-ups (all items)
+
+- `src/core/cli-flag-registry.generated.ts`: regenerated with `bun run build:flag-registry` in the separate final commit "INTEGRATOR-ROW: regenerate cli-flag-registry for lane 3" (tests docs-cli-commands, remediation-command-resolution, cli-flag-validation and conversation-facts-type-allowlist-drift need it). Additive only: facts +`--conversation --force --slugs --source-id`, doctor +`--conversation --entity --retry-model`, lint +`--max-cost-usd --slugs`, maintain and sync +`--conversation`. Drop it and rerun the generator after the lanes merge.
+- New exemption in `scripts/check-core-guard-coverage.mjs` (conversation-relink.ts: database-only fact rows, page text unchanged) and a write-attribution row in `docs/architecture/system-of-record.md`.
+- gstack pregate `literals` reports ~643 test locations "still carrying" MENTION_EXTRACTOR_VERSION 5. Every hit except test/mentions-pass.test.ts (fixed to use the symbol) is an unrelated literal 5 (array indexes, model names, counts); no test pins the mention version as a number. The `lanes` check flags this fragment file, which the integrator deletes.
diff --git a/docs/architecture/system-of-record.md b/docs/architecture/system-of-record.md
index 856076ef95..f30c1e1290 100644
--- a/docs/architecture/system-of-record.md
+++ b/docs/architecture/system-of-record.md
@@ -247,6 +247,7 @@ or a physical projection that leaves attribution untouched):
- `src/core/extract/receipt-writer.ts` (1): the extraction receipt page runs in `maintenanceTransaction`.
- `src/core/facts/backstop.ts` (1): the facts backstop's DB-only fallbacks insert each fact through one helper, in `maintenanceTransaction` at the extraction's derived tier; managed brains publish through the facts request preparer.
- `src/core/facts/conversation-publication.ts` (3): the managed conversation-facts preparer clears each member page's prior rows and inserts its frozen entry (or a blocked outcome row) inside the coordinator publication of its admitted batch request; the unmanaged cleanup runs the same clear in `maintenanceTransaction`.
+- `src/core/facts/conversation-relink.ts` (1): `gbrain facts relink --conversation`: a `managed_maintenance_conversation_relink` request on managed brains; the unmanaged relink runs in `writeDerivedFacts` (`maintenanceTransaction`).
- `src/core/facts/derivation-inputs.ts` (3): `hideDerivedRows` expires derived facts, deactivates derived takes and soft-deletes derived pages inside the purge's coordinated transaction, attributed to the purge request.
- `src/core/facts/fence-write.ts` (2): the markdown-first fence reconcile insert and its page body mirror each run in `maintenanceTransaction`.
- `src/core/facts/forget.ts` (4): the legacy fence expiry, withdrawal and strike-through each run in `maintenanceTransaction` (nested inside a caller's coordinated write, they keep its actor).
diff --git a/scripts/check-core-guard-coverage.mjs b/scripts/check-core-guard-coverage.mjs
index f640bc5466..20c3a9c162 100644
--- a/scripts/check-core-guard-coverage.mjs
+++ b/scripts/check-core-guard-coverage.mjs
@@ -44,6 +44,7 @@ const EXEMPT = {
'src/commands/extract-timeline-db.ts': 'writes timeline rows; timeline never enters core',
'src/core/extract-timeline-from-meetings.ts': 'writes meeting timeline rows on entity pages; page text is unchanged',
'src/core/facts/conversation-publication.ts': 'writes database-only conversation fact rows; page text is unchanged',
+ 'src/core/facts/conversation-relink.ts': 'sets entity_slug on database-only conversation fact rows; page text is unchanged',
'src/core/cycle/extract-facts.ts': 'fence reconcile and deleted-page expiry write fact rows only; page text is unchanged',
'src/core/cycle/extract-takes.ts': 'takes reextract writes take rows only; page text is unchanged',
'src/core/repair/take-supersession.ts': 'reprojection writes takes.superseded_by only; fence edits go through put_page (preparePageMutation)',
diff --git a/src/commands/doctor/checks/unlinked-facts.ts b/src/commands/doctor/checks/unlinked-facts.ts
index 6ef600ea92..c73ccbf37f 100644
--- a/src/commands/doctor/checks/unlinked-facts.ts
+++ b/src/commands/doctor/checks/unlinked-facts.ts
@@ -27,7 +27,7 @@ import { AUDIT_ROW_SOURCES } from '../../../core/facts/audit-sources.ts';
import type { Check } from '../../doctor.ts';
import type { Action } from '../../../core/agent-output.ts';
import { doctorVerify } from '../check-fix.ts';
-import { CONVERSATION_UNRESOLVED } from '../../../core/facts/conversation-relink.ts';
+import { CONVERSATION_UNRESOLVED } from '../../../core/facts/relink-reasons.ts';
import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';
export const UNLINKED_NEW_SHARE_WARN = 0.25;
diff --git a/src/core/facts/conversation-relink.ts b/src/core/facts/conversation-relink.ts
index 557e1bedf3..8a5a35b7e3 100644
--- a/src/core/facts/conversation-relink.ts
+++ b/src/core/facts/conversation-relink.ts
@@ -35,14 +35,13 @@ import { waitForWrite, writeResponse } from '../persistence/service.ts';
import { maintenancePreflight, submitDatabaseMaintenanceIntent } from '../persistence/prepared-maintenance.ts';
import { writeDerivedFacts } from '../persistence/derived-facts.ts';
import { AUDIT_ROW_SOURCES } from './audit-sources.ts';
+import { CONVERSATION_UNRESOLVED } from './relink-reasons.ts';
import { appendContextNote } from './subject-infer.ts';
import { inferConversationSubject } from './conversation-subject-infer.ts';
export const CONVERSATION_RELINK_INTENT = 'managed_maintenance_conversation_relink';
/** The request slug: a dot-led segment no page can hold; the page's own key is locked with it. */
export const CONVERSATION_RELINK_ANCHOR = '.maintenance/conversation-relink';
-/** The `fact_relink_attempts` outcome of a derived row this relink could not resolve. */
-export const CONVERSATION_UNRESOLVED = 'conversation_unresolved';
/** Pages one run relinks when no `--slugs` are named. */
export const CONVERSATION_RELINK_PAGES = 50;
/** The SQL predicate (on alias `f`, audit sources as `$audit`) of a conversation extractor's derived fact row. */
diff --git a/src/core/facts/relink-reasons.ts b/src/core/facts/relink-reasons.ts
index 022e75645f..8d13f544ad 100644
--- a/src/core/facts/relink-reasons.ts
+++ b/src/core/facts/relink-reasons.ts
@@ -23,5 +23,8 @@ export const RELINK_REASONS = {
revision_conflict: { memoized: false, fix: 'The fact or the entity page changed while relink ran. Rerun.' },
} as const satisfies Record<string, { memoized: boolean; fix: string }>;
+/** #6764: the `fact_relink_attempts` outcome `gbrain facts relink --conversation` records for a derived row it could not resolve. */
+export const CONVERSATION_UNRESOLVED = 'conversation_unresolved';
+
export type RelinkReason = keyof typeof RELINK_REASONS;
export const RELINK_REASON_CODES = Object.keys(RELINK_REASONS) as RelinkReason[];