Skip to content

fix(sdk-ts): forward resumeSessionId to Claude Code as resume - #1216

Closed
reachtrevor wants to merge 3 commits into
Agent-Field:mainfrom
reachtrevor:fix/ts-claude-code-resume
Closed

reachtrevor wants to merge 3 commits into
Agent-Field:mainfrom
reachtrevor:fix/ts-claude-code-resume

Conversation

@reachtrevor

Copy link
Copy Markdown

Summary

HarnessOptions.resumeSessionId is part of the TypeScript harness API, and the runner passes it through to the provider, but ClaudeCodeProvider never forwards it to the Claude Agent SDK. As a result, agent.harness(prompt, { provider: 'claude-code', resumeSessionId }) silently starts a new Claude Code session on every call. The Python provider already handles this (sdk/python/agentfield/harness/providers/claude.py maps resume_session_id to agent_options["resume"]), and the TS pi provider already honors resumeSessionId.

This PR maps a non-empty string resumeSessionId to the SDK's resume option in ClaudeCodeProvider.execute. An absent or empty value leaves resume unset, so existing callers are unaffected.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Docs only
  • Tests only
  • CI / tooling
  • Breaking change

Test plan

  • cd sdk/typescript && npx vitest run --config vitest.config.ts tests/harness_provider_claude.test.ts (16 passed)
  • cd sdk/typescript && npm test (102 files, 1494 passed, 1 skipped)
  • cd sdk/typescript && npm run lint (tsc --noEmit, clean)

Test coverage

Added a parameterized test in sdk/typescript/tests/harness_provider_claude.test.ts, mocking @anthropic-ai/claude-agent-sdk the same way as the existing provider tests. It asserts that resume reaches query() options when resumeSessionId is set, and that resume is absent when resumeSessionId is missing or an empty string. The new test fails without the provider change.

  • I ran tests for the surface(s) I changed locally.
  • New code paths are covered by tests in this PR (no bare additions).
  • If I removed code, I updated coverage-baseline.json in this PR only if the removal caused a legitimate regression and I called it out in the summary above.
  • The coverage gate check is green in CI before requesting review.

Checklist

Related issues / PRs

None found.

HarnessOptions accepts resumeSessionId, but ClaudeCodeProvider never
passed it to the Claude Agent SDK, so every harness call with
provider 'claude-code' started a fresh session. Map a non-empty
resumeSessionId to the SDK's resume option, matching the Python
provider.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Trevor Pierce <trevor@reachtrevor.com>
@reachtrevor
reachtrevor requested review from a team and AbirAbbas as code owners November 18, 2026 18:23
@CLAassistant

CLAassistant commented Nov 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ ZeroPoint95
❌ reachtrevor
You have signed the CLA already but the status is still pending? Let us recheck it.

@ZeroPoint95

Copy link
Copy Markdown
Contributor

Hi @reachtrevor,

Thanks for wiring resumeSessionId through to Claude’s resume option. That fixes the TypeScript SDK silently ignoring the session ID. Once resume works, the harness needs to handle two additional cases:

  • Retries can replay a turn. If Claude writes to the resumed session or runs a tool before the connection drops, AgentField can submit the same prompt to the same session again. The follow-up prevents AgentField from retrying a failed resume through both agent.harness() and executeWithRetry().
  • Session totals can overstate run cost. Claude can include earlier session spend in total_cost_usd. If the first run costs $0.50 and the follow-up costs $0.25, Claude correctly reports $0.75 for the session. Recording that $0.75 as the follow-up’s cost makes AgentField report $1.25 across the two runs, counting the original $0.50 twice. The follow-up leaves costUsd unset when Claude reports only the cumulative total. Token usage and the raw SDK response remain available. Claude’s cost-tracking docs

I’m pushing one follow-up commit with both fixes and their regression tests, plus a merge commit to bring the branch up to date with main.

I verified with the official Claude Agent SDK against a local test endpoint that a follow-up reused the same session and included the prior turn. The full TypeScript suite finished with 1,500 tests passed and 1 skipped.

@ZeroPoint95

Copy link
Copy Markdown
Contributor

CLA assistant check Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.1 out of 2 committers have signed the CLA.✅ ZeroPoint95❌ reachtrevorYou have signed the CLA already but the status is still pending? Let us recheck it.

@reachtrevor please also sign the CLA here when you have a minute. Thanks :)

@github-actions

Copy link
Copy Markdown
Contributor

Performance

SDK Memory Δ Latency Δ Tests Status
TS 365 B +4% 1.15 µs -43% ✓ ✓

✓ No regressions detected

@github-actions

Copy link
Copy Markdown
Contributor

📊 Coverage gate

Thresholds from .coverage-gate.toml: per-surface ≥ 84%, aggregate ≥ 85%, max per-surface regression ≤ 1.0 pp, max aggregate regression ≤ 0.50 pp.

Surface Current Baseline Δ
control-plane 88.20% 87.40% ↑ +0.80 pp 🟡
sdk-go 93.40% 92.00% ↑ +1.40 pp 🟢
sdk-python 94.83% 93.73% ↑ +1.10 pp 🟢
sdk-typescript 92.60% 90.42% ↑ +2.18 pp 🟢
web-ui 84.92% 84.79% ↑ +0.13 pp 🟡
aggregate 86.13% 85.75% ↑ +0.38 pp 🟡

✅ Gate passed

No surface regressed past the allowed threshold and the aggregate stayed above the floor.

@github-actions

Copy link
Copy Markdown
Contributor

📐 Patch coverage gate

Threshold: 80% on lines this PR touches vs origin/main (from .coverage-gate.toml:thresholds.min_patch).

Surface Touched lines Patch coverage Status
control-plane 0 — ➖ no changes
sdk-go 0 — ➖ no changes
sdk-python 0 — ➖ no changes
sdk-typescript 4 100.00% ✅
web-ui 0 — ➖ no changes

✅ Patch gate passed

Every surface whose lines were touched by this PR has patch coverage at or above the threshold.

@AbirAbbas

Copy link
Copy Markdown
Contributor

Closing this for now because the CLA is still unsigned for reachtrevor's commit (the bot asked on Nov 18, and again on Nov 20). The change itself was approved, so once it's signed through the CLA link above, leave a comment and we'll reopen and merge it.

@AbirAbbas AbirAbbas closed this Nov 23, 2026
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.

4 participants