Skip to content

fix: Propagates live_print_scope to shell message_callbacks#20

Merged
EspenAlbert merged 2 commits into
mainfrom
t11-35-propagate-live-print_scope-to-shell-stream-callbacks
Jun 1, 2026
Merged

fix: Propagates live_print_scope to shell message_callbacks#20
EspenAlbert merged 2 commits into
mainfrom
t11-35-propagate-live-print_scope-to-shell-stream-callbacks

Conversation

@EspenAlbert
Copy link
Copy Markdown
Owner

@EspenAlbert EspenAlbert commented Jun 1, 2026

Summary

Fixes live_print_scope not reaching message_callbacks because shell streaming runs on pool threads without the caller's contextvars.

What changed

  • ShellRun captures contextvars.copy_context() at construction.
  • Queue consumer dispatches _on_event inside that snapshot so callbacks (and print_to_live from them) see the caller's scope.
  • Docs: run_and_wait / message_callbacks propagation and snapshot semantics.

Reviewer notes

  • Not breaking; unset context behaves as before.
  • Snapshot at ShellRun creation is intentional: scope is fixed for the run (including retries), not updated mid-flight.
  • ShellRunBefore still runs outside the snapshot on the _execute_run thread; only queue-driven callbacks are in scope (matches tfdo stream-handler path).
  • Follow-up (tfdo): explicit [run_dir_key] prefixes in apply renderers can stay as defense-in-depth; orchestration may restore live_print_scope for non-renderer paths once this ships.

Test plan

  • just pre-commit-ask
  • Callback sees prefix under live_print_scope at run_and_wait time
  • Nested scope: inner prefix wins at construction

@EspenAlbert EspenAlbert changed the title todo update me with the PR title for branch t11-35-propagate-live-print_scope-to-shell-stream-callbacks fix: Propagates live_print_scope to shell message_callbacks Jun 1, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.29%. Comparing base (87014ed) to head (4df8044).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #20      +/-   ##
==========================================
+ Coverage   86.27%   86.29%   +0.01%     
==========================================
  Files          22       22              
  Lines        2084     2087       +3     
==========================================
+ Hits         1798     1801       +3     
  Misses        286      286              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@EspenAlbert EspenAlbert marked this pull request as ready for review June 1, 2026 15:50
@EspenAlbert EspenAlbert merged commit a7b35aa into main Jun 1, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants