Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

P2.7 (#5970): timeline ops name the page-edit correction route; the receipt returns the bullet

garrytan4f857682fd0b
diff --git a/docs/TOOL_CATALOG.md b/docs/TOOL_CATALOG.md
index 36d36b4a3d..c069e31b12 100644
--- a/docs/TOOL_CATALOG.md
+++ b/docs/TOOL_CATALOG.md
@@ -278,5 +278,5 @@ Every non-localOnly operation on the MCP surface: 149 tools across 25 areas. **S
| Tool | Description | Scope | Starter | Gate |
|---|---|---|---|---|
| `add_timeline_entry` | Append a dated entry to a page timeline. | write | yes | |
-| `get_timeline` | Get timeline entries for a page, optionally filtered by date window | read | | |
+| `get_timeline` | Get timeline entries for a page, optionally filtered by date window. | read | | |
diff --git a/docs/architecture/key-files/core-persistence.md b/docs/architecture/key-files/core-persistence.md
index 0d1c9a9ea7..a254308058 100644
--- a/docs/architecture/key-files/core-persistence.md
+++ b/docs/architecture/key-files/core-persistence.md
@@ -53,6 +53,6 @@ Connector ingestion, item holds, checkpoint validation and the single-write fast
- `src/core/persistence/unbound-source.ts` — #5254 policy for a Postgres page write to a filesystem source (`local_path`, or `sync.repo_path` for `default`) with default write-through and no worktree binding. `submitPageMutation` refuses `owner_unavailable` with `detail: unbound_source`, a `docs` pointer to `write-refusals.md#unbound-sources-on-postgres`, and a hint naming the filled `sources writer status`/`writer claim ... --admin-intent writer_claim --expected-state <admin_state>` bind command (host path only for trusted local callers) and, for `put_page` to a page without `source_path`, `gbrain config set persistence.unbound_write database_only`. That key (`refuse` default, validated by `config set`; any other stored value refuses) lets such a `put_page` admit with `databaseOnlyReason: 'unbound_source'`. On a classic brain (managed persistence not activated) the hint leads with the classic write path: write `<checkout>/<slug>.md`, commit it, `gbrain sync --source <id>` (a remote caller is told to ask the user to). The refusal is `retryable: false` with a `fix` of `next: ask_user` and a `user_message` (classic or managed wording), because every way out is the user's choice (`test/unbound-source-hint.test.ts`). Publication rechecks inside its transaction, after `authorizeStoredRequest` share-locks the source row, that the source is still unbound and the page still has no `source_path` (else `owner_unavailable`/`unbound_source`, hint rebuilt from the persisted message by `writeResponse`), then stamps `pages.database_only_reason='unbound_source'` (migration 177). After binding, `prepareFileTarget` keeps a stamped page with no file database-only (receipt `write_through.skipped: unbound_source` with a warning) and managed sync refuses to import a file at its path (`source_changed`, diagnostic reason `unbound_source`). PGLite keeps auto-claiming. Tests: `test/e2e/unbound-source-postgres.test.ts`, `test/persistence-unbound-source.test.ts`. See [persistence stalls](persistence-stalls.md).
-- `src/core/persistence/{semantic,semantic-pages}.ts` — revision-bound semantic tag/timeline merges through the journal. Supported merges reprepare against a newer snapshot (`mayReprepare`: `revision_conflict` or, #5385 [R13], `revision_required`, both only when the caller named no `expected_revision`); exact timeline replay leaves canonical bytes, revision, versions and structured rows unchanged. #5251: `add_tag` / `remove_tag` prepare with `deferEmbedding: true` (a tag change leaves every chunk's text as it was, so no `embedding` effect is queued and `embedding_state` reads `deferred`; the stale sweep still covers any chunk the republication left without a vector); the full page republication they ride stays, so the issue stays open. The public timeline handler resolves durable replay before page-existence preflight, retaining original outcomes after page purge or recreation; fresh writes preserve same-source diagnostics. `page-state/projections.ts` completes sanitized text and page search vectors together, and installs delayed embeddings with UPDATE-only revision/chunk/text/index-context checks. New vectors receive the full provider:model captured before provider execution, and a runtime model switch invalidates the prepared indexing context. Metadata updates preserve the sanitized vector. Tests: `persistence-semantic-pages.test.ts`, `page-projection-concurrency.test.ts`.
+- `src/core/persistence/{semantic,semantic-pages}.ts` — revision-bound semantic tag/timeline merges through the journal. Supported merges reprepare against a newer snapshot (`mayReprepare`: `revision_conflict` or, #5385 [R13], `revision_required`, both only when the caller named no `expected_revision`); exact timeline replay leaves canonical bytes, revision, versions and structured rows unchanged. The `add_timeline_entry` receipt carries `bullet`, the rendered Markdown line (#5970): there is no update/remove verb because the page is the system of record, so the caller corrects an entry by editing that line with `edit_page` and the row follows the page (both timeline op descriptions say so; `test/timeline-correction-path-5970.test.ts`). #5251: `add_tag` / `remove_tag` prepare with `deferEmbedding: true` (a tag change leaves every chunk's text as it was, so no `embedding` effect is queued and `embedding_state` reads `deferred`; the stale sweep still covers any chunk the republication left without a vector); the full page republication they ride stays, so the issue stays open. The public timeline handler resolves durable replay before page-existence preflight, retaining original outcomes after page purge or recreation; fresh writes preserve same-source diagnostics. `page-state/projections.ts` completes sanitized text and page search vectors together, and installs delayed embeddings with UPDATE-only revision/chunk/text/index-context checks. New vectors receive the full provider:model captured before provider execution, and a runtime model switch invalidates the prepared indexing context. Metadata updates preserve the sanitized vector. Tests: `persistence-semantic-pages.test.ts`, `page-projection-concurrency.test.ts`.
- `src/core/persistence/{source-lifecycle,managed-sources,topology-schema,topology-locks,topology-receipts,topology-clone,topology-clone-model,topology-filesystem,topology-recovery}.ts` — migration 157 coordinates source add/claim/archive/restore/remove/purge/rebind/reclone. Native root locks precede topology/source/grant/counter/request guards; `withTopologyLocks(..., { relocation: true })` (rebind only, #5914 P1.3c) verifies a recorded root that now resolves through a symlink to the rebind target with `inspectRelocatedPhysicalRoot` instead of the realpath check, and the rebind transaction then calls `relocatePhysicalRoot` and moves `local_path`, the host binding and `relative_path` in place of a new worktree; a shared root advances every membership and permanently conflicts accepted old-topology requests. Withdrawal mirrors and running publication must settle first. Administrative UUIDs share the page journal's principal-scoped conflict domain and permanent capacity counters. Directory replacement reserves the configured recovery budget before provider/staging work, records a verified manifest and physical identity, and recovers only known bytes; clone failure retains the original checkout and a replayable failure receipt. Rebinding accepts a fresh candidate with exactly matching canonical content, including deletions. Stored worktree manifests and clone recovery records keep `digest`, `file_count`, `canonical_stamp` and `self_transfer` but no per-file map (#5790), so their size is independent of the worktree; `compactStoredManifest` drops a legacy map on rewrite, and transfer prepare/accept hash under the native lock before their transaction. #5200 (W14 P1.4): only a lifecycle operation that compares or records checkout bytes (`add` at an existing root, `claim`, `rebind`, `restore`; `reclone` in `topology-clone.ts`) walks and hashes the checkout; `archive`, `remove` and `purge` skip the walk when every binding of the source already carries a verified `digest` and refresh the stored manifest's `canonical_stamp` in place (`manifest = COALESCE(manifest,'{}') || {canonical_stamp}`), so a symlink that appeared after the claim no longer refuses a retire (a binding claimed before activation has no digest yet, and the retire records that first manifest because clone recovery needs it), and every dry run reports `manifest_required` so preview and real run agree (`test/source-retire-symlink-manifest.test.ts`). The `writer_manifest_unsafe` text names the manifest, not a transfer, since claim and rebind raise it too. Large-repo tests: `test/persistence-large-manifest.test.ts` (12k files, both engines via `test/e2e/persistence-large-manifest-postgres.test.ts`) and `test/e2e/persistence-large-manifest-50k.test.ts`. Old root refusal records remain. Metadata deletion retains local storage. Restart recovery rotates a bounded root scan so one conflict cannot starve other roots. Tests: `test/persistence-source-lifecycle.test.ts` on PGLite and guarded isolated Postgres. #6099: manifests are Git-scoped for Git checkouts; see `worktree-manifest.ts` in [managed sync and persistence stalls](persistence-stalls.md).
diff --git a/docs/guides/memory-boundaries.md b/docs/guides/memory-boundaries.md
index 1eb7773f0f..e141e9496d 100644
--- a/docs/guides/memory-boundaries.md
+++ b/docs/guides/memory-boundaries.md
@@ -66,6 +66,11 @@ for an edge needed immediately, then verify it with `get_links` or a graph query
Check the write receipt and the graph separately; a saved page is not proof of
graph reconciliation. See [graph setup](../../INSTALL_FOR_AGENTS.md#step-45-wire-the-knowledge-graph).
+A timeline entry has no update or remove operation: `add_timeline_entry`
+returns the rendered bullet, and editing or deleting that bullet in the page's
+Timeline section through `edit_page` (with `expected_revision`) refreshes or
+removes its row, because the page is the system of record for timeline rows.
+
## Where text goes
Local storage does not mean every enabled feature runs locally. Keyless keyword
diff --git a/docs/mcp/TOOL_REFERENCE.md b/docs/mcp/TOOL_REFERENCE.md
index d95fe813f3..c8dfd18c7e 100644
--- a/docs/mcp/TOOL_REFERENCE.md
+++ b/docs/mcp/TOOL_REFERENCE.md
@@ -16,7 +16,7 @@ the row shape per call.
## `add_timeline_entry`
-Append an entry to the canonical Markdown timeline and structured timeline store in one committed write. Exact replay changes neither store.
+Append an entry to the canonical Markdown timeline and structured timeline store in one committed write. Exact replay changes neither store. The receipt returns `bullet`, the rendered Markdown line. There is no update or remove verb: the page is the system of record, so to change or remove an entry read the page with `get_page include_content: true`, replace or delete that bullet with `edit_page` (passing `expected_revision`), and the timeline row follows the page.
| Parameter | Type | Guidance |
| --- | --- | --- |
diff --git a/src/core/operation-manifest.generated.ts b/src/core/operation-manifest.generated.ts
index 3843788e86..2478294b34 100644
--- a/src/core/operation-manifest.generated.ts
+++ b/src/core/operation-manifest.generated.ts
@@ -1755,7 +1755,7 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
"name": "add_timeline_entry",
"idempotent": true,
"outputRedaction": "retrieval",
- "description": "Append a dated entry to a page timeline. Replaying the same entry changes nothing. A page's Timeline section needs no call.",
+ "description": "Append a dated entry to a page timeline. Replaying the same entry changes nothing. A page's Timeline section needs no call. The receipt returns the rendered bullet; to change or remove an entry, edit that bullet in the page's Timeline section with edit_page (expected_revision from get_page include_content:true): the row follows the page.",
"params": {
"request_id": {
"type": "string",
@@ -1812,7 +1812,7 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
"mutating": false,
"idempotent": true,
"outputRedaction": "retrieval",
- "description": "Get timeline entries for a page, optionally filtered by date window",
+ "description": "Get timeline entries for a page, optionally filtered by date window. To change or remove an entry, edit its bullet in the page's Timeline section with edit_page (expected_revision from get_page include_content:true): the row follows the page.",
"params": {
"slug": {
"type": "string",
diff --git a/src/core/ops/timeline.ts b/src/core/ops/timeline.ts
index 411c3e4904..ca7cedcf25 100644
--- a/src/core/ops/timeline.ts
+++ b/src/core/ops/timeline.ts
@@ -24,7 +24,7 @@ const add_timeline_entry: Operation = {
name: 'add_timeline_entry',
idempotent: true,
outputRedaction: 'retrieval',
- description: 'Append a dated entry to a page timeline. Replaying the same entry changes nothing. A page\'s Timeline section needs no call.',
+ description: 'Append a dated entry to a page timeline. Replaying the same entry changes nothing. A page\'s Timeline section needs no call. The receipt returns the rendered bullet; to change or remove an entry, edit that bullet in the page\'s Timeline section with edit_page (expected_revision from get_page include_content:true): the row follows the page.',
params: {
request_id: WRITE_REQUEST_PARAM,
...MERGE_PRECONDITION_PARAMS,
@@ -72,7 +72,7 @@ const get_timeline: Operation = {
mutating: false,
idempotent: true,
outputRedaction: 'retrieval',
- description: 'Get timeline entries for a page, optionally filtered by date window',
+ description: 'Get timeline entries for a page, optionally filtered by date window. To change or remove an entry, edit its bullet in the page\'s Timeline section with edit_page (expected_revision from get_page include_content:true): the row follows the page.',
params: {
slug: { type: 'string', required: true, description: 'Slug of the page whose timeline entries to return.' },
after: { type: 'string', description: 'Return entries on or after this date (YYYY-MM-DD)' },
diff --git a/src/core/persistence/semantic-pages.ts b/src/core/persistence/semantic-pages.ts
index 708ed62888..d443be041b 100644
--- a/src/core/persistence/semantic-pages.ts
+++ b/src/core/persistence/semantic-pages.ts
@@ -93,6 +93,7 @@ export async function prepareSemanticPageMutation(engine: BrainEngine, row: Writ
const [stored] = gate.verdict === 'flag' ? await tx.executeRaw<{ id: number }>(`SELECT t.id FROM timeline_entries t JOIN pages p ON p.id = t.page_id
WHERE p.source_id = $1 AND p.slug = $2 AND t.date = $3::date AND t.summary = $4 ORDER BY t.id DESC LIMIT 1`, [row.source_id, row.slug, rendered.canonical.date, rendered.canonical.summary]) : [];
const flagged = stored ? gateField(gate, `p:${row.source_id}/${row.slug}`, await recordWriteGateReceipt(tx, { targetTable: 'timeline_entries', targetId: Number(stored.id), sourceId: row.source_id, assessment: gate, requestId: row.id })) : undefined;
- return { ...outcome, status: exact && !inserted ? 'skipped' : 'ok', ...(exact && !inserted ? { reason: 'duplicate' } : {}), entry: rendered.canonical, ...(flagged ? { gate: flagged } : {}) };
+ // #5970: the rendered bullet is the exact line to edit (edit_page) when the entry needs a correction.
+ return { ...outcome, status: exact && !inserted ? 'skipped' : 'ok', ...(exact && !inserted ? { reason: 'duplicate' } : {}), entry: rendered.canonical, bullet: rendered.block, ...(flagged ? { gate: flagged } : {}) };
} };
}
diff --git a/test/fixtures/goldens/cli/tools-json.json b/test/fixtures/goldens/cli/tools-json.json
index e3d0c9c34b..8da9832dd5 100644
--- a/test/fixtures/goldens/cli/tools-json.json
+++ b/test/fixtures/goldens/cli/tools-json.json
@@ -2,8 +2,8 @@
"golden": {
"exitCode": 0,
"stderr": "",
- "stdoutBytes": 230679,
- "stdoutSha256": "dc9a2b59ffbb454139bd202eb28d827cd45dc57b91605771d154625920306eda",
+ "stdoutBytes": 231070,
+ "stdoutSha256": "d28c9613d378d0cb35ea4c24191fd61efcb7cd9cf465b890e9853cf6cb8eab93",
"toolNames": [
"remember",
"entity",
@@ -2138,7 +2138,7 @@
"scope": "read"
},
{
- "description": "Append a dated entry to a page timeline. Replaying the same entry changes nothing. A page's Timeline section needs no call.",
+ "description": "Append a dated entry to a page timeline. Replaying the same entry changes nothing. A page's Timeline section needs no call. The receipt returns the rendered bullet; to change or remove an entry, edit that bullet in the page's Timeline section with edit_page (expected_revision from get_page include_content:true): the row follows the page.",
"idempotent": true,
"local_only": false,
"mutating": true,
@@ -2199,7 +2199,7 @@
"scope": "write"
},
{
- "description": "Get timeline entries for a page, optionally filtered by date window",
+ "description": "Get timeline entries for a page, optionally filtered by date window. To change or remove an entry, edit its bullet in the page's Timeline section with edit_page (expected_revision from get_page include_content:true): the row follows the page.",
"idempotent": true,
"local_only": false,
"mutating": false,
diff --git a/test/timeline-correction-path-5970.test.ts b/test/timeline-correction-path-5970.test.ts
new file mode 100644
index 0000000000..f211986855
--- /dev/null
+++ b/test/timeline-correction-path-5970.test.ts
@@ -0,0 +1,90 @@
+/**
+ * #5970 (wave 15 P2.7): the timeline correction path is named at the call
+ * site. There is no update/remove verb on purpose: the page body is the
+ * system of record for timeline rows, so a bullet edited through `edit_page`
+ * (with the page's `expected_revision`) refreshes or deletes its row. The op
+ * descriptions say so, and the `add_timeline_entry` receipt returns the
+ * rendered bullet so the caller can find the exact line to edit.
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { withEnv } from './helpers/with-env.ts';
+import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { dispatchToolCall as dispatchToolCallImpl } from '../src/mcp/dispatch.ts';
+import { operations } from '../src/core/operations.ts';
+
+const SOURCE = 'default';
+const OPTS = { remote: true, sourceId: SOURCE } as const;
+const SLUG = 'notes/timeline-correction-example';
+const BODY = 'Synthetic note body for the timeline correction path.';
+
+let engine: PGLiteEngine;
+const home = mkdtempSync(join(tmpdir(), 'gbrain-timeline-correction-'));
+
+async function dispatchToolCall(...args: Parameters<typeof dispatchToolCallImpl>) {
+ return withEnv({
+ GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined, OPENAI_API_KEY: undefined,
+ ANTHROPIC_API_KEY: undefined, OPENROUTER_API_KEY: undefined, VOYAGE_API_KEY: undefined, GBRAIN_EMBEDDING_MODEL: undefined,
+ }, async () => {
+ try { return await dispatchToolCallImpl(...args); }
+ finally { await disposePersistenceConsumer(args[0]); }
+ });
+}
+
+function payload(result: { content: Array<{ type: string; text: string }> }) {
+ return JSON.parse(result.content[0]!.text) as Record<string, unknown>;
+}
+
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+ mkdirSync(join(home, '.gbrain'));
+ writeFileSync(join(home, '.gbrain', 'config.json'), JSON.stringify({ engine: 'pglite', embedding_disabled: true }));
+ await engine.putPage(SLUG, { type: 'note', title: 'Timeline correction fixture', compiled_truth: BODY, timeline: '' }, { sourceId: SOURCE });
+});
+
+afterAll(async () => {
+ await engine.disconnect();
+ rmSync(home, { recursive: true, force: true });
+});
+
+describe('#5970 timeline correction path', () => {
+ test('both timeline op descriptions name the page-edit route with expected_revision', () => {
+ const byName = new Map(operations.map(op => [op.name, op]));
+ for (const name of ['add_timeline_entry', 'get_timeline']) {
+ const description = byName.get(name)!.description;
+ expect(description).toContain('edit_page');
+ expect(description).toContain('expected_revision');
+ expect(description).toMatch(/change or remove/i);
+ }
+ });
+
+ test('the add receipt returns the rendered bullet, which is the exact line in the page, and editing that line corrects the row', async () => {
+ const added = await dispatchToolCall(engine, 'add_timeline_entry', { slug: SLUG, date: '2026-03-02', summary: 'Signed the example lease', source: 'manual' }, OPTS);
+ expect(added.isError).toBeUndefined();
+ const receipt = payload(added);
+ expect(receipt).toMatchObject({ status: 'ok', entry: { date: '2026-03-02', source: 'manual', summary: 'Signed the example lease' } });
+ expect(receipt.bullet).toBe('- **2026-03-02** | manual — Signed the example lease');
+
+ const read = payload(await dispatchToolCall(engine, 'get_page', { slug: SLUG, include_content: true }, OPTS)) as { revision: string; content: string };
+ expect(read.content).toContain(receipt.bullet as string);
+
+ const edited = await dispatchToolCall(engine, 'edit_page', {
+ slug: SLUG, expected_revision: read.revision,
+ edits: [{ old_text: receipt.bullet as string, new_text: '- **2026-03-02** | manual — Signed the example sublease' }],
+ }, OPTS);
+ expect(edited.isError).toBeUndefined();
+
+ const timeline = payload(await dispatchToolCall(engine, 'get_timeline', { slug: SLUG }, OPTS)) as Array<{ summary: string }> | { entries?: Array<{ summary: string }> };
+ const entries = Array.isArray(timeline) ? timeline : (timeline.entries ?? []);
+ expect(entries.map(e => e.summary)).toEqual(['Signed the example sublease']);
+
+ // Replaying the original entry after the correction reports the duplicate identity, not a second row.
+ const replay = await dispatchToolCall(engine, 'add_timeline_entry', { slug: SLUG, date: '2026-03-02', summary: 'Signed the example sublease', source: 'manual' }, OPTS);
+ expect(payload(replay)).toMatchObject({ status: 'skipped', reason: 'duplicate', bullet: '- **2026-03-02** | manual — Signed the example sublease' });
+ });
+});