test(opencode): add regression test for lost terminal-iteration wakeup - #1
Merged
Conversation
Cover the queued-work path repaired in anomalyco#36375 (refs anomalyco#35066). When a background subagent notifies the parent by calling ensureRunning while the parent turn is still running, the runner must queue that work and cycle Running -> RunningThenRun -> Running for every arrival instead of dropping it. Exercise two back-to-back notifications so the runner re-enters RunningThenRun a second time after the first queued run is promoted. Without the fix the runner never enters RunningThenRun, so the queued wakeup is lost: the test fails (waitForState times out) on the pre-fix runner.ts and passes with the fix in place.
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 freeto 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.
Your fix in
is the right root-cause repair: adding the
RunningThenRunstate soensureRunningqueues new work instead of discarding it while the runner is alreadyRunningis exactly what stops a background-subagent notification from being lost. This PR adds only one regression test on top of your branch — no production changes.Your tests already cover a single queued run: queuing behind a running turn, the
RunningThenRuntransition, and a third caller sharing the pending run. What none of them exercise is a repeated re-queue — a second notification that arrives after the first queued run has already been promoted toRunning, forcing the runner to cycleRunning → RunningThenRun → Running → RunningThenRun → Running. That's the real-world case of a parent session getting several background-subagent wakeups over its lifetime, so it's worth locking down.The new test
re-queues each run that arrives after the previous queued run is promoted(inpackages/opencode/test/effect/runner.test.ts):Running;RunningThenRun;Running;RunningThenRuna second time;parent,notify-a,notify-b), the work ran in order, and — via a flag A sets on completion that B reads at its start — that B was promoted only after A completed (serialization, not just start-ordering), ending back atIdle.It synchronizes only on published state via
waitForState, with no fixed sleeps, per the package's test-synchronization guidance.The test fails on the pre-fix runner and passes with your fix. With the fix present:
The full
runner.test.tsfile is29 pass, 0 fail, andtsgo --noEmit,prettier --check, andoxlintare clean.With only
packages/opencode/src/effect/runner.tsreverted to its pre-fix parent (the test left unchanged):Pre-fix the runner never reaches
RunningThenRunbecause the queued work is dropped, sowaitForState(runner, "RunningThenRun")times out — confirming the test guards the behavior your fix restores rather than passing vacuously.