Skip to content

feat(sdk): TypeScript SDK — crash-resume via resumeRun - #103

Merged
prashar32 merged 1 commit into
mainfrom
feat/ts-sdk-resume
Jun 12, 2026
Merged

feat(sdk): TypeScript SDK — crash-resume via resumeRun#103
prashar32 merged 1 commit into
mainfrom
feat/ts-sdk-resume

Conversation

@prashar32

Copy link
Copy Markdown
Owner

Adds the resume path to the TypeScript SDK so a Node/TS agent can pick its work
back up after a crash — the JS counterpart to the Python SDK's resume_run.

Runtime.resumeRun(runId, fn) re-attaches to an existing governed run by id. Unlike
governedRun, it neither creates a new run nor cancels on error: the daemon reloads
non-terminal runs on restart with the budget and usage they had already spent, so
enforcement continues without re-spending. The agent reads run.latestCheckpoint()
to resume from where it left off — the run id is the only thing it has to keep across
a restart.

await rt.resumeRun(runId, async (run) => {
  const cp = await run.latestCheckpoint();
  const start = (cp?.payload?.cursor as number) ?? 0;
  for (let i = start; i < total; i++) {
    await run.step();                     // counts against the SAME budget
    await run.checkpoint("step", { cursor: i + 1 });
  }
});

Tests

Exercised over real HTTP against the in-process mock daemon (no daemon, no keys):

  • a run that crashed after 3 paid steps re-attaches, reads its checkpoint, and
    continues stepping at index 3 (the counter does not reset) — no overspend on restart;
  • resumeRun never cancels a run it didn't start when the body throws;
  • an unknown run id surfaces APIError(404).

Docs: a "Resume after a crash" section in the SDK README and a CHANGELOG entry.

Closes #80.

Add Runtime.resumeRun(runId, fn) so a Node/TypeScript agent can re-attach to
an existing governed run after a crash. Like the Python SDK's resume_run, it
neither creates a new run nor cancels on error: the daemon reloads the run with
the budget and usage it had already spent, so enforcement continues without
re-spending. Read run.latestCheckpoint() to pick the work back up from the last
checkpoint.

Test the resume path end-to-end against the in-process mock daemon: a run that
crashed after paid steps re-attaches, continues stepping against the same budget
(no counter reset), never cancels on a thrown body, and surfaces APIError(404)
for an unknown run id. README gets a "Resume after a crash" section.
@prashar32
prashar32 merged commit 856ae33 into main Jun 12, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TS SDK: crash-resume (resumeRun) attaching to an existing run

1 participant