A partially written live command result aborts polling with JSONDecodeError

Open Beginner friendly
#784 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@pcbeingused333 is already working on this.

Since Nov 26, 2026.

  • #788 by @pcbeingused333 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
docker, python
Domain
cli

Research direction

Start in lean/components/docker/docker_manager.py at read_from_file: move the json.loads(output) inside the polling loop so an incomplete payload is retried rather than aborting, while a complete result still returns on the first read. Reproduce first with the mocked subprocess returning b'{"Success":' and then full JSON, as in the issue's reproduction, and check the existing docker manager tests for the polling helpers to extend. Done means the incomplete-read case returns the later complete result within the timeout and still fails cleanly once the window expires; the Lean-side producer Common/Commands/FileCommandHandler.cs is context, not a file to change here.

Written by the indexing model from the issue text.

Description

priority:P2

Problem

DockerManager.read_from_file stops polling on any nonempty output and only parses JSON afterward. Lean's FileCommandHandler.Acknowledge writes result files using File.WriteAllText, so a read overlapping that write can observe a nonempty prefix and abort with JSONDecodeError, even if the full successful result becomes available within the timeout.

Reproduction

On current master, mock a running container and a subprocess whose stdout.read() returns b'{"Success":'. Call read_from_file('container', Path('result.json'), interval=0.01, timeout=0.1).

Observed: JSONDecodeError: Expecting value: line 1 column 12 (char 11) after the first read, instead of retrying. Returning complete JSON on the next attempt cannot help because the polling loop has already ended.

Relevant code: lean/components/docker/docker_manager.py, the nonempty-output check and subsequent loads(output) in read_from_file; producer: Common/Commands/FileCommandHandler.cs in Lean.

Required result

A result observed during an incomplete write must not abort a command that completes within its wait window. Preserve immediate handling of a complete result and bound retries for an incomplete result. Suggestion: parse inside the polling loop and retry incomplete JSON, or make the producer publish complete files atomically.

Dominant language
Python
Stars
335
Forks
172
Avg merge
6h 54m
Merged PRs (30d)
37

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from QuantConnect/lean-cli

All issues in QuantConnect/lean-cli

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.