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
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 value in a narrowly scoped ensure after prerequisites have succeeded. Capture#run also stops mutating report_on_exception: that flag belongs to the thread owner, not cli-ui. WorkQueue now settles futures for non-StandardError task exceptions rather than letting them kill the worker. This prevents thread-death diagnostics from leaking over spinner output and prevents SpinGroup#wait from hanging forever on an incomplete future. Add regressions for nested IDs and captures, alternate-screen entry after a nested capture, exception-reporting ownership, and NotImplementedError handling in WorkQueue and SpinGroup. 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 14, 2026 20:46
7cd4cd5 to
7d6cf36
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 a separateWorkQueuebug: a non-StandardErrortask exception could kill its worker without settling the future, leavingSpinGroup#waitrunning forever.This PR restores routing state with narrowly scoped
ensureblocks, leaves exception-reporting policy to the thread owner, and makesWorkQueuesettle futures for non-StandardErrortask exceptions.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.WorkQueuecould abandon a future. Workers rescuedStandardErrorandInterrupt, but exceptions such asNotImplementedErrorare outsideStandardError. Such an exception killed the worker without completing or failing its future. With the oldreport_on_exceptionmutation this was a silent hang; without the mutation it was a hang accompanied by a thread-death backtrace over spinner output.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 its specialInterrupthandling, then catches otherExceptionsubclasses, fails the corresponding future, and keeps the worker available for subsequent work. The future carries the exception back to the caller instead of remaining incomplete.Normal, non-nested routing remains unchanged. Non-
StandardErrortask failures now reach callers through their future instead of killing a worker and deadlocking the spinner.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.NotImplementedErrorneither hangs nor emits a worker thread-death report.🤖 Updated by an LLM coding agent on behalf of Gord.