Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(pr3): gate fixes on the merged head: classify the five new write ops, write-refusal rows for revision_changed and tail_changed, abort_page_upload description, dispatch-context and governing-rule pins, BEHAVIOR block marker, managed huge put replays a pending request

garrytaneddf6ff13e56
diff --git a/docs/TOOL_CATALOG.md b/docs/TOOL_CATALOG.md
index 2429206e17..f999fc141d 100644
--- a/docs/TOOL_CATALOG.md
+++ b/docs/TOOL_CATALOG.md
@@ -168,7 +168,7 @@ Every non-localOnly operation on the MCP surface: 157 tools across 25 areas. **S
| Tool | Description | Scope | Starter | Gate |
|---|---|---|---|---|
-| `abort_page_upload` | Discard an uncommitted upload and free its staged bytes. | write | | |
+| `abort_page_upload` | Discard an uncommitted upload session: its staged parts are deleted and its quota is freed. | write | | |
| `append_page` | Add text to the end of a page, in time proportional to the text: use it for logs and conversations instead of re-putting a large page. | write | | |
| `begin_page_upload` | Start writing a page too large for one request: then upload_page_part from part 0 and commit_page_upload. | write | | |
| `cancel_write_request` | Cancel your accepted write before it publishes; returns the receipt. | write | yes | |
diff --git a/docs/architecture/managed-mutating-writers.tsv b/docs/architecture/managed-mutating-writers.tsv
index b2ad1cc24b..8a96883fbb 100644
--- a/docs/architecture/managed-mutating-writers.tsv
+++ b/docs/architecture/managed-mutating-writers.tsv
@@ -19,6 +19,11 @@ op remove_link coordinator coordinatedManualLinkWrite, same boundary as add_link
op add_timeline_entry coordinator submitPageMutation admits a journaled page mutation.
op revert_version coordinator submitPageMutation admits a journaled page mutation.
op edit_page coordinator submitPageMutation admits a journaled page mutation; edits apply to the locked snapshot.
+op append_page coordinator submitPageMutation admits a journaled page mutation; the append applies to the locked snapshot.
+op begin_page_upload no_canonical_write Opens an upload session row; no page is written until commit_page_upload.
+op upload_page_part no_canonical_write Stages one part of an upload session; no page is written until commit_page_upload.
+op commit_page_upload coordinator submitPageMutation admits the staged body as a journaled page mutation (put_page, or append_page in append mode).
+op abort_page_upload no_canonical_write Discards an uncommitted upload session and its staged parts; no page is written.
op put_skill coordinator Shared-skill publication through the persistence journal.
op delete_skill coordinator Shared-skill publication through the persistence journal.
op set_skill_policy no_canonical_write Shared-skill policy row, epoch-guarded; no page content.
diff --git a/docs/guides/write-refusals.md b/docs/guides/write-refusals.md
index 3689332828..1918189bb2 100644
--- a/docs/guides/write-refusals.md
+++ b/docs/guides/write-refusals.md
@@ -132,6 +132,8 @@ a receipt can report has a row here.
| `writer_pool_capacity` | `writer_pool_capacity` | The canonical owner has no free publication slot right now; the write stays queued. | Wait and poll the receipt (`gbrain write-request <id>`). If it persists, check `gbrain sources writer status <source>`. |
| `revision_required` | `revision_required` | The operation must be bound to a revision you reviewed (for example `--if-version` or `expected_revision`), and none was given: a `put_page` of a page that already exists without `expected_revision` reports this since #5385 (earlier releases said `revision_conflict`). | Preview first, then repeat with the revision the preview printed. |
| `revision_conflict` | `revision_conflict` | The page changed after the revision this write was bound to. Nothing was overwritten. | Re-read the page, merge your change, and save with the new revision. |
+| `revision_changed` | `revision_changed` | An `append_page` with `expected_revision`, or a `commit_page_upload` whose session was bound to a revision, found the page at a newer revision. Nothing was appended or written, and the upload session is aborted with its staged bytes released. | Read the page again (`get_page` with `body: 'none'`), check whether the text is still missing, then append against the new revision with a new `request_id` (for an upload, begin a new session). |
+| <a id="tail_changed"></a>`tail_changed` | `tail_changed` | An `append_page` with `expected_tail_sha256` found a different page end: another writer appended or edited first. Nothing was appended. | Read the page again (`get_page` with `body: 'none'` returns `tail_sha256`), check whether the text is still missing, and append against the current tail with a new `request_id`. |
| `sync_cursor_replaced` | `sync_cursor_replaced` | A managed sync checkpoint found that another sync run of the same source (a rediscovery, a newer sync) replaced the cursor it belongs to, so it had nothing left to publish. The receipt is a conflict; no managed-sync failure is recorded for it, and the run that awaited it goes on with the cursor that now covers the source. | Nothing: let the current sync finish. `gbrain sync status --source <id> --json` shows that cursor. A same-run index lag keeps reporting `revision_conflict`. |
| <a id="revision-backfill"></a>`revision_backfill_pending` | `revision_backfill_pending` | The page was written before page revisions existed (an upgrade from below schema v150) and the resumable revision backfill has not reached it, so it has no revision to bind to. Its revision reads as `backfill_pending`, never a UUID. Nothing was written. `gbrain doctor` reports the backfill as `revision_backfill` with the pending count and any failed rows by page. | Resume the backfill on the brain host with `gbrain apply-migrations --force-schema` (it prints its progress; `--yes` alone does not resume it once the schema is current). Rows that used all three attempts are no longer retried: run `gbrain repair orphan-children` to preview orphaned child rows and torn page bodies ([orphan children](repair.md#orphan-children)). |
| `idempotency_conflict` | `idempotency_conflict` | The `request_id` was already used for a different target, content or protocol. | Use a new `request_id` for a different write; reuse an ID only to replay the same write. |
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 00d1f4acde..92b984e598 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1010,6 +1010,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.320.0', text: 'A managed sync no longer stops a whole source when a file it would skip as already imported (a no-op waiver) has meanwhile become a symlink, a FIFO or an unreadable file in the working tree: that entry is simply not skipped and goes on like any other, where an unreadable file is held `file_unreadable`.' },
{ since: '0.60.320.0', text: 'A managed sync holds a committed file whose name is not valid UTF-8 (a Latin-1 name from an older system or an archive) under the new hold code `path_not_utf8`, naming the rename that fixes it, and the rest of the source syncs; before, the file was held with a raw Git error or stopped the source. Renaming the file to a UTF-8 name clears the hold. With `sync.holds=fail` the run stops with `path_not_utf8`.' },
{ since: '0.60.320.0', text: 'A managed sync of a folder of more than 20 pages moved with `git mv` keeps each page (a move, with its id, links and history): the mass-delete valve no longer counts a delete whose bytes arrive at a new path in the same round. Before, the valve withheld the old paths\' deletes in the first round, so every new path imported as a new page beside its old one (one `shares content_hash ... Indexing both` warning per file) and the old pages were deleted afterwards. A mass delete with nothing arriving is still withheld.' },
+ // Wave B PR 3 (page write operations: append_page, upload sessions, edit_page within). `since` is restamped at the merge slot.
{ since: 'TBD', text: 'New `append_page` adds text to the end of a page in time proportional to the text added, idempotent by `request_id`; use it for conversation logs instead of re-putting the page. `expected_tail_sha256` (the `tail_sha256` that `get_page` with `body: \'none\'` returns) refuses `tail_changed` when another writer appended first. `gbrain append <slug> [--file f | stdin]` calls it.' },
{ since: 'TBD', text: 'New upload sessions (`begin_page_upload`, `upload_page_part`, `get_page_upload`, `commit_page_upload`, `abort_page_upload`) let remote and thin clients write pages larger than one request, up to the page ceiling; `gbrain put --file` and `gbrain capture --file` use them on remote brains. A session is bound to the principal, source and page that began it (any other caller gets `upload_not_found`), staged bytes count against `persistence.limits` upload quotas (`write_quota_exhausted`), and an idle session expires after an hour. Locally, `gbrain put --file` and `gbrain capture --file` stream a file over 24 MiB straight in.' },
{ since: 'TBD', text: '`edit_page` accepts `within` to restrict a match to a range returned by a window read (`edit_target`), and edits a page stored in segments by rewriting only the segments the match touches instead of reading the whole page back.' },
diff --git a/src/core/operation-manifest.generated.ts b/src/core/operation-manifest.generated.ts
index 69e4868bf8..b0aa76284b 100644
--- a/src/core/operation-manifest.generated.ts
+++ b/src/core/operation-manifest.generated.ts
@@ -1111,7 +1111,7 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
"name": "abort_page_upload",
"idempotent": true,
"outputRedaction": "no_stored_text",
- "description": "Discard an uncommitted upload and free its staged bytes.",
+ "description": "Discard an uncommitted upload session: its staged parts are deleted and its quota is freed.",
"params": {
"upload_id": {
"type": "string",
diff --git a/src/core/ops/page-upload.ts b/src/core/ops/page-upload.ts
index 69e08b01db..86dfdec8aa 100644
--- a/src/core/ops/page-upload.ts
+++ b/src/core/ops/page-upload.ts
@@ -290,7 +290,7 @@ const abort_page_upload: Operation = {
name: 'abort_page_upload',
idempotent: true,
outputRedaction: 'no_stored_text',
- description: 'Discard an uncommitted upload and free its staged bytes.',
+ description: 'Discard an uncommitted upload session: its staged parts are deleted and its quota is freed.',
params: { upload_id: { type: 'string', required: true, description: 'From begin_page_upload.' } },
mutating: true,
scope: 'write',
diff --git a/test/behavior-change-notice-6712-block.test.ts b/test/behavior-change-notice-6712-block.test.ts
index 0a6fbd65aa..b6feb95029 100644
--- a/test/behavior-change-notice-6712-block.test.ts
+++ b/test/behavior-change-notice-6712-block.test.ts
@@ -25,7 +25,7 @@ function locateBlock(source: string): { rowLines: number; first: number; count:
const trimmed = line.trimStart();
if (trimmed.startsWith(MARKER)) { inBlock = true; first = rowLines; continue; }
if (trimmed.startsWith('//')) inBlock = false;
- const rows = line.match(/\{ since: '\d/g)?.length ?? 0;
+ const rows = line.match(/\{ since: '/g)?.length ?? 0;
rowLines += rows;
if (inBlock) count += rows;
}
@@ -49,9 +49,9 @@ describe('#6712 PR 4b BEHAVIOR_CHANGES block', () => {
expect(block.filter(row => row.since !== block[0]!.since).map(row => row.since)).toEqual([]);
});
- test("the block sits after master's rows: last in the array, and no earlier row is newer", () => {
- expect(first + count).toBe(BEHAVIOR_CHANGES.length);
+ test("the block sits after master's rows: no earlier row is newer, and no later row is older", () => {
expect(BEHAVIOR_CHANGES.slice(0, first).filter(row => compareReleases(row.since, block[0]!.since) > 0).map(row => row.since)).toEqual([]);
+ expect(BEHAVIOR_CHANGES.slice(first + count).filter(row => row.since !== 'TBD' && compareReleases(row.since, block[0]!.since) <= 0).map(row => row.since)).toEqual([]);
});
test(`every row of the block is plain text inside the rendered ${NOTICE_CAP}-character cap`, () => {
diff --git a/test/cli-page-writes.test.ts b/test/cli-page-writes.test.ts
index a4176f1a43..b44d4b47a3 100644
--- a/test/cli-page-writes.test.ts
+++ b/test/cli-page-writes.test.ts
@@ -188,7 +188,13 @@ for (const backend of testBackends()) {
}
expect(await managed()).toBe(true);
const body = hugeBody('Managed huge');
- const put = await cli(['put', 'notes/managed-huge', '--file', file('managed-huge.md', body)]);
+ const path = file('managed-huge.md', body);
+ let put = await cli(['put', 'notes/managed-huge', '--file', path]);
+ if (put.code === 10) {
+ const requestId = /Retry the same put with --request-id ([0-9a-f-]{36})/.exec(put.stderr)?.[1];
+ expect(requestId, put.stderr).toBeDefined();
+ put = await cli(['put', 'notes/managed-huge', '--file', path, '--request-id', requestId!]);
+ }
expect(put.code, put.stderr).toBe(0);
expect(await stored('notes/managed-huge')).toMatchObject({ body_storage: 'segmented' });
expect(await uploads()).toBeGreaterThan(0);
diff --git a/test/fixtures/goldens/cli/tools-json.json b/test/fixtures/goldens/cli/tools-json.json
index 12824760c6..fc9e438d91 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": 252763,
- "stdoutSha256": "32b0c98f713f00be91ab771872ceaec27deb8d5d75ad0814ae5fde298046c0cb",
+ "stdoutBytes": 252798,
+ "stdoutSha256": "71b348f0e16ec33eeb7b856a2fa24821a5f971503416d541e00226572381ab56",
"toolNames": [
"remember",
"entity",
@@ -1428,7 +1428,7 @@
"scope": "write"
},
{
- "description": "Discard an uncommitted upload and free its staged bytes.",
+ "description": "Discard an uncommitted upload session: its staged parts are deleted and its quota is freed.",
"idempotent": true,
"local_only": false,
"mutating": true,
diff --git a/test/mcp-instructions-governing-rule.test.ts b/test/mcp-instructions-governing-rule.test.ts
index cca9aafd9e..62479f26c8 100644
--- a/test/mcp-instructions-governing-rule.test.ts
+++ b/test/mcp-instructions-governing-rule.test.ts
@@ -24,7 +24,7 @@ const KEEP = 'drafts, proposals and agent-written notes do not override records'
const OLD = 'For what is true now, prefer the newest governing source';
const HARNESS_READ_LIMIT = 2_048;
/** [start, end) of the governing sentence per surface, default rendering. */
-const RECORDED_OFFSETS: Record<string, [number, number] | null> = { verbs: null, starter: [1_553, 1_829], full: [1_704, 1_980] };
+const RECORDED_OFFSETS: Record<string, [number, number] | null> = { verbs: null, starter: [1_553, 1_829], full: [1_705, 1_981] };
const render = (surface: typeof SURFACES[number], opts: Parameters<typeof buildMcpInstructions>[0] = {}) => {
const listed = new Set(filterOpsForSurface(operations, surface).map(o => o.name));
diff --git a/test/serve-http-mcp-dispatch-context.serial.test.ts b/test/serve-http-mcp-dispatch-context.serial.test.ts
index fd1c46c601..55f0b44f1b 100644
--- a/test/serve-http-mcp-dispatch-context.serial.test.ts
+++ b/test/serve-http-mcp-dispatch-context.serial.test.ts
@@ -89,7 +89,7 @@ async function rpc(base: string, token: string, method: string, params?: unknown
return JSON.parse(dataLine ? dataLine.slice('data:'.length) : text).result;
}
-const FULL_SURFACE_KEYS = ['admissionOrigin', 'auth', 'config', 'isListed', 'logger', 'metaHook', 'noticeLedger', 'remote', 'resultRows', 'sourceId', 'surface', 'surfaceCeiling', 'takesHoldersAllowList', 'transport'];
+const FULL_SURFACE_KEYS = ['admissionOrigin', 'auth', 'config', 'inboundFrameBytes', 'isListed', 'logger', 'metaHook', 'noticeLedger', 'remote', 'resultRows', 'sourceId', 'surface', 'surfaceCeiling', 'takesHoldersAllowList', 'transport'];
describe('POST /mcp dispatch context', () => {
test('full surface: remote http dispatch with the verified auth and token source scope', async () => {