[OPIK-5282] [SDK] feat: capture runner job stdout/stderr and stream to backend#5976
Merged
petrotiurin merged 6 commits intomainfrom Mar 31, 2026
Merged
Conversation
…vate_runner Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…o backend Add per-job log capture for the Python runner, matching TypeScript behavior. Uses contextvars to track which job owns each print() call, and an async LogStreamer to send logs to the backend without blocking execution. - context.py: ContextVar for per-job ID tracking - log_streamer.py: async task that intercepts stdout/stderr, batches entries, and sends via append_job_logs - in_process_loop.py: propagates context to executor threads via contextvars.copy_context().run() - prefixed_output.py: replace TTY guard with idempotency flag - e2e + unit tests for log capture pipeline Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
f0ffa1e to
9bb6048
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Graceful LogStreamer shutdown: cancel and await task before closing loop - Guard _CaptureStream.write against closed event loop - Restore signal handlers in test_activate fixture Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Details
Python runner was not capturing or sending stdout/stderr from agent job executions to the backend. This adds per-job log capture matching the TypeScript runner behavior.
Uses
contextvars.ContextVarto track which job owns eachprint()call across concurrent executions, and an asyncLogStreamertask that intercepts stdout/stderr writes, batches log entries per-job, and sends them to the backend viaappend_job_logswithout blocking agent execution.Key changes:
context.py: newContextVarfor per-job ID trackinglog_streamer.py:_CaptureStreamwraps stdout/stderr to intercept writes; async task batches and sends viarun_in_executorin_process_loop.py: sets job context before execution, propagates to executor threads viacontextvars.copy_context().run()prefixed_output.py: replace TTY guard with idempotency flag (TTY guard prevented capture in subprocess/CI environments)Change checklist
Issues
AI-WATERMARK
AI-WATERMARK: yes
Testing
python -m pytest tests/unit/runner/ -xvs(36 passed)python -m pytest tests/e2e/runner/test_runner_e2e.py::test_runner_happy_path -xvs(1 passed — verifies logs appear viaget_job_logsAPI after job completion)422: text must not be blankerror from whitespace-only writes is filtered outDocumentation
N/A