Skip to content

Report Docker's diagnostic when writing to a container file fails - #775

Merged
quantconnect-kronos[bot] merged 1 commit into
masterfrom
kronos/bug-745-docker-write-diagnostic
Nov 23, 2026
Merged

quantconnect-kronos[bot] merged 1 commit into
masterfrom
kronos/bug-745-docker-write-diagnostic

Conversation

@quantconnect-kronos

Copy link
Copy Markdown
Contributor

Closes #745

DockerManager.write_to_file ran docker exec without capturing its output. When the command failed, CalledProcessError.output was None and the handler's .decode() raised AttributeError: 'NoneType' object has no attribute 'decode', which hid the intended ValueError.

The docker exec call now captures its output, and the message is built from stderr and stdout, with either one allowed to be empty or None. The fix is the commit from #758 by @pcbeingused333, cherry-picked with its authorship kept.

The only change in behavior is on failure: the ValueError is raised as intended and includes Docker's diagnostic, which before went straight to the terminal. Successful writes work as before.

Testing

  • Two new tests in tests/components/docker/test_docker_manager.py cover a failure with no output and a failure with a Docker diagnostic. Both fail on master (the AttributeError) and pass with the change.
  • python -m pytest -s -rs: 2908 passed, 81 skipped.
  • python static_analysis.py: BUILD PASSED. Its 5 unused-import warnings are not in the changed files.
  • Tested end to end against a real running container, with a write to a path whose directory doesn't exist:
    • with the change: ValueError: Failed to write to command.json: bash: line 1: /missing/dir/command.json: No such file or directory
    • on master: AttributeError: 'NoneType' object has no attribute 'decode'

write_to_file ran docker exec without capturing output, so CalledProcessError.output was None and the handler raised AttributeError instead of the intended ValueError. Capture the output and build the message from stderr/stdout, tolerating empty values.
@quantconnect-kronos quantconnect-kronos Bot added kronos:develop:working develop: in progress kronos:review Request review labels Nov 23, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued kronos:review:working review: in progress and removed kronos:review Request review kronos:review:queued review: queued labels Nov 23, 2026
@quantconnect-kronos-reviewer
quantconnect-kronos-reviewer Bot marked this pull request as ready for review November 23, 2026 14:20

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. A failed docker exec in write_to_file now raises the intended ValueError with Docker's diagnostic, instead of an AttributeError. That is what #745 asks for. Successful writes work as before, and the one caller (send_command in lean/commands/live/live.py) still gets a ValueError, as it did before.

Verified: both new tests fail on master and pass on this commit. A write to a missing directory in a real running container gives ValueError: Failed to write to command.json: bash: line 1: /missing/dir/command.json: No such file or directory, and a payload containing quotes and $ is still written literally.

Label risk:low: a small, easily reverted change that only affects the error path, with tests, green CI and an end-to-end run.

Once this merges, #758 (the original of this commit) can be closed.

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added risk:low Low risk and removed kronos:review:working review: in progress labels Nov 23, 2026
@quantconnect-kronos quantconnect-kronos Bot added the kronos:review Request review label Nov 23, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued and removed kronos:review Request review labels Nov 23, 2026
@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot added kronos:review:working review: in progress and removed kronos:review:queued review: queued labels Nov 23, 2026

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved; no blocking findings.

Independent verification:

  • python -m pytest -q -rs: 2,908 passed, 81 skipped. Both new regression tests fail with the base implementation and pass with this fix.
  • python static_analysis.py: passed, with five existing unused-import warnings outside the changed files.
  • Tested end to end: lean live command Sample --data '{}', with a forced container-file write failure, exits 1 and reports Failed to write to command-….json with Bash's diagnostic, without the NoneType error.
  • Real Docker comparison: writing to a missing directory raises ValueError with the diagnostic on this commit versus AttributeError on the base. Successful writes preserve the exact payload and filename on both, including apostrophes, dollar signs, backticks and backslashes.
  • Six additional output cases pass: absent streams, empty streams, stdout only, stderr only, both streams, and invalid UTF-8.

The change stays within #745 and leaves successful command submission unchanged.

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot removed the kronos:review:working review: in progress label Nov 23, 2026
@quantconnect-kronos
quantconnect-kronos Bot merged commit 508863e into master Nov 23, 2026
60 checks passed
@quantconnect-kronos
quantconnect-kronos Bot deleted the kronos/bug-745-docker-write-diagnostic branch November 23, 2026 14:36
@quantconnect-kronos quantconnect-kronos Bot removed the kronos:develop:working develop: in progress label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Low risk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker command write failures are masked by an AttributeError

1 participant