Repository navigation
fix(agents): opencode runs as many turns as memory fits, and takes its system prompt as instructions - #372
Merged
Conversation
…s system prompt as instructions Each `opencode run` peaks near 900 MB, so a modal_vm (8 GB, no swap) running every concurrent turn at once ran out of memory, and its kernel killed one: "opencode exited with code -9", which failed the A2A validator's mcp probe on whichever turn it hit. Turns past the cap (memory, or the cgroup's limit, past 1 GB, at 900 MB a turn; OPENCODE_MAX_CONCURRENT_TURNS sets it) now wait for one to finish. A system prompt prepended to the message read as the user's own words: the validator's "respond with this token" system prompt, still set when its snapshot probe planted a token, made the model take the planted turn for a prompt injection and refuse to recall it. It's now written to the context's data directory and named in the config's `instructions`, which opencode puts in the system message. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
opencode-cli failed AgentEnvHub's dev promotion gate for 0.9.1373 on
mcpandsnapshot, and the gate restored its previous image. This fixes both, in the opencode agent:opencode runprocesses run at once than the machine's memory fits: one per 900 MB past the first 1 GB, using the cgroup's limit when that's lower. That's 7 on an 8 GB modal_vm.OPENCODE_MAX_CONCURRENT_TURNSsets the number. Turns past the cap wait for one to finish.system-prompt.mdin the conversation's data directory and named in the config'sinstructions. Before, it was prepended to the message.Why
mcp: the VM ran out of memory. In the gate run (dev instanceopencode-cli__validate-a2a-v16-7lsevzc4) the MCP probe failed with"agent_response": "opencode exited with code -9 without completing", and it called no tools.opencode runpeaked at 600–860 MB, used memory reached 7,743 MB, and the kernel log showsOut of memory: Killed process … (opencode)four times.snapshot: the model refused to recall. Save, load and resume all worked, and the recall turn resumed the same session.Testing
tst/unit/agents/opencodepasses (96 passed, 7 skipped). New tests:instructionsfile and not in the message;agentenv-opencodeimage, against a local stand-in for the model endpoint that records each request. Withinstructions: ["/tmp/system-prompt.md"], the system message carriesInstructions from: /tmp/system-prompt.mdfollowed by the file's text, and the user message carries only the user's words.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge, with no actionable findings.Summary
The PR limits concurrent OpenCode turns based on available memory and passes system prompts through instruction files.
Known tradeoff: earakely-scale noted that queued turns can hit the validator’s 120-second timeout.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Task arrives] --> B[Acquire workspace access and context lock] B --> C[Prepare attachments] C --> D[Wait for a turn slot] D --> E[Write system prompt file if supplied] E --> F[Run OpenCode with instructions config] F --> G[Finish or clean up canceled CLI] G --> H[Release turn slot] H --> I[Save session reference and capture changes]Reviews (1) · Last reviewed commit: "fix(agents): opencode runs as many turns..." · Reviewed by Greptile