Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(repair): repair visibility stamps unstamped concepts that have no lineage

garrytand0f0250ac267
diff --git a/docs/guides/repair.md b/docs/guides/repair.md
index 5184f4732f..3d914b6a84 100644
--- a/docs/guides/repair.md
+++ b/docs/guides/repair.md
@@ -144,7 +144,7 @@ work behind exits 0, so scripts should also check `results[].complete`.
| Kind | Doctor check that points here | What it does | Left alone and counted |
| --- | --- | --- | --- |
| `timeline` | `timeline_history` | Re-saves each page with its current body through a revision-bound `put_page`. The save writes each database-only timeline entry back into the page as a bullet preceded by `<!-- gbrain:materialized v1 <hash> -->`. | `kept_unrenderable_rows`: entries that would change if written as a bullet (for example an empty source). They stay in the database. |
-| `visibility` | `derived_visibility` | Stamps an explicit `visibility` on extracted atoms and synthesized concepts. An atom takes its origin page's visibility; transcript atoms and atoms whose origin is gone become `private`; a concept takes the strictest visibility of its input atoms. A concept input found only through an atom's `concepts:` list counts as private. Atoms are repaired before concepts. It never loosens an explicit value: `private` stays `private`, and `world` can only become `private`. A missing value is stamped with the origin's value, which is `world` when the origin page is public. | `concepts_without_lineage`: concepts whose inputs cannot be found. They stay as they are, and remote readers already treat a missing visibility as private. `atoms_origin_gone_to_private` counts atoms made private because their origin page no longer exists. |
+| `visibility` | `derived_visibility` | Stamps an explicit `visibility` on extracted atoms and synthesized concepts. An atom takes its origin page's visibility; transcript atoms and atoms whose origin is gone become `private`; a concept takes the strictest visibility of its input atoms. A concept input found only through an atom's `concepts:` list counts as private. Atoms are repaired before concepts. It never loosens an explicit value: `private` stays `private`, and `world` can only become `private`. A missing value is stamped with the origin's value, which is `world` when the origin page is public. | `concepts_without_lineage`: concepts whose inputs cannot be found. One with no visibility is stamped `private` (what remote readers already treat it as), so the doctor warning clears; an explicit value stays as it is. `atoms_origin_gone_to_private` counts atoms made private because their origin page no longer exists. |
| `request-indexes` | `persistence_request_indexes` | Creates a missing request-table index (the managed sync checkpoint pair, the purge slug index, the dream postprocess request-id index, the write claims' foreground-commit index, the failed-writes replay and page-sequence indexes), or drops an INVALID one (left by an interrupted concurrent build) and rebuilds it, on a brain whose schema version is already current. Postgres builds each index `CONCURRENTLY`, one at a time, so writes continue; PGLite builds inline. It changes no user data, takes no journal admission and runs brain-wide (`--source` does not narrow it). See [managed sync request indexes](#request-indexes). | `building`: an index another session is still building; it is never dropped. |
| `connector-fences` | none (a `connector_fence_below_timeline` refusal names it) | Moves a facts or takes fence that sits below the timeline sentinel of a Google or GitHub page into the page body through a revision-bound `put_page`, so the connector's next re-render carries the fence instead of refusing. Then re-attempt the held item with `gbrain sources retry-held <source>`. | `kept_ambiguous_pages`: pages whose fences are duplicated, unbalanced or unparseable. Move the fence by hand: read the page, place the fence above the `<!-- timeline -->` line, and save it with the current `expected_revision`. |
| `take-supersession` | none | Rebuilds `takes.superseded_by` for supersession chains written before the pointer moved onto the old fence row (#5886). Each struck take is linked to the row that replaced it only from evidence: a committed `takes_supersede` receipt, a stored `superseded_by`, or a row carrying the old `superseded by #<own row>` pointer with exactly one possible predecessor. The pointer is written onto the old row (`<source>; superseded by #N`) and stale self-pointers are dropped through a revision-bound `put_page`; a page whose fence is already right but whose stored pointers differ is reprojected without a page write. See [take supersession](#take-supersession). | `ambiguous_pages` / `ambiguous_rows`: pages where a new row has two or more possible predecessors, or where evidence conflicts. The preview lists each with its candidates and the manual edit; nothing on them changes. `unparsed_pages`: pages whose takes fence does not parse cleanly. |
diff --git a/src/core/repair/visibility.ts b/src/core/repair/visibility.ts
index df0cab3db4..d980c81358 100644
--- a/src/core/repair/visibility.ts
+++ b/src/core/repair/visibility.ts
@@ -17,7 +17,7 @@
* An item is only ever made stricter than it is now: explicit `private` stays,
* explicit `world` becomes `private` when its origin is stricter, and a missing
* field (read as private) is stamped with the origin's value. A concept with no
- * recoverable lineage is left unchanged and counted. Atoms are applied before
+ * recoverable lineage is counted; a missing value on it is stamped private and an explicit one is left unchanged. Atoms are applied before
* concepts so a concept is judged against its repaired inputs.
*
* The preview plans one class at a time (`--class facts|events|aliases|lineage`, default all), in the
@@ -120,9 +120,10 @@ async function planLineage(engine: BrainEngine, sourceIds: string[], only?: { id
let noLineage = 0;
for (const concept of concepts) {
const rows = inputsByConcept.get(Number(concept.id)) ?? [];
- if (!rows.length) { noLineage++; continue; }
+ if (!rows.length) noLineage++;
+ if (!rows.length && concept.visibility === 'world') continue;
const members = rows.map(row => row.linked ? atomVisibility.get(Number(row.atom_id)) ?? 'private' : 'private');
- const next = tightened(concept.visibility, strictestVisibility(members));
+ const next = tightened(concept.visibility, rows.length ? strictestVisibility(members) : 'private');
if (next) changes.push({ id: Number(concept.id), source_id: concept.source_id, slug: concept.slug, phase: 1, from: concept.visibility, to: next });
}
return { changes, rows: [...atoms, ...concepts], residuals: { atoms_origin_gone_to_private: originGone, concepts_without_lineage: noLineage } };
diff --git a/test/derived-visibility-repair.test.ts b/test/derived-visibility-repair.test.ts
index d94d8c6a1f..f0112a5527 100644
--- a/test/derived-visibility-repair.test.ts
+++ b/test/derived-visibility-repair.test.ts
@@ -296,4 +296,26 @@ describe('#5525 tighten-only visibility backfill', () => {
expect((await derivedVisibilityCheck(engine)).status).toBe('ok');
}
}, 120_000);
+
+ test('an unstamped synthesized concept with no recoverable lineage is stamped private, so the doctor warning clears (#8848)', async () => {
+ for (const engine of engines) {
+ await reset(engine);
+ await seed(engine, 'concepts/unstamped-orphan', 'concept', { synthesized_by: 'synthesize_concepts-v0.41' });
+ await seed(engine, 'concepts/world-orphan', 'concept', { synthesized_by: 'synthesize_concepts-v0.41', visibility: 'world' });
+ expect(await remoteSees(engine, 'concepts/unstamped-orphan')).toBe(false);
+ expect(await derivedVisibilityCheck(engine)).toMatchObject({ status: 'warn', details: { unstamped_concepts: 1 } });
+ await withEnv({ GBRAIN_HOME: home }, async () => {
+ const scope = await resolveRepairScope(engine);
+ const preview = await runRepair(ctx(engine, false), visibilityRepair, scope, { apply: false });
+ expect(preview.affected).toBe(1);
+ expect(preview.residuals).toMatchObject({ concepts_without_lineage: 2 });
+ expect(await runRepair(ctx(engine, false), visibilityRepair, scope, { apply: true })).toMatchObject({ applied: 1, complete: true });
+ expect(await runRepair(ctx(engine, false), visibilityRepair, scope, { apply: true })).toMatchObject({ affected: 0, applied: 0, complete: true });
+ });
+ expect(await visibilityOf(engine, 'concepts/unstamped-orphan')).toBe('private');
+ expect(await visibilityOf(engine, 'concepts/world-orphan')).toBe('world');
+ expect(await remoteSees(engine, 'concepts/unstamped-orphan')).toBe(false);
+ expect((await derivedVisibilityCheck(engine)).status).toBe('ok');
+ }
+ }, 120_000);
});