Delivery issue409 - #411
Merged
Merged
Conversation
Early-return command dispatches (/memory, /trust, /goal non-kick) wrote their parts and returned without ever entering the session runner, so the busy→idle status transition never fired and the run CLI — which exits its event loop only on the idle event — hung forever (#409). The response parts also lacked time.end, which run mode requires before printing text. Run the early-return writes as a micro-turn via SessionRunState.startIfIdle (idle sessions get the busy→idle transition; busy sessions keep today's inline semantics so the /goal busy guards still read true status), and stamp time {start,end} on the response parts. Goal kick dispatch stays outside the turn: its guards read the live session status. Regression: test/cli/run/early-return-command.test.ts (4 arms, all exit 0 with non-empty output).
LeXwDeX
marked this pull request as ready for review
August 21, 2026 01:08
3 tasks
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.
Closes #409
Why
opencode run "/memory"(andrun --command memory) hung forever with zero output, while the same command via servePOST /session/:id/commandreturned instantly. Early-return command dispatches (/memory,/trust,/goalnon-kick atpackages/opencode/src/session/prompt.ts) write a user message + text parts and return WITHOUT entering the session runner. The run CLI exits its event loop only on thesession.status {type:"idle"}event (run.ts), which only the runner's onIdle publishes — so these commands never emitted it. Secondary: run mode prints text parts only whentime.endis set; the early-return response parts carried notime, so output would have been empty even without the hang.What changed
packages/opencode/src/session/prompt.ts: newcommandTurnhelper runs the early-return writes as a micro-turn viaSessionRunState.startIfIdle— idle sessions get the real busy→idle transition (idle event fires, run mode exits); busy sessions keep today's inline semantics (no queueing, no duplicate idle), preserving the/goalbusy guards./memory,/trust, and/goal//subgoalnon-kick branches now wrap their message/part writes incommandTurn; response parts carrytime: { start, end }so run-mode consumers print them.loop()as before.Evidence
packages/opencode/test/cli/run/early-return-command.test.ts(4 arms:run "/memory",run --command memory,run --command trust status,run "/goal"): RED before fix (30s spawn-timeout kill, exit ≠ 0), GREEN after (all exit 0, non-empty stdout, ~1.3s each).headless-init.test.ts(fix: headless init does not stamp project time_initialized so memory stays inert #404, 4/4),goal.test.ts+workspace-trust.test.ts+dag-goal-wake-retrigger.test.ts(50/50),prompt.test.ts+httpapi-memory-wiring.test.ts(78 pass),bun run test:dag-coregate passed.bun typecheck(packages/opencode) and repobun run lintratchet clean (4837 ≤ 4850).Checklist
specgit finishexits 0.