Skip to content

fix: preserve sibling Runs and stream parallel tool calls - #47

Merged
oakimov merged 3 commits into
oakimov:mainfrom
moritzWa:fix/ping-failure-keeps-sibling-runs
Oct 8, 2026
Merged

oakimov merged 3 commits into
oakimov:mainfrom
moritzWa:fix/ping-failure-keeps-sibling-runs

Conversation

@moritzWa

@moritzWa moritzWa commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

A failed reuse ping must retire the shared HTTP/2 connection with close() so sibling Runs can finish. Separately, finishing the provider step after the first Cursor tool call serializes calls from the same generation. Emit each tool on arrival and defer the OpenCode step boundary using Cursor's listed call count, with an idle fallback.

The implementation preserves late frames across timeouts, counts internal/refused calls correctly, and avoids replay after host tool emission. It includes streamed-edit, display-mirror and terminal regressions, plus sibling-stream tests on Node and Bun. Recent-traffic ping suppression and its cancellation/retry behavior are tracked separately in tasks/todo.md.

Validation: 1,442 tests pass; strict typecheck, build and architecture/package checks pass. A built-provider AI SDK probe verifies three overlapping tool executions in one step. Full live Cursor/OpenCode acceptance remains pending.

Related to #44.

getSession() destroyed the cached HTTP/2 session when its health-check
ping failed or timed out. Every other Run multiplexed on that session was
aborted mid-stream, and because those Runs had already produced output,
pumpWithRecovery refused to replay them ("automatic retry unsafe").

Retire the session the same way GOAWAY and age rotation do: drop it from
the cache and close() it so in-flight streams drain, while the new Run
opens a fresh connection.
@oakimov

oakimov commented Oct 7, 2026

Copy link
Copy Markdown
Owner

CONTRIBUTING checklist

Per CONTRIBUTING.md:

  • PR freeze — this repository is temporarily not accepting public PRs; only invited collaborators can open pull requests. Please use Discussions → Ideas or Issues unless you are invited.
  • OpenCode 1.x and 2.0 — note that the transport fix was considered for both (or is host-agnostic), even briefly.
  • Prompt-cache confirmation — confirm RequestContext / checkpoint continuity stays warm on surviving sibling Runs (cache diagnosis: / docs/cache-log-runbook.md).

Problem statement, fix, test, and CHANGELOG are otherwise in good shape. This PR is not being closed.

@nkoynov

nkoynov commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for this fix! It's merged in our fork as nkoynov@d1691d6, with a small follow-up so that a Run Cursor cancels on the retired connection isn't mistaken for a lost connection by our ping-skip resend under Bun.

Merge current main and retain the reviewed CLI-based implementation.
Keep sibling Runs alive on failed reuse pings, group streamed calls by
Cursor's generation count, and preserve frame and replay safety.

Add pump and Node/Bun transport regressions and track separate evaluation
of recent-traffic ping suppression and cancellation-aware retries.
@oakimov oakimov changed the title fix(transport): keep sibling Runs alive when a cached session ping fails fix: preserve sibling Runs and stream parallel tool calls Oct 7, 2026
@oakimov

oakimov commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Thanks @moritzWa for opening this PR and providing the reproduction. I've updated the branch with our reviewed implementation: failed reuse pings retire the shared connection with close(), allowing sibling Runs to drain.

The update also follows Cursor CLI's fire-on-arrival execution: emit tools as they arrive, then finish the OpenCode step when Cursor's listed call count is satisfied, with an idle fallback. Regression fixes cover late frames, internal/refused-call accounting, and terminal handling without replaying already-started host tools.

Validation: 1,442 tests pass, strict typecheck/build pass, and Node/Bun transport regressions cover refused, timed-out, callback-error and throwing pings. The built-provider AI SDK probe starts three tools concurrently before finish and joins all three results in one step. Full live Cursor/OpenCode acceptance remains pending. Could you please retest your multi-chat reproduction and parallel tool/subagent calls on this updated branch?

@nkoynov, thanks for identifying the retired-connection cancellation case under Bun. The recent-traffic ping optimization and its cancellation/retry behavior are worth investigating separately. I've added that evaluation to tasks/todo.md, including performance measurements, Node/Bun cancellation tests and replay safety; it isn't included in this fix.

@oakimov
oakimov merged commit 60b98d9 into oakimov:main Oct 8, 2026
1 check passed
oakimov added a commit to nkoynov/cursor-opencode-provider that referenced this pull request Oct 8, 2026
@moritzWa

Copy link
Copy Markdown
Contributor Author

Thanks @oakimov, retested current main (ddb14a1) in a separate macOS 26 Cua VM with OpenCode 1.18.16 and composer-2.5.

  • Two simultaneous chats both completed, with their shell work overlapping by about 5 seconds.
  • Parallel tools worked: the first call ran separately before capability discovery, then the remaining two were emitted in the same step and overlapped for 4 seconds.
  • Two general subagents both completed, with their shell work overlapping by 3 seconds.
  • Focused session/ping/parallel regressions: 74 passed, 0 failed. Node HTTP/2 cleanup and ping retirement also passed all four failure modes.

Checked actual tool output, exit codes and timestamps rather than just the final model responses. No failures in those live concurrency cases. I did not inject failed reuse pings into the live Cursor connection or verify warm-cache continuity across retirement; those failure modes were covered by the deterministic Bun/Node tests.

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.

3 participants