Repository navigation
Description
Problem Description
Each devops command writes the line Elapsed: <duration> to stderr at exit, also when stderr is not a terminal. _print_elapsed in src/devops_cli/main.py (lines 27-35) is an atexit hook with no terminal check. An agent tool such as the Bash tool of Claude Code captures stdout and stderr together, so the line goes into the agent context on almost every call. A 2>&1 pipe puts it after the JSON reply, and the JSON parser fails with JSONDecodeError: Extra data.
Evidence from the Claude Code transcripts of this project:
- 2026-11-11 to 2026-11-13: 9,281 of 19,767
devopsresults (47%) hold theElapsed:line. - In the same window, 2,331 of 19,767
devopscalls (12%) add agrep -vfilter forElapsed. Before 2026-11-11, 548 of 34,453 calls did so. Agents now copy the filter from brief to brief. - 2026-10-16 to 2026-11-10: 63
Extra datafailures afterdevops gh api ... | python3. TheElapsed:line after the JSON gives this error. CONTRIBUTING.md(section "JSON fromuv run devops gh apibreaks in two ways") tells agents about the line. It does not remove the cause.
The other JSON failure class, Expecting value (231 cases before 2026-11-11), came mostly from the uv Bytecode compiled line. #4592 removed that line for Claude Code on 2026-11-11. Since then, only 4 such failures occurred. This item does not change uv.
Reproduction Steps
- Run
uv run devops gh rate-limit --format json 2>&1 | cat. - See the
Elapsed:line after the JSON. - Run
uv run devops gh api repos/{owner}/{repo} 2>&1 | python3 -c 'import json,sys; json.load(sys.stdin)'. - See
json.decoder.JSONDecodeError: Extra data.
Expected vs Actual Behavior
Expected: the Elapsed: line appears only when stderr is a terminal. A person at a terminal still sees it. A pipe, a file and an agent tool get no line. The command duration stays in the telemetry (devops_cli_subcommand_duration_seconds and the command span).
Actual: the line goes to stderr in every case.
Proposed Solution
_print_elapsedprints only whensys.stderr.isatty()is true.- Do not use Rich
Console.is_terminal. Rich treatsFORCE_COLORandTTY_COMPATIBLEas a terminal, so a pipe in a shell that sets them gets the line again. - Change the
CONTRIBUTING.mdsection on JSON fromdevops gh api: remove theElapsed:part, and keep the zshechopart. Change any brief or skill that tells agents to filter the line.
Acceptance Criteria
- A test runs a command with stderr in a pipe and proves that stderr holds no
Elapsed:line. The test fails on the base. - A test with stderr on a pseudo-terminal proves that the line is still there.
- A test proves that
FORCE_COLOR=1with stderr in a pipe gives no line. -
uv run devops ci fail-to-pass --base origin/mainshows that the new tests fail on the base. - Measure in telemetry:
devops_cli_subcommand_duration_secondsstill records each command after the change, so no duration is lost. - Measure in the agent transcripts, 7 days after the release: the share of
devopsresults that holdElapsed:goes to 0, and newgrep -v Elapsedfilters go down.
Existing Tool Considered
The standard library sys.stderr.isatty(). No new tool. Cost to build (estimate): 0.1 M model input and output, and 1 to 2 hours. Cost to keep: near 0.
Related
#4592 (the uv lines), #4833 (CLI usage tracker).
Proposed design
Problem statement
Each devops command writes Elapsed: <duration> to stderr at exit, also when stderr is a pipe. An agent tool captures stdout and stderr together, so the line enters the agent context. A 2>&1 pipe puts the line after JSON, and the parser fails with JSONDecodeError: Extra data. The change adds a terminal check to _print_elapsed and removes the workaround from the agent documentation.
Acceptance criteria
Requirement: Pipe gets no elapsed line
The CLI SHALL write the Elapsed: line to stderr only when stderr is a terminal.
Scenario: A pipe receives no elapsed line
- WHEN A test runs a CLI command with stderr connected to a pipe.
- THEN The captured stderr holds no
Elapsed:line.
Requirement: Terminal gets the elapsed line
The CLI SHALL write the Elapsed: line to stderr when stderr is a terminal.
Scenario: A pseudo-terminal receives the elapsed line
- WHEN A test runs a CLI command with stderr connected to a pseudo-terminal.
- THEN The pseudo-terminal output holds the
Elapsed:line.
Requirement: Color variables do not enable the line
The CLI MUST ignore FORCE_COLOR and TTY_COMPATIBLE when it decides whether stderr is a terminal.
Scenario: Color variables with a pipe
- WHEN A test runs a CLI command with
FORCE_COLOR=1andTTY_COMPATIBLE=1and stderr connected to a pipe. - THEN The captured stderr holds no
Elapsed:line.
Requirement: Duration telemetry survives the terminal guard
The change SHALL keep the command duration metric for a command whose stderr is a pipe.
Scenario: A piped command still emits its duration
- WHEN A test runs a delegated CLI command with stderr connected to a pipe and the telemetry emit function replaced by a test double.
- THEN The test observes one
devops_cli_subcommand_duration_secondsemission for the command.
Requirement: Contributing guide drops the elapsed workaround
The CONTRIBUTING.md section on JSON from devops gh api SHALL remove the Elapsed: workaround, keep the zsh echo warning, and no longer say that JSON breaks in two ways.
Scenario: The JSON section keeps only the zsh warning
- WHEN A test reads
CONTRIBUTING.md. - THEN The test finds the zsh
echowarning, no instruction to filterElapsed:, and no text that JSON breaks in two ways.
Requirement: Agent briefs drop the elapsed filter
Each agent brief or skill that tells agents to filter Elapsed: from devops gh api output SHALL no longer do so.
Scenario: Repository search finds no elapsed filter
- WHEN A test searches the tracked documentation and skill files for an instruction to filter
Elapsed:. - THEN The search finds no instruction to filter
Elapsed:fromdevops gh apioutput.
Existing Tool Considered
No alternatives check has run. The standard library sys.stderr.isatty() covers the need and lacks no needed feature; it needs no new dependency. Cost to build: 0.1 M model input and output tokens and 1 to 2 hours. Cost to keep: near 0.
Key questions
- Which terminal check should
_print_elapseduse?: Usesys.stderr.isatty(). Do not use RichConsole.is_terminal, because Rich treatsFORCE_COLORandTTY_COMPATIBLEas a terminal. (best practice) [sources: src/devops_cli/main.py:27, tests/conftest.py:772]- Chosen:
sys.stderr.isatty(). It reads the real stderr file descriptor and ignores color environment variables. - Rejected: Rich
Console.is_terminal. It treatsFORCE_COLORandTTY_COMPATIBLEas a terminal, so a pipe in such a shell gets the line. - Rejected: Remove the line entirely. A person at a terminal loses the duration display that the issue keeps.
- Chosen:
- Which stream should carry the
Elapsed:line?: Keep it on stderr. A terminal user sees it, and stdout stays valid JSON for a pipe. (best practice) [sources: src/devops_cli/main.py:27, CONTRIBUTING.md:131]- Chosen: stderr. It is the current stream and keeps stdout clean for JSON.
- Rejected: stdout. It would mix the line into JSON and break parsers.
- Rejected: both streams. It adds the line to stdout and repeats the defect.
- Does the change keep the command duration telemetry?: Yes.
_delegateemitsCOMMAND_DURATIONand the command span independently of_print_elapsed, so the change keeps both. [sources: src/devops_cli/main.py] - What should the documentation and agent instructions say after the change?: Remove the
Elapsed:workaround fromCONTRIBUTING.mdand from each brief or skill that tells agents to filter it. Keep the zshechowarning, which is a separate JSON defect. (best practice) [sources: CONTRIBUTING.md:131]- Chosen: Remove the
Elapsed:workaround and keep the zshechowarning. The cause is gone, and the zshechodefect remains. - Rejected: Leave the workaround in place. It tells agents to filter a line that the CLI no longer writes.
- Rejected: Remove the whole JSON section. The zsh
echowarning still prevents JSON parse failures.
- Chosen: Remove the
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 13, 2026
47% of agent results hold the line and 63 JSON parse failures occurred, so it blocks automation at scale.Both items fix non-JSON text that breaks a JSON stream, but #3532 is logfire spans on stdout in tests and the candidate is the Elapsed line on stderr in the CLI.devops-cli-service commentedon Nov 13, 2026
Status set to Ready at b4a4ffb (see proposed design in issue body).
Moved to new items: #5461.
devops-cli-service commentedon Nov 13, 2026
Staged: branch
fix/5448-print-the-elapsed-line-only-when, draft pull request #5544. The pull request plans the item and closes no issue.The task groups, with the tokens of the inputs of each step, for a budget of 64000 tokens:
A model review of the plan found these points. They stop no draft, and a person judges them:
false_premiseat proposal (feasibility): The hook also reads_timing['start']and returns without printing when it is absent, so the claim that it reads onlysys.stderris false; this is why group 2 calls it with no start time. Evidence: "_print_elapsed()takes no argument and reads onlysys.stderr; it needs no checkout, no client and no network."otherat tasks (2): The pseudo-terminal test calls_print_elapsed()with an empty_timing, which the autouse fixture clears after every test, so the hook prints nothing and the assertion on the master descriptor can never pass. Evidence: "call_print_elapsed()and assert the master descriptor holds theElapsed:line"otherat tasks (2): Group 2 imports the private_print_elapsedfromdevops_cli.main, whiledocs/TESTING.mdforbids a test from importing a private name and requires reaching private code through the public interface. Evidence: "imports_print_elapsedfromsrc/devops_cli/main.py"ignores_existing_codeat tasks (3): Group 3 replaces theemitattribute of a devops-cli module with a recorder, whichdocs/TESTING.mdforbids, and ignores the existingFakeCollector/otlpfake in the same test module. Evidence: "replaceemitofsrc/devops_cli/telemetry/instruments.pywith a recorder"spec_delta_wrongat spec console-output (The elapsed line goes only to a terminal): The scenario 'A pseudo-terminal receives the elapsed line' has no test that can assert it, because group 2's test prints nothing with an empty_timing. Evidence: "A pseudo-terminal receives the elapsed line"otherat tasks (1): The pseudo-terminal case skips when the host cannot open a pty, and docs/TESTING.md forbids a test that skips on host state, so the suite no longer runs the same on every host. A host without /dev/ptmx would leave the requirement's pseudo-terminal scenario unproven. Evidence: "it skips with a reason that names the missing pseudo-terminal whenopenpty()raisesOSError"The runs of the planner and the review made 103 model request(s), and used 8374195 input tokens and 244426 output tokens. The tool calls, in order:
read_file({"path":"src/devops_cli/main.py","start_line":1,"end_line":40})read_file({"path":"src/devops_cli/main.py","start_line":170,"end_line":400})list_files({"directory":"tests/invariants"})read_spec({"capability":"console-output"})read_file({"path":"openspec/specs/console-output/spec.md","start_line":1,"end_line":60})read_spec({"capability":"command-error-exit"})search_code({"text":"reset_timing"})search_code({"text":"fail-to-pass"})read_file({"end_line":175,"path":"tests/conftest.py","start_line":115})read_file({"end_line":830,"path":"tests/conftest.py","start_line":760})read_file({"end_line":80,"path":"openspec/specs/command-error-exit/spec.md","start_line":1})references({"name":"Elapsed"})read_file({"end_line":160,"path":"CONTRIBUTING.md","start_line":110})search_code({"text":"grep -v"})read_file({"end_line":130,"path":"src/devops_cli/output/console.py","start_line":95})search_code({"text":"def print_muted"})read_file({"end_line":530,"path":"src/devops_cli/output/console.py","start_line":455})search_code({"text":"def new_typer"})read_file({"end_line":420,"path":"src/devops_cli/core/cli.py","start_line":230})read_file({"end_line":215,"path":"tests/conftest.py","start_line":170})read_file({"end_line":175,"path":"src/devops_cli/main.py","start_line":140})search_code({"text":"isatty"})search_code({"text":"elapsed"})search_code({"text":"_print_elapsed"})search_code({"text":"Elapsed:"})list_files({"directory":"openspec/changes"})search_code({"text":"5448"})search_code({"text":"from devops_cli.telemetry.instruments import"})list_files({"directory":"k8s/devops/dashboards"})list_files({"directory":"tests/fixtures/dashboard_queries"})list_files({"directory":"openspec/specs"})list_files({"directory":"src/devops_cli/ai/knowledge_base/it_domains/tools"})list_files({"directory":"openspec/changes/archive"})file_symbols({"path":"src/devops_cli/output/console.py"})file_symbols({"path":"src/devops_cli/commands/config.py"})file_symbols({"path":"tests/telemetry/test_telemetry_instruments.py"})read_file({"end_line":80,"path":"tests/invariants/test_source_tree.py","start_line":1})read_file({"end_line":90,"path":"tests/telemetry/test_telemetry_instruments.py","start_line":70})search_code({"text":"from devops_cli.main import"})search_code({"text":"openpty"})search_code({"text":"pty"})search_code({"text":"StringIO"})read_file({"end_line":120,"path":"tests/commands/test_command_error_exit.py","start_line":1})search_code({"text":"working directory does not exist"})read_file({"end_line":245,"path":"tests/output/test_output.py","start_line":215})read_file({"end_line":175,"path":"tests/output/test_output.py","start_line":120})references({"name":"devops_cli_subcommand_duration_seconds"})search_code({"text":"elapsed_time"})search_code({"text":"MESSAGES.ci.elapsed_time"})read_file({"end_line":590,"path":"src/devops_cli/lang/en/messages.py","start_line":570})search_code({"text":"_timing"})search_code({"text":"reset_timing()"})search_code({"text":"time.monotonic() - _timing"})search_code({"text":"runner.invoke(app"})search_code({"text":"app,"})read_file({"end_line":80,"path":"tests/invariants/test_suite_refuses_real_programs.py","start_line":1})search_code({"text":"REAL_PROGRAMS"})read_file({"end_line":110,"path":"docs/TESTING.md","start_line":80})read_file({"end_line":80,"path":"tests/support/fakes/otlp.py","start_line":1})read_file({"end_line":1055,"path":"tests/telemetry/test_telemetry_instruments.py","start_line":1020})search_code({"text":"def otlp"})search_code({"text":"FakeCollector"})read_file({"path":"tests/telemetry/test_telemetry_instruments.py","start_line":1,"end_line":120})search_code({"text":"SUBCOMMAND_DURATION"})search_code({"text":"otlp"})read_file({"path":"docs/TESTING.md","start_line":225,"end_line":275})search_code({"text":"def test_"})file_symbols({"path":"tests/telemetry/test_telemetry_instruments.py"})read_file({"path":"src/devops_cli/core/cli.py","start_line":1,"end_line":90})read_file({"path":"tests/telemetry/test_telemetry_instruments.py","start_line":1026,"end_line":1060})search_code({"text":"subcommand"})read_file({"end_line":120,"path":"src/devops_cli/telemetry/instruments.py","start_line":1})read_file({"end_line":80,"path":"tests/support/fakes/otlp.py","start_line":1})search_code({"text":"def emit("})search_code({"text":"otlp.metrics"})read_file({"end_line":905,"path":"src/devops_cli/telemetry/instruments.py","start_line":860})read_file({"end_line":75,"path":"tests/telemetry/test_telemetry.py","start_line":30})read_file({"end_line":230,"path":"src/devops_cli/core/cli.py","start_line":90})read_spec({"capability":"command-error-exit"})read_spec({"capability":"console-output"})read_spec({"capability":"command-error-exit","requirement":"A command run from a deleted working directory stops with one error line"})search_code({"text":"breaks in two ways"})file_symbols({"path":"src/devops_cli/commands/config.py"})read_file({"end_line":190,"path":"src/devops_cli/commands/config.py","start_line":133})search_code({"text":"def print_muted("})search_code({"text":"_STDERR_CONSOLE"})search_code({"text":"reset_timing"})read_file({"path":"src/devops_cli/output/console.py","start_line":460,"end_line":495})search_code({"text":"devops_cli.main import app"})search_code({"text":"standalone_mode=False"})read_file({"end_line":80,"path":"tests/support/cli.py","start_line":1})search_code({"text":"private"})search_code({"text":"_print_elapsed"})search_code({"text":"private name"})read_file({"path":"src/devops_cli/entry.py"})search_code({"text":"sys.executable"})read_file({"end_line":70,"path":"tests/core/test_process_hardening.py","start_line":25})search_code({"text":"live(\"python\")"})search_code({"text":"INVARIANT_TEST"})search_code({"text":"test_cli_elapsed_line"})search_code({"text":"unlisted"})search_code({"text":"tests/invariants/"})search_code({"text":"Elapsed:"})references({"name":"Elapsed"})list_files({"directory":"tests/ai/ast"})read_file({"path":"src/devops_cli/telemetry/instruments.py","start_line":38,"end_line":60})list_files({"directory":"tests/support"})list_files({"directory":"tests/invariants"})read_file({"path":"src/devops_cli/main.py","start_line":24,"end_line":38})read_file({"path":"tests/support/paths.py","start_line":1,"end_line":40})list_files({"directory":"tests/support/fakes"})list_files({"directory":"tests/ai/ast"})read_file({"path":"src/devops_cli/core/cli.py","start_line":40,"end_line":50})read_file({"path":"src/devops_cli/telemetry/instruments.py","start_line":50,"end_line":58})read_file({"path":"tests/conftest.py","start_line":128,"end_line":135})read_file({"path":"docs/TESTING.md","start_line":82,"end_line":88})read_file({"end_line":252,"path":"docs/TESTING.md","start_line":244})read_file({"end_line":80,"path":"tests/telemetry/test_telemetry_instruments.py","start_line":64})search_code({"text":"openpty"})search_code({"text":"isatty()"})search_code({"text":"test_workflow_contracts.py"})list_files({"directory":"tests"})search_code({"text":"test_swallowed_failures_check.py"})search_code({"text":"test_adr_records.py"})search_code({"text":"INVARIANT"})search_code({"text":"unlisted"})search_code({"text":"test_runner_image.py"})search_code({"text":"TESTING.md"})search_code({"text":"test_dry_run_class_ratchet.py"})file_symbols({"path":"tests/invariants/test_source_tree.py"})search_code({"text":"module_durations"})read_file({"end_line":750,"path":"tests/invariants/test_source_tree.py","start_line":710})read_file({"path":"docs/TESTING.md","start_line":85,"end_line":112})search_code({"text":"_read_testing_md_invariant_subjects"})search_code({"text":"devops_cli.main"})list_files({"directory":"tests/ai/ast"})search_code({"text":"devops_cli.main"})search_code({"text":"_print_elapsed"})search_code({"text":"from devops_cli import main"})search_code({"text":"main as"})search_code({"text":"names no existing test of that module"})read_file({"path":"tests/ai/ast/test_treesitter_engine.py","start_line":1,"end_line":40})search_code({"text":"devops_cli.main import app"})search_code({"text":"import devops_cli.main as main_module"})search_code({"text":"_timing["})read_file({"path":"tests/support/fakes/otlp.py","start_line":200,"end_line":330})read_file({"path":"docs/TESTING.md","start_line":80,"end_line":260})read_file({"path":"CONTRIBUTING.md","start_line":110,"end_line":175})read_file({"path":"src/devops_cli/main.py","start_line":270,"end_line":330})read_spec({"capability":"console-output"})read_spec({"capability":"command-error-exit"})search_code({"text":"Elapsed"})read_file({"path":"tests/invariants/test_hermetic_floor.py","start_line":850,"end_line":900})read_file({"path":"tests/conftest.py","start_line":110,"end_line":150})read_file({"path":"src/devops_cli/telemetry/tracer.py","start_line":1650,"end_line":1680})read_file({"path":"src/devops_cli/telemetry/instruments.py","start_line":860,"end_line":895})read_spec({"capability":"command-error-exit","requirement":"A command run from a deleted working directory stops with one error line"})read_file({"end_line":445,"path":"tests/ai/mcp/test_mcp_tool_argv.py","start_line":420})read_file({"end_line":740,"path":"tests/invariants/test_source_tree.py","start_line":705})read_file({"end_line":60,"path":"src/devops_cli/core/cli.py","start_line":30})search_code({"text":"mark.live"})read_file({"path":"tests/invariants/test_suite_refuses_real_programs.py","start_line":1,"end_line":80})read_file({"end_line":500,"path":"src/devops_cli/output/console.py","start_line":455})read_file({"end_line":215,"path":"tests/commands/test_telemetry_profile.py","start_line":185})read_file({"end_line":255,"path":"docs/TESTING.md","start_line":240})search_code({"text":"fail-to-pass"})search_code({"text":"grep -v"})list_files({"directory":".claude/skills"})references({"name":"Elapsed"})search_code({"text":"NOT_IN_RUNNER"})search_code({"text":"RUNNER_TOOLS"})read_file({"end_line":1040,"path":"tests/telemetry/test_telemetry_instruments.py","start_line":1015})search_code({"text":"def show("})search_code({"text":"config show"})read_file({"end_line":185,"path":"src/devops_cli/commands/config.py","start_line":120})search_code({"text":"skip"})read_file({"end_line":170,"path":"docs/TESTING.md","start_line":150})search_code({"text":"host state"})search_code({"text":"pytest.skip"})search_code({"text":"\"python\""})read_file({"end_line":270,"path":"src/devops_cli/main.py","start_line":180})read_file({"path":"tests/support/host_paths.py"})search_code({"text":"host_path_guard"})search_code({"text":"_print_elapsed"})read_file({"path":"src/devops_cli/entry.py","start_line":20,"end_line":35})search_code({"text":"addopts"})read_file({"path":"pyproject.toml","start_line":1,"end_line":20})read_file({"end_line":80,"path":"docs/TESTING.md","start_line":55})search_code({"text":"tests/invariants"})search_code({"text":"def print("})search_code({"text":"def get_console"})read_file({"end_line":260,"path":"src/devops_cli/output/console.py","start_line":80})search_code({"text":"_execute_traced_cli_command"})search_code({"text":"def new_typer"})search_code({"text":"invariant"})Tool calls: file_symbols=6 (empty=0), list_files=15 (empty=0), read_file=72 (empty=0), read_spec=8 (empty=0), references=4 (empty=0), search_code=90 (empty=4)
docs(openspec): plan #5448 Print the elapsed line only on a terminal (#…
7 remaining items
fix(cli): Drop the elapsed workaround from the contributing guide (#5448
docs(openspec): archive the change (#5448)
devops-cli-service commentedon Nov 13, 2026
Pull request #5554 is ready for review. The checks passed.
Spend: 181 model requests, 15553239 input tokens, 75773 output tokens.
devops-cli-service commentedon Nov 13, 2026
The runner Job devops-cli-runner-20261113-203559-e1ae ended: succeeded.
Image digest: sha256:071d132e3f8ec097af18e9773bcbafb4ab39f8a12b357dc22c594c06d012189f
The last lines of its log:
fix(cli): Guard the elapsed line with the stderr terminal check (#5448)
fix(cli): Prove the sub-command duration survives a piped stderr (#5448)
fix(cli): Drop the elapsed workaround from the contributing guide (#5448
docs(openspec): archive the change (#5448)
devops-cli-service commentedon Nov 13, 2026
Released in v0.133.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.133.0
devops-cli-service commentedon Nov 13, 2026
Live since 2026-11-13 22:33 UTC