Skip to content

fix(sandbox): devops sandbox logs reads each line with its stream from a real engine - #2546

Merged
dan-petty merged 4 commits into
mainfrom
fix/2520-sandbox-logs-streams
Oct 28, 2026
Merged

dan-petty merged 4 commits into
mainfrom
fix/2520-sandbox-logs-streams

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

devops sandbox logs failed on every real Docker engine. DockerEngineService.container_log_stream called container.logs(..., demux=True), and the docker SDK's logs has no demux argument (docker 7.2.0: ContainerApiMixin.logs(self, container, stdout=True, stderr=True, stream=False, timestamps=False, tail='all', since=None, follow=None, until=None)). Each call raised TypeError, which the service reported as "Container log stream failed". The tests did not see it, because they gave the service a mock client that took any argument.

  • container_log_frames in src/devops_cli/docker/engine.py reads GET /containers/{id}/logs through the SDK client's own session (client.api.get, with base_url, api_version and timeout), with the query that the SDK's logs sends: stdout, stderr, timestamps, follow and tail. It gives each frame as (stdout, stderr) bytes, in the order of the reply. The SDK's docker.utils.socket.demux_adaptor names the stream of each multiplexed frame, and a container with a TTY gives its one raw stream on stdout. A refused request raises the SDK's own error (create_api_error_from_http_exception), and a followed log has no read timeout, as the SDK's own followed log has none. container_log_stream calls it, and EngineApi in docker/sdk.py names the session's parts that it uses.
  • The SDK's logs and both of its log helpers drop the stream number of each frame header, so no SDK call keeps the two streams apart. The change adds one loop of about ten lines that reads each 8-byte frame header (the "Stream format" of the Engine API reference). Its written cost, and the rejected options (attach(logs=True, demux=True), two logs calls, the SDK's private helpers, frames_iter, python-on-whales, podman-py) with their evidence, are in the archived change.
  • The Docker engine fake answers the same request from a container's scripted frames, with tail and timestamps, and keeps Config.Tty as an engine does. A new contract scenario, log_frames_keep_their_stream, recorded from Docker Engine 29.9.2 (API 1.56), holds the fake and the SDK client to the same lines with tail, timestamps, follow and a TTY. The recordings of the other scenarios do not change.
  • The sandbox log tests in tests/test_sandbox_logs.py read the logs over the fake and give up their mock clients.

Closes #2520

Change: openspec/changes/archive/2026-10-28-2520-sandbox-logs-streams/

@dan-petty

Copy link
Copy Markdown
Owner Author

Test evidence:

  • uv run devops ci fail-to-pass --base origin/main: 5 failed on base, 40 passed (tests/docker/test_engine_contract.py, tests/test_sandbox_logs.py).
    • test_engine_logs_success, test_engine_logs_generator_stream, test_engine_logs_demux_stream_preservation and test_engine_logs_follow_bounded_buffer failed with DockerEngineError: Container log stream failed: ContainerApiMixin.logs() got an unexpected keyword argument 'demux', the defect of the issue, now that the fake refuses demux as the SDK does.
    • test_the_fake_answers_each_scenario_as_the_recorded_engine[log_frames_keep_their_stream] failed with ImportError: cannot import name 'container_log_frames'.
  • On the branch, after the rebase onto origin/main: 331 passed in tests/docker/, tests/test_docker_engine.py, tests/test_sandbox_logs.py, tests/test_sandbox_lifecycle.py and tests/test_workload_sandbox.py. mypy on src/devops_cli/docker/ and src/devops_cli/sandbox/ passes, and the pre-commit hooks pass on every changed file.
  • Recording: only the new scenario was recorded, from the local Docker Engine 29.9.2 (API 1.56), the engine of the existing record, with tests.support.docker_engine_recording._record_scenario. The record of the other scenarios is unchanged (the fixture's diff has additions only). The scenario removed its two containers, and the engine holds no devops-contract object.

Pending a person:

  • Run devops sandbox logs <sandbox> on a running sandbox, and see its stdout and stderr lines.
  • Review the diff in tuicr (tuicr -r origin/main..HEAD).

…m a real engine

`DockerEngineService.container_log_stream` called `container.logs(...,
demux=True)`. The docker SDK's `logs` has no `demux` argument, so each
call raised `TypeError`, and `devops sandbox logs` failed with
"Container log stream failed" on every real engine.

The service now reads `GET /containers/{id}/logs` through the SDK
client's own session, with the query that the SDK's `logs` sends, and
gives each frame as `(stdout, stderr)` bytes in the order of the reply.
The SDK's `demux_adaptor` names the stream of each multiplexed frame,
and a container with a TTY gives one raw stream on stdout. The SDK's
`logs` drops the stream of each frame, so no SDK call keeps the two
streams apart.

The Docker engine fake serves the same read from a container's
scripted frames, a contract scenario recorded from Docker Engine
29.9.2 holds the fake and the SDK client to the same lines, and the
sandbox log tests run on the fake instead of mock clients.
…with no new type ignore

deptry refuses `requests` as a direct import, since only docker-py depends on it, so the log read catches the HTTPError of a refused reply as an Exception and gives it to the SDK's `create_api_error_from_http_exception`. The demux helper comes from `docker.utils`, whose missing-stub ignore the file already holds, so the count of type ignores in src stays at its ceiling.
@dan-petty
dan-petty force-pushed the fix/2520-sandbox-logs-streams branch from f6f498c to 568b571 Compare October 28, 2026 21:38
…ner and gets the engine's 404

The read of a removed container's log goes through the refused-reply branch of container_log_frames over the docker SDK client and the engine's recorded 404, and over the fake. Only the log_frames_keep_their_stream scenario is recorded again, from the same Docker Engine 29.9.2.
@dan-petty
dan-petty force-pushed the fix/2520-sandbox-logs-streams branch from 568b571 to 505dd23 Compare October 28, 2026 21:47
@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 21:54
@dan-petty
dan-petty merged commit e7216d5 into main Oct 28, 2026
17 checks passed
@dan-petty
dan-petty deleted the fix/2520-sandbox-logs-streams branch October 28, 2026 21:54
dan-petty pushed a commit that referenced this pull request Oct 29, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.12.0](v0.11.3...v0.12.0)
(2026-10-29)


### Features

* **ai:** constrain structured replies on the openai and claude
providers ([#2550](#2550))
([4f7390a](4f7390a))
* **argo:** retire the Helm release records of the charts that Argo CD
renders ([#2568](#2568))
([cabfcd4](cabfcd4))
* **k8s:** devops k8s tunnel keeps the cloudflared forward to
k8s.&lt;domain&gt; running
([#2567](#2567))
([f9493fa](f9493fa)),
closes [#1641](#1641)
* **monitoring:** alert when the otel collector fails to export spans,
metric points or log records
([#2565](#2565))
([4fc8ff7](4fc8ff7))
* **telemetry:** the roadmap Service counts its GitHub writes, budget
holds, Firecrawl searches and own deliveries, and caps refine's comments
on one item
([#2556](#2556))
([9819877](9819877)),
closes [#2475](#2475)


### Bug Fixes

* **git:** report a worktree that a run in parallel removed as removed,
not a failed reclaim
([#2557](#2557))
([a556984](a556984)),
closes [#2408](#2408)
* **k8s:** the devops perimeter opens only the collector's OTLP/HTTP
port, 4318
([#2549](#2549))
([d156ce7](d156ce7))
* **sandbox:** devops sandbox logs reads each line with its stream from
a real engine
([#2546](#2546))
([e7216d5](e7216d5)),
closes [#2520](#2520)
* **service:** the webhook route refuses an unsigned or oversized
delivery before it reads the body, and a rate limit guards it
([#2553](#2553))
([40efcd4](40efcd4)),
closes [#2476](#2476)


### Performance Improvements

* **ai:** price a request with one load of the settings
([#2555](#2555))
([5d86538](5d86538)),
closes [#1420](#1420)


### Code Refactoring

* **config:** a default that backs a settings field is read only through
the settings
([#2561](#2561))
([0702d13](0702d13))
* **exceptions:** each exception class declares its error_code and
exit_code ([#2558](#2558))
([410dece](410dece))
* **review:** render the review report from one input, outside the
orchestrator
([#2563](#2563))
([9e73e6d](9e73e6d)),
closes [#1008](#1008)
* **security:** src has no unreviewed Bandit findings, and the gate
scans src at low severity
([#2560](#2560))
([45261dd](45261dd)),
closes [#1538](#1538)
* **security:** the scanners stop looking for mocks, and their tests run
on the scanner fake
([#2551](#2551))
([2b7f37a](2b7f37a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
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.

fix(sandbox): devops sandbox logs fails on a real Docker engine because the docker SDK's logs call takes no demux argument

1 participant