Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(persistence-robot): a fact write never asserts liveness of a page whose put is pending

garrytanb8ae30228b52
diff --git a/scripts/persistence/model.ts b/scripts/persistence/model.ts
index cf88cc2d3e..db196ebf9b 100644
--- a/scripts/persistence/model.ts
+++ b/scripts/persistence/model.ts
@@ -396,11 +396,11 @@ const pageWrite = (kind: 'put' | 'edit'): Fold => async (m, d, o) => {
}
else if (page.lastMarker && !markersIn(String(read.content)).includes(page.lastMarker)) m.violate({ class: 'untrue_receipt', op: d.id, detail: `committed ${d.kind} marker ${page.lastMarker} not visible` });
};
+/** A write that moves a page's revision. A page the model has not seen committed (its put may still be pending) stays untracked. */
const touch = (slugOf: (d: OpDescriptor) => string): Fold => async (m, d, o) => {
const k = key(d.source, slugOf(d)); m.touched.add(k);
- const page = m.page(d.source, slugOf(d));
- if (o.values.revision) page.revision = o.values.revision;
- else page.revision = null;
+ const page = m.pages.get(k);
+ if (page) page.revision = o.values.revision ?? null;
};
/** A file edit picked up by sync, or a connector item: the page now carries its marker. */
@@ -437,7 +437,8 @@ export const MODEL: Record<OpKind, Fold> = {
if (fact) {
if (fact.source !== d.source) m.violate({ class: 'source_isolation', op: d.id, detail: `forget in ${d.source} expired fact ${id} of ${fact.source}` });
fact.withdrawn = true; m.reasserted.delete(`${fact.source}\u0000${fact.text}`);
- m.touched.add(key(fact.source, fact.entity)); m.page(fact.source, fact.entity).revision = null;
+ const k = key(fact.source, fact.entity); m.touched.add(k);
+ const page = m.pages.get(k); if (page) page.revision = null;
}
},
takes_add: touch(d => String(d.args.slug)),
diff --git a/test/persistence-crash-robot.test.ts b/test/persistence-crash-robot.test.ts
index 473308a38e..af9d6c2b68 100644
--- a/test/persistence-crash-robot.test.ts
+++ b/test/persistence-crash-robot.test.ts
@@ -170,6 +170,33 @@ describe('injected session drops', () => {
});
}, 120_000);
+ // Local replay of the pooler_disconnect fault (Bun 1.4.2, seed 5105): drops kept a put pending past its caller's
+ // wait, so the model never folded it; the next remember on that page created a model entry saying "not live"
+ // and the drained page then read as an untrue receipt.
+ test('a fact write on a page whose put is still pending claims nothing about that page', async () => {
+ await robotBrain(async ({ world }) => {
+ const source = world.remotes[0].sourceId;
+ const model = new ReferenceModel(world);
+ const put = descriptor('pending-put', 'put_page', 'local', source, { slug: 'notes/alpha', content: pageBody('notes/alpha', 'mk-pending0') });
+ const fact = descriptor('fact', 'remember', 'local', source, { fact: 'Alpha fact mk-fact0', entity: 'notes/alpha' });
+ const forget = descriptor('forget', 'forget', 'local', source, { fact_id: { $ref: fact.id, field: 'fact_id' } });
+ world.descriptors = new Map([put, fact, forget].map(d => [d.id, d]));
+ const committed = await executeOp(world, put);
+ expect(committed.status).toBe('committed');
+ model.beginStep(false);
+ await model.observe(put, { ...committed, status: 'pending', values: {} });
+ await model.checkGlobal('after the pending put');
+ for (const d of [fact, forget]) {
+ const seen = await executeOp(world, d);
+ expect(seen.status).toBe('committed');
+ model.beginStep(false);
+ await model.observe(d, seen);
+ await model.checkGlobal(`after ${d.id}`);
+ }
+ expect(model.violations).toEqual([]);
+ });
+ }, 120_000);
+
test('a drop round counts once it terminated a session, including a round still in flight', async () => {
const drops = new SessionDrops();
expect(await drops.injectedBefore()).toBe(false);