From 54aad330a942f47414862371b5a8998af36c96ab Mon Sep 17 00:00:00 2001 From: Ray Xu Date: Sat, 9 May 2026 22:30:20 -0700 Subject: [PATCH] fetchProgress: accept optional sessionId to scope history walk-back MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds an optional `sessionId` field to PlatformClient.fetchProgress's options. When set together with `history: true`, the field is forwarded to the platform as `?session_id=` and instructs the server to scope its previous-job walk-back to records matching that session id rather than returning the most-recent previous job only. Used by resume-after-permission-timeout flows where the resumed job's target session may not be the most recent in the assignment — an unrelated sibling job (e.g. an integrator follow-up that landed between the original session pausing and the user clicking 'Allow') would otherwise shadow the target session's progress snapshot, and the resumed runtime would silently degrade to a fresh session instead of restoring conversation state. The field is purely additive; existing callers that do not pass it get identical behavior to before. Server-side support already ships in sweagentd's `/jobs/:jobID/progress?session_id=` query parameter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/client.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/client.ts b/src/client.ts index 98a0642..36eb173 100644 --- a/src/client.ts +++ b/src/client.ts @@ -407,10 +407,23 @@ export class PlatformClient { /** * Fetches progress records from the platform, optionally filtered by * namespace and including history from previous jobs. + * + * @param options.namespace Restrict results to a single namespace. + * @param options.history When true, walk back to previous jobs in the + * same assignment for cross-job context. The platform's default + * walk-back returns only the most recent previous job's records. + * @param options.sessionId When set together with `history: true`, + * scope the walk-back to a specific session id rather than the + * default newest-job-only behavior. Used by resume-after-permission- + * timeout flows where the target session may not be the most recent + * in the assignment, so an unrelated newer sibling job would + * otherwise shadow the session's progress snapshot. Empty/undefined + * preserves the existing newest-job-only behavior. */ async fetchProgress(options?: { namespace?: string; history?: boolean; + sessionId?: string; }): Promise { const url = new URL(`jobs/${this._jobId}/progress`, this.baseUrl); if (options?.namespace) { @@ -419,6 +432,9 @@ export class PlatformClient { if (options?.history) { url.searchParams.set("history", "true"); } + if (options?.sessionId) { + url.searchParams.set("session_id", options.sessionId); + } try { const response = await fetch(url.toString(), {