Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(loops): open_loops flat truncated marks a list cut by the limit or the 500-row cap; loops list says how many it showed (#7291)

garrytan4a5d6c62e03d
diff --git a/src/commands/loops.ts b/src/commands/loops.ts
index 35bac0217e..d168b5f714 100644
--- a/src/commands/loops.ts
+++ b/src/commands/loops.ts
@@ -309,7 +309,7 @@ export async function runLoops(engine: BrainEngine, args: string[]): Promise<voi
'open_loops',
{ group_by: 'none', limit: 200, ...narrowing },
readScope,
- )) as { loops: Array<Record<string, unknown>>; count: number };
+ )) as { loops: Array<Record<string, unknown>>; count: number; truncated: boolean };
if (json) {
process.stdout.write(JSON.stringify({ ok: true, status: 'ok', ...result }, null, 2) + '\n');
return;
@@ -322,6 +322,7 @@ export async function runLoops(engine: BrainEngine, args: string[]): Promise<voi
const due = l.due_at ? ` due ${String(l.due_at).slice(0, 10)}` : '';
process.stdout.write(`#${String(l.id).padEnd(5)} [${String(l.loop_type)}]${due} ${String(l.summary)}\n`);
}
+ if (result.truncated) process.stdout.write(`Showing the ${result.loops.length} most recently active of ${result.count}${result.count >= 500 ? '+' : ''} matching loops.\n`);
return;
}
diff --git a/src/core/operation-manifest.generated.ts b/src/core/operation-manifest.generated.ts
index cca15f2d97..ce4a8eea9f 100644
--- a/src/core/operation-manifest.generated.ts
+++ b/src/core/operation-manifest.generated.ts
@@ -6795,7 +6795,7 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
},
"limit": {
"type": "number",
- "description": "Grouped: max groups (default 3). Flat: max loops (default 50). The internal fetch is capped at 500 rows; `truncated: true` marks a hit."
+ "description": "Grouped: max groups (default 3). Flat: max loops (default 50); `count` is the number matched (at most 500) and `truncated: true` marks a list cut by this limit or by the 500-row internal cap (then `count` is a lower bound)."
},
"include_context": {
"type": "boolean",
diff --git a/src/core/ops/loops.ts b/src/core/ops/loops.ts
index 44e776d04d..86a159d1b3 100644
--- a/src/core/ops/loops.ts
+++ b/src/core/ops/loops.ts
@@ -413,7 +413,7 @@ const open_loops: Operation = {
id: { type: 'number', description: 'Fetch the single loop with this id (ids come from earlier open_loops results). Matches any status unless `status` is passed; the source scope still applies, and the grouped view omits `text`.' },
loop_type: { type: 'string', enum: ['commitment_owed_by_me', 'commitment_owed_to_me', 'unanswered_inbound', 'unanswered_outbound', 'decision_pending'], description: 'Filter to one loop type.' },
counterparty: { type: 'string', description: 'Filter to one counterparty (slug or email).' },
- limit: { type: 'number', description: 'Grouped: max groups (default 3). Flat: max loops (default 50). The internal fetch is capped at 500 rows; `truncated: true` marks a hit.' },
+ limit: { type: 'number', description: 'Grouped: max groups (default 3). Flat: max loops (default 50); `count` is the number matched (at most 500) and `truncated: true` marks a list cut by this limit or by the 500-row internal cap (then `count` is a lower bound).' },
include_context: { type: 'boolean', description: 'Attach the counterparty entity card per group (trusted local only). Default true.' },
source_id: { type: 'string', description: "Scope to one source (e.g. the google source, when the caller's transport is bound elsewhere). Remote callers must hold a grant covering it." },
all_sources: { type: 'boolean', description: 'Trusted local: span every source in the brain. Remote callers stay inside their grant.' },
@@ -481,21 +481,22 @@ const open_loops: Operation = {
...(p.loop_type ? { loopType: p.loop_type as LoopType } : {}),
...(p.counterparty ? { counterparty: p.counterparty as string } : {}),
...(loopId === undefined ? {} : { loopId }),
- limit: 500,
+ limit: 501,
});
+ const capped = loops.length > 500;
+ if (capped) loops.length = 500;
const freshness = await googleSourceFreshness(ctx, scope);
const noGoogleSources = freshness.sources.length === 0;
const partialStaleSources = freshness.stale ? [] : freshness.staleSources;
const coverage = await heldCoverage(ctx, freshness.sources, trusted);
const deepLinks = trusted ? await deepLinksFor(ctx, loops) : new Map<string, string>();
- const truncated = loops.length >= 500;
if (groupBy === 'none') {
const limit = Math.min(Math.max((p.limit as number | undefined) ?? 50, 1), 500);
return {
loops: loops.slice(0, limit).map((l) => loopView(l, trusted, deepLinks)),
count: loops.length,
- truncated,
+ truncated: capped || loops.length > limit,
stale: freshness.stale,
sources: freshness.sources,
...(partialStaleSources.length > 0 ? { stale_sources: partialStaleSources } : {}),
@@ -597,7 +598,7 @@ const open_loops: Operation = {
no_counterparty: noCounterparty,
...(loopId === undefined ? { withheld_noise: await withheldNoise(ctx, freshness.sources) } : {}),
count: loops.length,
- truncated,
+ truncated: capped,
stale: freshness.stale,
sources: freshness.sources,
...(partialStaleSources.length > 0 ? { stale_sources: partialStaleSources } : {}),
diff --git a/test/fixtures/goldens/cli/tools-json.json b/test/fixtures/goldens/cli/tools-json.json
index bdf0a71950..6fe1ddf382 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": 265045,
- "stdoutSha256": "4358e6505ccac2f00bcbe3a01fb54daf3d13c8a7c526315a8c53aaf223a01dc8",
+ "stdoutBytes": 265133,
+ "stdoutSha256": "bdb9a113cc33b3e0dc7d4e9c5342f711dc5b083f96208c768326fbf02ff7fd0b",
"toolNames": [
"remember",
"entity",
@@ -7928,7 +7928,7 @@
"type": "boolean"
},
"limit": {
- "description": "Grouped: max groups (default 3). Flat: max loops (default 50). The internal fetch is capped at 500 rows; `truncated: true` marks a hit.",
+ "description": "Grouped: max groups (default 3). Flat: max loops (default 50); `count` is the number matched (at most 500) and `truncated: true` marks a list cut by this limit or by the 500-row internal cap (then `count` is a lower bound).",
"type": "number"
},
"loop_type": {
diff --git a/test/ops-loops.test.ts b/test/ops-loops.test.ts
index 31c2819c83..0488caf33a 100644
--- a/test/ops-loops.test.ts
+++ b/test/ops-loops.test.ts
@@ -424,6 +424,9 @@ describe('open_loops group_by none (flat)', () => {
};
expect(res.loops).toHaveLength(2);
expect(res.count).toBe(5);
+ // #7291: a list cut by the limit says so.
+ expect((res as { truncated?: boolean }).truncated).toBe(true);
+ expect(((await openLoopsOp.handler(ctx(), { group_by: 'none', limit: 5 })) as { truncated: boolean }).truncated).toBe(false);
// Ordered by last_activity_at DESC → the two newest.
expect(res.loops.map((l) => l.counterparty_email)).toEqual([