Skip to content

fix: reap turns parked only on StructuredOutput - #22

Open
karimodm wants to merge 1 commit into
openchamber:mainfrom
karimodm:fix/reap-structured-output-park
Open

karimodm wants to merge 1 commit into
openchamber:mainfrom
karimodm:fix/reap-structured-output-park

Conversation

@karimodm

Copy link
Copy Markdown

When OpenCode runs a structured-output request (a JSON-schema format, as used by memory plugins like opencode-mem), it injects a StructuredOutput tool. It ends the request as soon as the model calls that tool, and it never sends a tool result back. On claude-code/* the bridge parks on that call, waiting for a result that never arrives. Its Claude Code process stays alive until the whole server restarts.

We hit this with opencode-mem: every memory capture left one claude process behind. After a day we had dozens of idle CLIs under opencode serve, and the machine was swapping.

Fix: when a turn parks and every pending tool is StructuredOutput, schedule a reaper. If the same calls are still pending after the grace period, the reaper closes the bridge with deleteBridge. The default grace period is 60s, adjustable with OPENCODE_CLAUDE_STRUCTURED_OUTPUT_REAP_MS. Turns parked on any other tool are not affected. If OpenCode does send a result within the grace period, the normal resume path runs and the reaper does nothing.

Test: test/structured-output-reap-regression.ts uses a mock SDK turn that calls a bridged tool through the real MCP server and then waits. A StructuredOutput park gets closed; on main it isn't, and the test fails. A bash park stays open. bun test/smoke.ts and tsc --noEmit pass.

Related but out of scope: other abandoned parks (a user starts a new session instead of answering) also stay alive until the server restarts. A general idle-park TTL might be worth adding separately.

OpenCode treats a StructuredOutput call as the end of the request and
never sends a tool result back, so the parked bridge was never resumed
and its Claude Code process leaked, one per structured request. Close
the bridge when nothing resumed it within a grace period (60s, override
with OPENCODE_CLAUDE_STRUCTURED_OUTPUT_REAP_MS).
JosueGalRe added a commit to JosueGalRe/opencode-claude that referenced this pull request Sep 22, 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.

1 participant