Skip to content

ci(optimization-report): cap stdout dump at 1 MiB to keep GHA runner alive - #2658

Merged
zackees merged 3 commits into
masterfrom
ci/cap-optimization-report-output
May 31, 2026
Merged

zackees merged 3 commits into
masterfrom
ci/cap-optimization-report-output

Conversation

@zackees

@zackees zackees commented May 31, 2026 •

Copy link
Copy Markdown
Member

Summary

  • -fopt-info-all writes a per-board optimization report. Across the full example matrix (~110 sketches on nrf52840_dk + the other Adafruit-BSP boards), the report routinely exceeds 100 MB.
  • The Optimization Report step in build_template.yml dumps the entire file to the GitHub Actions log via print(text). This overruns the runner's log buffer and triggers an external runner shutdown signal.
  • Symptom: the build step succeeds, several post-build analytics steps succeed, then Optimization Report cancels at ~37s and the runner dies; downstream cleanup steps stay pending and the workflow is marked FAILURE despite the build being green.

Verified failures on master SHA a302c1ba:

  • nrf52840_supermini run 26705682359 — build SUCCESS at 08:51:29, Optimization Report cancelled 08:55:02
  • adafruit_feather_nrf52840_sense run 26705682371 — same pattern, build SUCCESS at 08:51:29, Optimization Report cancelled 08:55:02

Fix

  • Default to printing the last 1 MiB of the report (most-recently-emitted optimizer info, which is the most useful slice for size-driven debugging).
  • --max-bytes 0 opts back into the full dump for local use.
  • Tail is snapped to the next line boundary so the output doesn't lead with a half-line.
  • Prints a one-line announcement up front showing the total size and how many bytes were elided.

Counterpart to PR #2655

#2655 added timeout-minutes: 5 to Symbol Analysis + Optimization Report, but couldn't help when the runner shutdown arrives faster than the step timeout (the log-buffer overrun is faster than 5 minutes).

Test plan

  • CI passes for the affected nRF52840 workflows once this lands on master.
  • Existing local uv run ci/optimization_report.py --first --cwd /tmp/some/build still produces useful output for normal-sized reports (the cap is only enforced when the report exceeds 1 MiB).

Refs #2641, #2653.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Optimization reports output is now capped at a configurable limit, displaying the tail portion when truncated
    • Added --max-bytes CLI flag and FL_OPT_REPORT_MAX_BYTES environment variable to customize the default report size (0 disables the cap)
    • Invalid or missing env values fall back to a sane default; negative values are treated as zero
    • Truncated reports include a summary showing total size, bytes displayed, and bytes omitted; CLI help text clarified for inspection use

…alive

With `-fopt-info-all` applied across the full example matrix (~110
sketches on nrf52840_dk + Adafruit BSP boards), the per-board
optimization_report.txt routinely exceeds 100 MB. The Optimization
Report step in build_template.yml prints the entire file to the GitHub
Actions log, which overruns the runner's log-buffer limit and triggers
an external shutdown signal — see master CI for nrf52840_supermini
(run 26705682359) and adafruit_feather_nrf52840_sense (run 26705682371)
where the build step succeeded but Optimization Report cancelled at
~37s with the runner dying mid-step, leaving downstream cleanup steps
unrun and the workflow marked FAILURE despite the build being green.

Default to printing the LAST 1 MiB of the report (most-recently emitted
optimizer info, which is what's most useful for size-driven debugging),
with a `--max-bytes 0` escape hatch for the rare local case where the
full dump is desired. Snap the tail to the next line boundary so we
don't lead with a truncated half-line, and announce up front how many
bytes were elided.

Refs #2641, #2653. Counterpart to #2655 (which added timeout-minutes:5
to the Symbol Analysis + Optimization Report steps but couldn't help
when the runner shutdown comes faster than the step timeout).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@coderabbitai

coderabbitai Bot commented May 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c884f7c1-3671-4998-bd18-e6456f69b6b2

📥 Commits

Reviewing files that changed from the base of the PR and between 3da7f31 and 11c013a.

📒 Files selected for processing (1)
  • ci/optimization_report.py

📝 Walkthrough

Walkthrough

The script adds a configurable byte cap for printing optimization_report.txt (env FL_OPT_REPORT_MAX_BYTES → default constant, overridable via --max-bytes). When the file exceeds the cap the script reads only the final bytes, advances to the next newline to avoid a partial first line, decodes safely, and prints a summary plus the tail.

Changes

Report output limiting

Layer / File(s) Summary
Byte limit configuration and CLI integration
ci/optimization_report.py
Added DEFAULT_MAX_REPORT_BYTES, env-derived default from FL_OPT_REPORT_MAX_BYTES (fallback/clamp), --max-bytes CLI flag, updated CLI description, and changed parse_args()/main() signatures to accept optional argv.
Conditional report output with truncation
ci/optimization_report.py
Removed an obsolete commented line and replaced unconditional file read/print with size-aware behavior: compute total size and effective max_bytes, print whole file when allowed or tail only when capped, snap tail start to next newline, decode with UTF-8 replacement, and print a header with total/shown/elided byte counts plus the truncated content.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 I peeked the bytes at eventide,

Tail-trimmed lines now softly ride,
New cap set by env or flag,
No split word starts to snag,
A tidy report, snug and spry.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: capping the optimization report stdout dump to prevent GHA runner issues.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/cap-optimization-report-output

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…ow-up

Address review feedback:
- Allow FL_OPT_REPORT_MAX_BYTES env var to override the 1 MiB default so
  devs can bump it locally without editing the script. `0` disables the
  cap. The --max-bytes CLI flag still wins.
- Document the durable fix (upload optimization_report.txt as a build
  artifact + print only a summary) as a follow-up so this PR remains a
  focused stop-gap.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/optimization_report.py`:
- Around line 35-51: The parse_args function must accept an optional list[str]
parameter so tests can inject argv; update the signature of parse_args
(currently parse_args() -> argparse.Namespace) to parse_args(argv: list[str] |
None = None) -> argparse.Namespace, adjust the type hint accordingly, and pass
that argv into parser.parse_args(argv) when returning so existing behavior (None
uses sys.argv) is preserved; reference the parse_args function and the
parser.parse_args call in your change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 80e1ab85-35cc-4b41-931b-438316fe2b23

📥 Commits

Reviewing files that changed from the base of the PR and between a302c1b and 3da7f31.

📒 Files selected for processing (1)
  • ci/optimization_report.py

Comment thread ci/optimization_report.py Resolved
Address CodeRabbit comment on PR #2658: make parse_args / main accept
an optional argv list[str] | None so tests can supply arguments
deterministically.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@zackees

zackees commented May 31, 2026

Copy link
Copy Markdown
Member Author

Addressed in commit 11c013a: parse_args and main now accept an optional argv: list[str] | None = None for deterministic test injection. Behavior unchanged for CLI use (argv stays None → argparse defaults to sys.argv[1:]).

@zackees
zackees merged commit e03ab51 into master May 31, 2026
5 checks passed
zackees added a commit that referenced this pull request May 31, 2026
Today every non-AVR / non-esp32c2 board unconditionally gets
`-fopt-info-all=<board>/optimization_report.txt` injected by
ci/compiler/pio.py. The flag is APPEND-mode and writes a single file
shared across every example in the matrix — for slow-link (no-LTO)
boards with a large example set (nrf52840 + Adafruit BSP: ~110
examples × ~25-96 source files × hundreds of opt-info lines per TU)
the file routinely exceeds 100 MB.

When build_template.yml's Optimization Report step then dumps that
file to the GitHub Actions log via `ci/optimization_report.py --first`,
the per-step log buffer overruns and the runner is killed mid-step,
masking already-successful builds. PR #2658 capped the log-side dump
at 1 MiB as a stop-gap; this PR closes the source-side hole by making
the GCC flag itself opt-in.

Changes:
- Add `Board.generate_optimization_report: bool = False` (default OFF)
- ci/compiler/pio.py only injects `-fopt-info-all=...` when the board
  opts in (and still respects the esp32c2 / atmelavr suppression)
- The linker map (`-Wl,-Map,firmware.map`) stays unconditional — it's
  a small per-example file and is consumed by size-analysis tooling

Behavior for the Optimization Report workflow step is unchanged for
opted-in boards. For non-opted-in boards the report file simply
doesn't exist; `ci/optimization_report.py --first` already handles
that case gracefully (prints a "No optimization report found" message
and exits 0).

Boards that need the report for size/perf debugging can opt in by
adding `generate_optimization_report=True` to their `Board(...)`
definition in ci/boards.py.

Refs PR #2658.

Co-authored-by: Claude Opus 4.7 <[email protected]>
@zackees
zackees deleted the ci/cap-optimization-report-output branch August 21, 2026 19:15
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.

1 participant