Skip to content

fix: retry a live command result that is still being written - #788

Open
pcbeingused333 wants to merge 1 commit into
QuantConnect:masterfrom
pcbeingused333:fix/read-from-file-partial-json
Open

pcbeingused333 wants to merge 1 commit into
QuantConnect:masterfrom
pcbeingused333:fix/read-from-file-partial-json

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Fixes #784

Root cause: DockerManager.read_from_file stopped polling on any non-empty output and parsed the JSON after the loop. Lean writes the result file with File.WriteAllText, so a read that overlaps the write can see a prefix, which aborted the command with JSONDecodeError even though the full result would have been there within the timeout.

Fix: parse inside the polling loop. Incomplete JSON now goes through the existing error handling, which sleeps for interval and reads again, bounded by timeout. A complete result is still returned immediately and clears any earlier transient error. A file that stays invalid until the timeout returns a failed result with the parse error instead of raising.

Tests: two tests for a partial read followed by the full result, and for a result that stays incomplete. Both fail before the change with JSONDecodeError and pass after; tests/components/docker/test_docker_manager.py and tests/commands/live pass.

This change was prepared with AI assistance.

read_from_file stopped polling on any non-empty output and parsed it after
the loop, so reading a result file while Lean was writing it raised
JSONDecodeError. Parse inside the loop and read again until the timeout.
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.

A partially written live command result aborts polling with JSONDecodeError

1 participant