Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

GBRA-156: a subagent job delegated by a remote OAuth client keeps the remote page cap

garrytan7ca8663eaea0
diff --git a/src/core/search/remote-page-cap.ts b/src/core/search/remote-page-cap.ts
index aa826c85ac..0161d3d9bb 100644
--- a/src/core/search/remote-page-cap.ts
+++ b/src/core/search/remote-page-cap.ts
@@ -15,8 +15,8 @@
* pages the keyword path returns, and lets vector-only pages fill the result
* only up to `search.remote_page_cap` distinct pages in total. A query with
* no lexical match still gets its top vector pages. An explicit `limit`, a
- * paged call (offset > 0), every trusted local caller and a delegated host
- * subagent tool call (`viaSubagent`) keep today's rows;
+ * paged call (offset > 0), every trusted local caller and a host subagent
+ * tool call (`viaSubagent`) that no remote client delegated keep today's rows;
* `0` turns the cap off.
*/
import type { OperationContext } from '../ops/contract.ts';
@@ -34,7 +34,7 @@ export interface RemotePageCapMeta {
/** The cap for one call, or null when it does not apply. */
export async function remotePageCap(ctx: OperationContext, p: Record<string, unknown>): Promise<number | null> {
- if (ctx.remote === false || ctx.viaSubagent === true || p.limit || p.offset) return null;
+ if (ctx.remote === false || (ctx.viaSubagent === true && !ctx.auth) || p.limit || p.offset) return null;
const raw = await ctx.engine.getConfig(REMOTE_PAGE_CAP_KEY).catch(() => null);
const n = raw === null || raw.trim() === '' ? Number.NaN : Number(raw);
const cap = Number.isInteger(n) && n >= 0 ? n : DEFAULT_REMOTE_PAGE_CAP;
diff --git a/test/search-remote-page-cap.test.ts b/test/search-remote-page-cap.test.ts
index 6e93f2212c..bb79979f78 100644
--- a/test/search-remote-page-cap.test.ts
+++ b/test/search-remote-page-cap.test.ts
@@ -74,6 +74,11 @@ describe('remotePageCap callers and the cap line', () => {
expect(await remotePageCap({ remote: true, engine } as never, {})).toBe(DEFAULT_REMOTE_PAGE_CAP);
});
+ test('a subagent job delegated by a remote OAuth client stays capped', async () => {
+ const auth = { token: '', clientId: 'client-example', principal: { kind: 'oauth_client', id: 'client-example' } };
+ expect(await remotePageCap({ remote: true, viaSubagent: true, auth, engine } as never, {})).toBe(DEFAULT_REMOTE_PAGE_CAP);
+ });
+
test('the line names only the pages the cap left out, and the flag the reader passes', () => {
const retrieval = { page_cap: { cap: 3, kept_pages: 3, dropped_pages: 9 } };
expect(pageCapLine(retrieval)).toBe('[gbrain search] 9 more pages matched only by meaning and were left out (default remote cap 3). Pass limit to read them.');