From f562a1a44f32fa52c345738c0079d12eb2c5cfba Mon Sep 17 00:00:00 2001 From: Vegard Stikbakke Date: Fri, 7 Aug 2026 09:55:13 +0200 Subject: [PATCH] docs(agent): clarify branch query helpers --- packages/agent/src/harness/session/session.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/agent/src/harness/session/session.ts b/packages/agent/src/harness/session/session.ts index 262cdcd8c..f4be8adfa 100644 --- a/packages/agent/src/harness/session/session.ts +++ b/packages/agent/src/harness/session/session.ts @@ -223,6 +223,7 @@ export class Session implem return this.queryLog(options); } + /** Returns the lane's current leaf, or null when empty. Throws when the lane does not exist. */ private async getLeafIdForLane(lane: string): Promise { const pointer = (await this.getLanes()).find((candidate) => candidate.lane === lane); if (!pointer) throw new SessionError("invalid_lane", `Lane not found: ${lane}`); @@ -235,14 +236,18 @@ export class Session implem return this.storage.findEntries(resultLimit === query.limit ? query : { ...query, limit: resultLimit }); } + /** + * Queries from `query.start` toward the root, defaulting to the lane's current leaf. + * `resultLimit` lets single-entry queries cap results without changing the caller's query. + */ private async queryBranchEntries( - lane: string, + defaultLane: string, query: EntryQuery & BranchBounds = {}, resultLimit = query.limit, ): Promise { assertValidLimit(query.limit); assertValidCursor(query.cursor?.afterSeq); - const start = query.start ?? (await this.getLeafIdForLane(lane)); + const start = query.start ?? (await this.getLeafIdForLane(defaultLane)); if (start === null) return []; const storageQuery = resultLimit === query.limit ? query : { ...query, limit: resultLimit }; return this.storage.findEntriesOnBranch({ ...storageQuery, start });