Restore shadowed routing state; settle worker failures - #627
Draft
GoodForOneFare wants to merge 1 commit into
Draft
Restore shadowed routing state; settle worker failures#627GoodForOneFare wants to merge 1 commit into
GoodForOneFare wants to merge 1 commit into
Conversation
GoodForOneFare
force-pushed
the
gordo-stdout-router-thread-local-restore
branch
from
August 14, 2026 19:13
efc5d78 to
7cd4cd5
Compare
GoodForOneFare
force-pushed
the
gordo-stdout-router-thread-local-restore
branch
from
August 14, 2026 20:46
7cd4cd5 to
7d6cf36
Compare
Capture#run and with_id hard-reset Thread.current routing state on exit instead of restoring the values they shadowed. A nested capture therefore left its still-active outer capture invisible, which could crash in_alternate_screen at current_capture!.stdout, while a nested output ID stripped the outer scope's labelling. Save and restore each routing value in a narrowly scoped ensure after prerequisites have succeeded. Capture#run also stops mutating report_on_exception: that flag belongs to the owner of a caller-provided thread, not cli-ui. WorkQueue now carries non-StandardError task failures through their futures, protects the dequeue-to-future handoff from asynchronous interruption, and settles an active future if its worker is killed. Workers unregister on exit and replace themselves while queued work remains, so a dead worker cannot strand already-enqueued tasks or retain a concurrency slot. wait follows replacement workers, while interrupt owns deliberate teardown without leaking worker diagnostics or replacing the caller's exception. SpinGroup stops its queue and sibling tasks before a non-StandardError failure escapes the render loop. Add regressions for nested routing state, alternate-screen entry, exception-reporting ownership, non-StandardError tasks, killed workers, task-raised interrupts, replacement workers, and sibling teardown. Co-authored-by: River <river@shopify.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Assisted-By: devx/24e11ae9-0556-4186-a8fe-69bb6bc342ff
GoodForOneFare
force-pushed
the
gordo-stdout-router-thread-local-restore
branch
from
August 17, 2026 14:07
7d6cf36 to
b8859db
Compare
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.
What
Capture#runandStdoutRouter.with_idhard-resetThread.currentrouting state on exit instead of restoring the values they shadowed.Capture#runalso changedThread#report_on_exceptionto hide spinner worker failures. Removing that suppression exposed deeperWorkQueuelifecycle bugs: some failures could abandon a future, kill a worker without replacing its concurrency slot, or leave sibling spinner tasks running afterSpinGroup#waitescaped.This PR restores routing state with narrowly scoped
ensureblocks, leaves exception-reporting policy to the owner of caller-provided threads, makes worker failures observable through futures, replaces failed workers while queued work remains, and tears down spinner siblings before propagating exceptional failures.The bugs
Capture#runpermanently disabledreport_on_exception. It setThread.current.report_on_exception = falsewith no restore. A caller-owned or reusable worker thread that ran a capture therefore stopped producing Ruby's diagnostic report for later unhandled thread exceptions.A nested capture lost the outer capture and could crash a prompt. The
ensurereset:cliui_current_capturetonilrather than the previous value. After an inner capture completed,Capture.in_alternate_screencould reachcurrent_capture!.stdoutwhilecurrent_capturewasnil, raisingNoMethodError. Every interactive prompt uses this alternate-screen path.A nested
with_idlost the outer ID. Itsensurereset:cliui_output_idtonil, so output in the remainder of the outer scope silently lost its[id]label.A worker failure could abandon futures and queued work. Workers rescued
StandardErrorandInterrupt, but exceptions such asNotImplementedErrorare outsideStandardError. Such an exception killed the worker without settling its future. A worker killed asynchronously could do the same, and dead workers remained in@workers, permanently occupying their concurrency slot. Withmax_concurrent: 1, work already queued behind a dead worker could therefore remain unrun forever.A propagated task failure left sibling work unattended. Once a non-
StandardErrorreachedSpinGroup#wait, it escaped mid-render without stopping the group or interrupting its queue, allowing sibling tasks to continue after nobody was watching the group.The fix
Capture#runsaves and restores:cliui_current_capture,:no_cliui_frame_inset, and:cliui_output_hookin local, narrowly scopedensureblocks. The saves occur only after prerequisites such asassert_enabled!have succeeded, avoiding the method-level-ensureclobbering window.with_idsimilarly restores the previous:cliui_output_id.Capture#runno longer reads or writesreport_on_exception; caller-owned captures retain the thread owner's setting.WorkQueuepreserves specialInterrupthandling and carries otherExceptionsubclasses back through their futures instead of letting them terminate a worker unnoticed.WorkQueue::WorkerDiedif its worker exits before settling it.waitfollows replacement workers, including replacements started after the queue has closed for draining.WorkQueue#interruptteardown is serialized, safely drains queued futures, suppresses diagnostics only on WorkQueue-owned threads being terminated, and does not let a worker'sInterruptreplace the caller's in-flight exception.SpinGroup#waitstops the group and its siblings before re-raising a non-StandardError. The exception still propagates to the caller.Normal, non-nested routing remains unchanged. Worker failures now settle their active future, and queued work either runs on a replacement worker or is failed during deliberate teardown.
Tests
with_idrestores the outer ID on both the normal and raising paths.report_on_exceptionuntouched in both thetrueandfalsestates.NotImplementedErrorfails itsWorkQueuefuture and the worker continues with later work.Interruptreplaces the dead worker and does not strand already-queued work.NotImplementedErrorneither hangs nor emits a worker thread-death report.StandardErrorstops the group and interrupts sibling tasks before escaping.🤖 Updated by an LLM coding agent on behalf of Gord.