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 });