Skip to content

fix(code): preserve JavaScript subagent costs across resume - #6433

Merged
Mason Daugherty (mdrxy) merged 6 commits into
mainfrom
mdrxy/code/js-subagent-durable-cost
Sep 29, 2026
Merged

Mason Daugherty (mdrxy) merged 6 commits into
mainfrom
mdrxy/code/js-subagent-durable-cost

Conversation

@mdrxy

@mdrxy Mason Daugherty (mdrxy) commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Session costs retain JavaScript subagent spending across interruptions, resumes, failures, and nested cancellation without replaying cached JavaScript task results.


  • Keep the accounting bridge local to deepagents-code: only owned cost transfers reach parent state; child messages and unrelated state remain isolated.
  • Persist each locally priced accounting-node delta in the existing thread checkpointer before returning its graph update. Descendants share the outer eval's accounting owner; transferred totals are excluded from receipts to avoid double-counting.
  • Resume child graphs under request-fingerprint and identical-request occurrence namespaces, rather than positional langgraph.func.task results. Parallel completion order cannot exchange results for different requests. Direct task calls and structured output stay intact.
  • Settle cancellation and receipt writes before collecting spend. Child graphs use synchronous checkpoint durability even when the parent uses exit durability, because successful nested graphs otherwise leave no resumable checkpoint.

This covers the async interpreter with a checkpointer, including reopened SQLite checkpoints. Receipts use the existing saver and thread retention, with one additional checkpoint per priced node and an eval-scoped metadata query. Arbitrary JavaScript side effects are not exactly-once; identical requests remain occurrence-ordered, and nondeterministic scripts are not made replay-safe. The adapter relies on LangGraph's private namespace/scratchpad configuration. It does not recover provider usage lost before pricing/persistence, and synchronous interpreter accounting is unchanged.

Made by Open SWE · view thread · openai:gpt-5.6-sol (medium)

@github-actions github-actions Bot added org:internal Issue or pull request created by a member of the `langchain-ai` GitHub organization. package:dcode Changes related to the `deepagents-code` terminal coding agent. size: L Pull request with a large diff. type:bug An unexpected problem or incorrect behavior. labels Sep 18, 2026

@open-swe open-swe Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Open SWE Review: No issues found

Open SWE reviewed this PR and found no potential bugs to report.

Open in Web • View Open SWE trace

@github-actions github-actions Bot added size: XL Pull request with an extra-large diff. topic:performance Performance, resource usage, and cost optimization. size: L Pull request with a large diff. and removed size: L Pull request with a large diff. size: XL Pull request with an extra-large diff. labels Sep 19, 2026
@mdrxy

Copy link
Copy Markdown
Member Author

Related upstream work: langchain-ai/langgraph#8819 (currently an open draft) proposes Send(..., key=...), where task identity derives from an explicit key rather than packet position, and child graphs inherit a stable checkpoint namespace. Its tests cover interrupt/resume with reversed arrival order and keyed child persistence under exit durability. The PR description explicitly calls for LangChain/Deep Agents integration.

This looks worth coordinating with as a path to removing the namespace/scratchpad manipulation here. It is not a drop-in replacement: this JavaScript bridge directly invokes the task tool, whereas the proposed public API assigns keys through Send. We would need to route these dispatches through keyed Sends or have a supported API for keying direct child invocations. The key would also need to distinguish separate evals and identical-request occurrences.

The cost receipts and cancellation settlement would still be needed; stable child identity alone does not preserve spending when a child fails before returning. Separately, we could reduce private API use by passing the existing saver explicitly and setting public durability="sync" at the child graph invocation rather than through __pregel_durability.

@open-swe
open-swe Bot force-pushed the mdrxy/code/js-subagent-durable-cost branch from b50fc76 to cbf1860 Compare September 28, 2026 21:36
@mdrxy
Mason Daugherty (mdrxy) marked this pull request as ready for review September 29, 2026 15:25
@mdrxy
Mason Daugherty (mdrxy) merged commit 340a73c into main Sep 29, 2026
60 checks passed
@mdrxy
Mason Daugherty (mdrxy) deleted the mdrxy/code/js-subagent-durable-cost branch September 29, 2026 15:25
Mason Daugherty (mdrxy) pushed a commit that referenced this pull request Sep 29, 2026
> [!CAUTION]
> Merging this PR will automatically publish to **PyPI** and create a
**GitHub release**.

For the full release process, see
[`.github/RELEASING.md`](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md).

---

_Release notes preview: keep this section in sync with the package
`CHANGELOG.md`. Publish reads the merged CHANGELOG via `release.yml`,
not this PR description — keep them aligned anyway so the PR stays an
accurate historical record for reviewers and anyone returning later._

---


##
[0.1.79](deepagents-code==0.1.78...deepagents-code==0.1.79)
(2026-09-29)

### Bug Fixes

- MCP tool calls now use configurable timeouts to prevent them from
hanging indefinitely
([#6625](#6625)).
- Stdio MCP servers now start in the session directory
([#6626](#6626)).
- JavaScript subagent costs are preserved when resuming a session
([#6433](#6433)).
- Thread switching now completes its preflight faster and shows progress
sooner ([#6607](#6607)).
- The `/effort` setting is now constrained for between-tools thinking
([#6630](#6630)).
- CLI help now displays the same defaults used at runtime
([#6613](#6613)).
- The incognito label now appears on the chat input border
([#6627](#6627)).

_End release notes preview._

---

> [!NOTE]
> A **community contributors** list and a **Special thanks** section
(crediting the users who filed the issues this release's PRs closed) are
appended to the GitHub release notes automatically at publish time (see
[Release
Pipeline](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md#release-pipeline),
step 3).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: langchain-oss-automated-triage[bot] <248757908+langchain-oss-automated-triage[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

org:internal Issue or pull request created by a member of the `langchain-ai` GitHub organization. package:dcode Changes related to the `deepagents-code` terminal coding agent. size: XL Pull request with an extra-large diff. topic:performance Performance, resource usage, and cost optimization. type:bug An unexpected problem or incorrect behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant