Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(versions): a segmented version's body_ref no longer names a get_page read that returns the current page (#7800)

garrytanb8c24f71030f
diff --git a/docs/guides/repair.md b/docs/guides/repair.md
index fbfc157404..6a93c84f91 100644
--- a/docs/guides/repair.md
+++ b/docs/guides/repair.md
@@ -3884,7 +3884,8 @@ brain had recorded it at an instant, from the belief ledger
`as_of` on `get_links`, which is valid time (a date). A read answers with the
interval the instant falls in, `certified` (false with `uncertified_reason` on
an unmanaged source, a drifted interval or a truncated walk), and a `body` of
-`live`, `version`, `segmented` (read it through `body_ref`) or `unavailable`
+`live`, `version`, `segmented` (`body_ref` gives its size; no read serves an
+older segmented body yet) or `unavailable`
with a `body_reason` (`purged`, `expired`, `hard_deleted`, `pruned`,
`version_missing`). A body no retained version holds is disclosed, never
borrowed from the version next to it. The refusals below change nothing; run
diff --git a/src/core/ops/admin.ts b/src/core/ops/admin.ts
index fe302f850d..d22b9e139b 100644
--- a/src/core/ops/admin.ts
+++ b/src/core/ops/admin.ts
@@ -236,14 +236,13 @@ const get_versions: Operation = {
}
const plain = page(await ctx.engine.getVersions(p.slug as string, opts));
const versions = canReadWriteAttribution(ctx) ? await attributeVersions(ctx.engine, plain) : plain;
- // Wave B: a segmented version's body is never returned whole; body_ref names its size and the windowed read.
+ // Wave B: a segmented version's body is never returned whole; body_ref names its size (no read serves an older segmented body yet, #7800).
const out = [];
for (const v of versions) {
if (isSegmentedPage(v)) {
const sized = await remoteVersionSize(ctx, v);
const { compiled_truth: _b, timeline: _t, ...rest } = sized;
- out.push({ ...rest, body_ref: { version_id: v.id, total_bytes: 'total_bytes' in sized ? sized.total_bytes : pageBodyBytes(v),
- read: { tool: 'get_page', arguments: { slug: p.slug, version_id: v.id, body: 'window' } } } });
+ out.push({ ...rest, body_ref: { version_id: v.id, total_bytes: 'total_bytes' in sized ? sized.total_bytes : pageBodyBytes(v) } });
continue;
}
if (ctx.remote === false) { out.push(v); continue; }
diff --git a/src/core/ops/known-as-of.ts b/src/core/ops/known-as-of.ts
index 9e0e2c53a5..de4c2cea37 100644
--- a/src/core/ops/known-as-of.ts
+++ b/src/core/ops/known-as-of.ts
@@ -79,7 +79,7 @@ function intervalView(ctx: OperationContext, i: PageInterval, opts: { body: bool
if (!opts.body || !i.page) return meta;
const bytes = i.page.body_bytes ?? 0;
if (i.body === 'segmented' || bytes > opts.inlineMax) {
- return { ...meta, body_ref: { total_bytes: bytes, ...(i.version_id != null ? { read: { tool: 'get_page', arguments: { slug: i.slug, version_id: i.version_id, body: 'window' } } } : {}) } };
+ return { ...meta, body_ref: { total_bytes: bytes } };
}
const clean = (s: string | null) => s == null ? null : ctx.remote === false ? s : sanitizeRemoteBody(s, { includeWithdrawn: true, keepMaterializedMarkers: true });
// #8042: a third-party page as recorded reaches an untrusted reader quoted, as get_page's current body does.
diff --git a/test/large-pages/segmented-versions.test.ts b/test/large-pages/segmented-versions.test.ts
index 6d0da78ef9..daaea4b257 100644
--- a/test/large-pages/segmented-versions.test.ts
+++ b/test/large-pages/segmented-versions.test.ts
@@ -140,8 +140,16 @@ for (const kind of testBackends()) {
const [full] = await operationsByName.get_versions!.handler(ctx, { slug: SLUG, include_body: true }) as Array<Record<string, unknown>>;
expect(full).not.toHaveProperty('compiled_truth');
expect(full).not.toHaveProperty('timeline');
- expect(full!.body_ref).toEqual({ version_id: full!.id, total_bytes: 2 * KB,
- read: { tool: 'get_page', arguments: { slug: SLUG, version_id: full!.id, body: 'window' } } });
+ expect(full!.body_ref).toEqual({ version_id: full!.id, total_bytes: 2 * KB });
+ });
+
+ test('#7800: a segmented version body_ref never names a read get_page does not serve', async () => {
+ await engine.createVersion(SLUG);
+ const ctx = { engine, config: { engine: engine.kind }, remote: false, dryRun: false, logger: { info() {}, warn() {}, error() {} } } as unknown as OperationContext;
+ const [full] = await operationsByName.get_versions!.handler(ctx, { slug: SLUG, include_body: true }) as Array<{ body_ref: { read?: { tool: string; arguments: Record<string, unknown> } } }>;
+ const read = full!.body_ref.read;
+ const params = operationsByName[read?.tool ?? 'get_page']!.params;
+ expect(Object.keys(read?.arguments ?? {}).filter(k => !(k in params))).toEqual([]);
});
test('revertToVersion refuses a segmented version with page_body_segmented and writes nothing', async () => {