Skip to content

fix(lifecycle): keep failed commands' output, cap it at 1024 lines, pass false parameters - #162

Merged
masonng-astro merged 5 commits into
mainfrom
fix/runner-output-and-false-parameters
Nov 1, 2026
Merged

masonng-astro merged 5 commits into
mainfrom
fix/runner-output-and-false-parameters

Conversation

@chitrangpatel

@chitrangpatel chitrangpatel commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Why

Runner bugs, and the size of saved output, found while running the baseband localization pipeline on CANFAR through static configs (CHIMEFRB/baseband-analysis#661):

  1. A failed command saves no output. execute.command called process.check_returncode() before storing stdout and stderr, so when a command exits non-zero its Work has no output, only the logged CalledProcessError. Those are the runs where the output is needed most. The same happened when a command hit its timeout.
  2. Parameters that are false never reach a click command. configure.arguments skipped every falsy value (if parameter_value_in_work:), so False, 0 and "" were silently replaced by the command's defaults. On/off flags couldn't be turned off: trace: false for a --trace/--no-trace option (default on) still ran with tracing. The runner also only ever passed a flag's "on" name.
  3. All of a command's output is saved in the database. stdout and stderr go into the Work's results, so into Buckets and Results (MongoDB), which keep them with no retention. One baseband localization Work holds about 3 MB of output, mostly on stderr (Python logging writes there by default).
  4. Spinner frames fill the logs of headless runs. workflow run forced its spinner on (Console(force_terminal=True)) even without a terminal, slowed to 1 frame/s, so every frame went into the container's logs for the whole run: 5,209 frames in one localization's saved step logs, each on its own line.

What

  • execute.command stores the output in the Work's results (new output() helper) before checking the return code. A failed command is still marked failure, now with its stdout, stderr and returncode. A command stopped by its timeout keeps what it printed before it was killed, with returncode: None.
  • Only the last 1024 lines of stdout and of stderr are kept (OUTPUT_LINES). That still includes a failure's traceback, and the last line of stdout, which results are read from.
  • configure.arguments only leaves a parameter to its default when it's missing (None). A flag set to False is passed by its secondary name (--no-trace) when it has one, and left off otherwise. 0 and "" are passed as values.
  • workflow run only shows the spinner when stdout or stderr is a terminal.

Tests

tests/test_run.py::test_run_without_a_terminal_writes_no_spinner runs workflow run without a terminal (backends, workspace and lifecycle stubbed) and checks that no spinner frames are written; it fails without the fix.

tests/test_lifecycle.py:

  • a command that succeeds, fails (exit 3) and times out keeps its stdout/stderr;
  • a command printing 3000 lines to each stream keeps the last 1024 lines of each;
  • trace: false → --no-trace, trace: true → --trace, a plain flag set to False is left off, 0 and "" are passed, None falls back to the default, and click parses them back to the values given.

All lifecycle tests and the new run test pass, and pre-commit passes. tests/test_run.py::test_complete_work_run and tests/test_cli.py::TestWorkspaceCLI::test_workflow_buckets_cli fail locally on main too (they need local Buckets/Results servers).

Notes

  • configure.defaults() has the same falsy handling but isn't called anywhere, so it's left as is.
  • validate.size measures sys.getsizeof(work.results), which is only the dict's own size, not its contents, so the 4 MB check never triggers. Not changed here.
  • Pipelines pick these up when their images are rebuilt with the release.

🤖 Generated with Claude Code

chitrangpatel and others added 3 commits October 31, 2026 08:25
configure.arguments skipped every parameter whose value was falsy, so False,
0 and "" were silently replaced by the command's defaults, and on/off flags
(e.g. --trace/--no-trace) could never be turned off. Only missing (None)
parameters now fall back to the defaults; a flag set to False is passed by
its secondary name (--no-trace) when it has one, and left off otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
execute.command checked the return code before storing stdout and stderr,
so a failed command's Work had no output at all, only the logged
CalledProcessError. The output is now stored first; a command stopped by its
timeout keeps what it printed before it was killed (returncode None).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A command's whole stdout was saved in its Work's results, and so in the
Buckets and Results databases, which keep it with no retention (one
baseband localization Work holds about 3 MB of output). Only its last
1024 lines are kept now, which still include the last line that results
are read from; stderr is kept whole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chitrangpatel chitrangpatel changed the title fix(lifecycle): keep failed commands' output and pass false parameters fix(lifecycle): keep failed commands' output, cap stdout, pass false parameters Oct 31, 2026
Programs that use Python logging write it to stderr by default, so stderr is
where most output is (34,000 of 36,000 lines for a baseband localization).
Both streams are now capped at their last 1024 lines (OUTPUT_LINES), which
still include a failure's traceback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chitrangpatel chitrangpatel changed the title fix(lifecycle): keep failed commands' output, cap stdout, pass false parameters fix(lifecycle): keep failed commands' output, cap it at 1024 lines, pass false parameters Oct 31, 2026
The runner's spinner was forced on even without a terminal, so in a
container every frame was written to its logs, once a second for the
whole run (5,209 frames in one localization's saved logs). It is now
only shown when stdout or stderr is a terminal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@masonng-astro
masonng-astro merged commit 8071431 into main Nov 1, 2026
14 checks passed
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.

2 participants