Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test+docs: N5-2/N5-3 Postgres lane wiring and lane C notes
garrytane9c6ad825eb7
diff --git a/docs/fix-wave-notes/capy-evalwave-fixes-c.md b/docs/fix-wave-notes/capy-evalwave-fixes-c.mdindex 25bac335fd..932ef1584f 100644--- a/docs/fix-wave-notes/capy-evalwave-fixes-c.md+++ b/docs/fix-wave-notes/capy-evalwave-fixes-c.md@@ -100,6 +100,59 @@ one provenance collided with the first Lisbon row and Porto stayed current.fresh write, the race), PGLite and Postgres via`test/e2e/hot-memory-invalidation-postgres.test.ts`.+## N5-3 — first remember after a forget refused as stale bytes (PGLite CLI)++The forget commits, queues its `withdrawal-mirror` effect and exits; a CLI+process has no resident consumer. The next process (the remember) starts a+consumer whose effect worker and request worker run in the same tick+(`consumer.ts` `doTick`). The mirror rewrites the page file after the remember+captured `expectedBeforeHash` and before it publishes, at an unchanged page+revision, so publication refused with `source_changed` → `raw_file_changed`.+Postgres and the servers hid it by timing.++- `CLAIMABLE_WRITE_SQL` (`journal.ts`): a file write is not claimed while a+ queued or running withdrawal mirror targets its page (an untargeted legacy+ mirror blocks its whole worktree). Writes to other pages are unaffected.+- `publishMutation` (`coordinator.ts`): changed bytes **and** a moved page+ revision (a forget committed while the write was preparing) throw+ `revision_conflict`, so semantic writes reprepare; changed bytes at an+ unchanged revision still refuse as `raw_file_changed`.+- Tests: `test/withdrawal-followup-writes.test.ts` (PGLite and Postgres via+ `test/e2e/withdrawal-followup-writes-postgres.test.ts`).++## N5-2 — forget under concurrent CLI writes on PGLite++Two independent causes. The ledger said the `owner_unavailable` forgets had+committed; they had not (refused before sending, fact still active).++- **Missing chunks.** `recordFactWithdrawal` deletes the withdrawn pages'+ chunks in the commit and leaves the rebuild to the resident projection+ worker, which a CLI forget never runs. It reproduced without concurrency+ (forget, then search). `submitForgetMutation` now rebuilds those pages'+ text projections after the commit and before answering+ (`rebuildPendingPageProjections` gained a `pages` filter). A failed rebuild+ stays queued as durable projection work and does not turn a committed+ forget into an error.+- **`owner_unavailable`.** `maybeDelegateLocalOperation` treated any PGLite+ lock holder as a resident owner; when the holder was another CLI call+ there was no owner socket, so concurrent CLI writes (forgets and remembers)+ got `owner_unavailable` with `submission_status: not_sent`. A holder that+ is not a serve and answers no owner socket now falls through to the engine+ path, which already waits up to 30 s for the lock. A serve holder, or a+ socket that answered, still makes every failure final.+ `maybeDelegateLocalAdministration` is unchanged.+- Behavior change to call out: concurrent CLI calls on one PGLite brain now+ take turns on the lock instead of failing fast; behind a long-running+ non-serve holder (e.g. a jobs daemon) a CLI write waits and then fails+ lock-busy rather than answering `owner_unavailable` immediately.+- `test/persistence-memory-mutations.test.ts` "forget commits offline" used+ to assert the chunks were empty after a forget (the N5-2 behavior); it now+ asserts the chunks keep the retained text and drop the withdrawn claim.+- Tests: `test/withdrawal-followup-writes.test.ts` (retained fact in chunks+ and keyword search after an acknowledged forget),+ `test/persistence-local-client.test.ts` (non-serve holder falls through;+ serve holder without a socket still throws).+## Repros (gbrain-evals `capy/wave-n1-n5`, run against this checkout)| Repro | Before (a551d84b) | After |@@ -108,3 +161,5 @@ one provenance collided with the first Lisbon row and Porto stayed current.| N1-2 | third write `noop`; current Porto | third write `superseded_prior`; current Lisbon || N1-3 | remote sees `decision_style=deliberate, risk_tolerance=high (private marker)` | remote sees `decision_style=deliberate` || N5-1 | `context_pack` and `get_page` `_meta` right after forget carry the fact | both `false` |+| N5-2 | rounds lose chunks after `forget ok` (search false) or answer `owner_unavailable` (2/5 each) | 10/10 rounds over two runs: forget ok, retained neighbor in recall and search |+| N5-3 | first remember `scope_denied: The source file bytes changed after this request was accepted.`; retry ok | first remember ok |diff --git a/scripts/e2e-test-map.ts b/scripts/e2e-test-map.tsindex 58c8185db6..03a522672d 100644--- a/scripts/e2e-test-map.ts+++ b/scripts/e2e-test-map.ts@@ -38,7 +38,7 @@ export const E2E_TEST_MAP: Record<string, string[]> = {// Fix wave 5 #5401: projection drain CLI and the budgeted resident drain."src/commands/projections.ts": ["test/e2e/projection-drain-postgres.test.ts", "test/e2e/fix-wave-5-integration.test.ts"],"src/core/persistence/consumer.ts": ["test/e2e/projection-drain-postgres.test.ts"],- "src/core/persistence/journal.ts": ["test/e2e/projection-drain-postgres.test.ts"],+ "src/core/persistence/journal.ts": ["test/e2e/projection-drain-postgres.test.ts", "test/e2e/withdrawal-followup-writes-postgres.test.ts"],// Fix wave 5 (#5731): the extractor-facts restore and its doctor check."src/core/repair/extractor-facts.ts": ["test/e2e/repair-extractor-facts-postgres.test.ts", "test/e2e/fix-wave-5-integration.test.ts"],"src/commands/doctor/checks/extractor-facts.ts": ["test/e2e/repair-extractor-facts-postgres.test.ts"],@@ -429,6 +429,8 @@ export const E2E_TEST_MAP: Record<string, string[]> = {// ontology observations) and the per-stint ontology dedup key."src/core/persistence/database-write.ts": ["test/e2e/managed-ontology-propose-postgres.test.ts", "test/e2e/managed-writers-w3.test.ts"],"src/core/schema-migrations/v189-facts-ontology-stint-dedup.ts": ["test/e2e/ontology-merge-parity.test.ts", "test/e2e/schema-drift.test.ts"],+ "src/core/persistence/memory-mutations.ts": ["test/e2e/withdrawal-followup-writes-postgres.test.ts"],+ "src/core/persistence/coordinator.ts": ["test/e2e/withdrawal-followup-writes-postgres.test.ts"],"src/core/facts/meta-hook.ts": ["test/e2e/hot-memory-invalidation-postgres.test.ts", "test/e2e/facts-context-injection-postgres.test.ts", "test/e2e/serve-http-meta.test.ts"],"src/mcp/dispatch.ts": ["test/e2e/hot-memory-invalidation-postgres.test.ts"],// Schema source of truth: any change must pass the cross-engine drift gate.diff --git a/test/e2e/withdrawal-followup-writes-postgres.test.ts b/test/e2e/withdrawal-followup-writes-postgres.test.tsnew file mode 100644index 0000000000..1b8ffacf40--- /dev/null+++ b/test/e2e/withdrawal-followup-writes-postgres.test.ts@@ -0,0 +1,3 @@+import { registerPostgresTests } from '../helpers/test-backends.ts';++await registerPostgresTests(() => import('../withdrawal-followup-writes.test.ts'));diff --git a/test/withdrawal-followup-writes.test.ts b/test/withdrawal-followup-writes.test.tsindex e6bb4c1b7b..f08877765b 100644--- a/test/withdrawal-followup-writes.test.ts+++ b/test/withdrawal-followup-writes.test.ts@@ -27,6 +27,7 @@ import { runPersistenceEffects } from '../src/core/persistence/effects.ts';import { prepareMemoryMutation, submitForgetMutation, submitRememberMutation } from '../src/core/persistence/memory-mutations.ts';import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';+import { testBackends } from './helpers/test-backends.ts';const engines: BrainEngine[] = [];const roots: string[] = [];@@ -36,16 +37,18 @@ const context = (engine: BrainEngine, sourceId: string): OperationContext => ({config: { engine: engine.kind, embedding_disabled: true }, logger: { info() {}, warn() {}, error() {} } });beforeAll(async () => {- const lite = new PGLiteEngine(); await lite.connect({}); await lite.initSchema(); engines.push(lite);- if (process.env.DATABASE_URL) {- const pg = await isolatedPersistencePostgres(process.env.DATABASE_URL);+ const backends = testBackends();+ if (backends.includes('pglite')) { const lite = new PGLiteEngine(); await lite.connect({}); await lite.initSchema(); engines.push(lite); }+ if (backends.includes('postgres')) {+ const pg = await isolatedPersistencePostgres(process.env.DATABASE_URL!);engines.push(pg.engine); closePostgres = pg.close;}for (const engine of engines) await registerLocalWriter(engine, 'cli');}, 120_000);afterAll(async () => {for (const engine of engines) await disposePersistenceConsumer(engine);- await engines[0]?.disconnect(); await closePostgres?.();+ for (const engine of engines) if (engine instanceof PGLiteEngine) await engine.disconnect();+ await closePostgres?.();for (const root of roots) rmSync(root, { recursive: true, force: true });});