Skip to content

CI: cancel stale runs, -Werror on app code, size budget, UBSan - #184

Merged
raorjun merged 10 commits into
mainfrom
arjun/ci-hardening-main
Oct 27, 2026
Merged

raorjun merged 10 commits into
mainfrom
arjun/ci-hardening-main

Conversation

@raorjun

@raorjun raorjun commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Targets main directly and does not depend on #182. Replaces #183, which
was stacked on #182.

  • Cancel stale runs: a new push to a PR cancels that PR's older run.
    Runs on main still finish.
  • -Wall -Wextra -Werror on each board's app library. Board/ is
    excluded, because it links with CubeMX and ST HAL sources that are not
    warning-clean.
  • {image}_size_test: fails above 85% of flash or RAM
    (size_budget_percent on firmware_project). VCU on main: 10.3% flash,
    12.9% RAM. With VCU: firmware reorg, control fixes, and feedforward power limit #182: 26.6% flash, 41.1% RAM.
  • --config=ubsan: host tests with undefined behavior trapping.
    Presubmit runs it on //boards and //drivers. ASan is not possible
    because the hermetic LLVM ships no sanitizer runtime.

Checked in WSL with --config=local, on main alone: 17/17 tests pass,
8/8 under UBSan, and the format check passes. On top of #182: 37/37, and
28/28 under UBSan.

Not included: the log-replay test. It needs trimmed CSV fixtures and a
plant model, so it gets its own PR.

Summary by CodeRabbit

  • Tests
    • Host C++ tests can run with undefined-behavior checks in trap mode.
    • Firmware image checks flag flash or RAM usage above the configured budget, with per-region budget overrides.
    • Presubmit results include a summary of firmware memory usage.
  • Documentation
    • Added guidance for running UBSan tests and interpreting firmware size checks.
  • Chores
    • New pull-request runs cancel older in-progress runs in the same workflow; other runs are not canceled by this setting.
    • Firmware application builds enable additional compiler warnings and treat warnings as errors.

- A new push to a PR cancels that PR's older run of each workflow. Runs
  on main still finish.
- Board app libraries compile with -Wall -Wextra -Werror. Board/ shares a
  binary with CubeMX and ST HAL code, so it is not covered.
- Each firmware image gets an {image}_size_test that fails above 85% of
  flash or RAM, read from the ELF and the linker script's MEMORY block. The
  VCU is at 26.6% flash and 41.1% RAM.
- --config=ubsan reruns the host tests with undefined behavior trapping.
  The hermetic LLVM ships no ASan runtime, so trap-mode UBSan is the
  sanitizer that works without one. Presubmit runs it on //boards and
  //drivers.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 78f7ac1 and 6cd2b0e.

Files selected for processing: 5
  • .github/workflows/presubmit.yml
  • tools/firmware/README.md
  • tools/firmware/firmware_project.bzl
  • tools/firmware/size_check.py
  • tools/firmware/size_check_test.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The changes add firmware memory-budget tests, a UBSan configuration and presubmit checks, and pull-request concurrency controls for seven GitHub workflows.

Changes: Workflow concurrency

Layer / File(s) Summary
Configure workflow run concurrency
.github/workflows/{autonomy,bevo,docs,lint-format,presubmit,simulation,telemetry}.yml
Each workflow groups runs by workflow and pull-request number, or by run ID when no pull-request number is available. In-progress runs are canceled only for pull-request events.

Firmware checks

Layer / File(s) Summary
Parse firmware memory usage
tools/firmware/size_check.py, tools/firmware/size_check_test.py, tools/firmware/BUILD.bazel
The checker parses linker memory regions and allocated sections from a 32-bit little-endian ELF. It accounts for run and load addresses, reports per-region usage, and returns failure when a region exceeds its budget. Tests cover parsing, accounting, and budget outcomes.
Create a size test for each firmware image
tools/firmware/firmware_project.bzl, tools/firmware/README.md
The firmware macro creates a size test for each image, passing its ELF, linker script, and budget to the checker. It supports a default budget and per-region overrides. The app library enables -Wall, -Wextra, and -Werror.
Run host tests with UBSan
.bazelrc, .github/workflows/presubmit.yml, tools/ubsan/*, README.md, mkdocs.yml, tools/README.md, tools/firmware/README.md
The UBSan configuration enables undefined-behavior checks in trap mode and excludes tests tagged firmware_size. Presubmit runs selected host tests and a trap canary, and adds firmware size-test output to the step summary. Documentation describes the configuration, canary, and size-test exclusion.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Other

Merge Risk: Minimal · up to 6cd2b

The firmware size checks and CI summary have no identified issue that needs fixing before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 14.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 6 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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 clearly and concisely summarizes the main changes: stale CI run cancellation, app warning enforcement, firmware size budgets, and UBSan support.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 14.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 6 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@raorjun
raorjun requested review from dhairs and samuelLi05 October 26, 2026 04:31
@raorjun
raorjun marked this pull request as ready for review October 26, 2026 04:31
@lhre-ultron

lhre-ultron Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Safe to merge. I found no new problems, and all four of my earlier findings are fixed.

  • The hex LENGTH parsing and the brace-in-comment handling in tools/firmware/size_check.py are fixed. Comments are stripped first and hex lengths are accepted.
  • The bare KeyError on a missing FLASH or RAM region is gone. Every region the linker script declares is now checked.
  • A section outside every region now raises an error instead of being skipped.
  • The .github/workflows/autonomy.yml concurrency group now falls back to github.run_id, so push, schedule and manual runs are never cancelled.
What I checked

Checked: I read the whole diff. I ran size_check_test.py and all 20 tests pass. I checked the VCU linker script's MEMORY block against the parser. I traced the bazel-testlogs path built in the presubmit summary step, and it resolves correctly. I checked that the ubsan config filters out the firmware_size tests and that trap_test is manual but named explicitly in presubmit. I checked the concurrency group expression in every workflow.

Didn't check: I did not run Bazel, so the -Werror builds, the UBSan runs and the CI steps are untested. I did not confirm that -fsanitize=undefined in trap mode builds cleanly for code with polymorphic classes, or that exec-config tools build under it. The PR author reports 28/28 passing under UBSan, but I did not reproduce that.

Assumed: elf_out hands the size test the ELF built for the target MCU, not a host build. The $(rootpath) use for linker_script matches the existing $(location) use in firmware_project.bzl.

Ultron reviewed 6cd2b0e · it re-reviews on new pushes

@lhre-ultron lhre-ultron Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultron's review of d9daa3b, line by line.

Comment thread tools/firmware/size_check.py Resolved
Strip comments before finding the MEMORY block, so a brace in a comment
cannot end it. Accept hex LENGTH values. Fail clearly on a zero-length
region instead of dividing by zero. Adds a parser test.
coderabbitai[bot]

This comment was marked as resolved.

@lhre-ultron lhre-ultron Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultron's review of 011acde, line by line.

Comment thread .github/workflows/autonomy.yml Resolved
Keying by ref let a newer push or schedule drop a pending run on main.
Keying by run_id keeps every non-PR run. PR runs still cancel the older
run.

@lhre-ultron lhre-ultron Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultron's review of 74bce57, line by line.

Comment thread tools/firmware/size_check.py Resolved
@raorjun
raorjun requested a review from GrayM8 October 26, 2026 04:43
A linker script with other region names now fails with a message that
lists the regions found, not a bare KeyError.

@GrayM8 GrayM8 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

A LENGTH like "512K - 16K" used to parse as 512K, overstating the region
and under-reporting usage. It's now an error naming the region. Region
attributes are optional, as GNU ld allows.

The tests now build a small ELF and check the budget math end to end,
including .data counting against both flash and RAM.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The generated CAN pack/unpack code does the shifts and sign extension
UBSan exists for, so //lib/codegen/cpp/... joins the UBSan step.
//tools/ubsan:trap_test overflows on purpose and passes only if that
traps, so the step can't go green just because the flags stopped
reaching the compiler.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@lhre-ultron lhre-ultron Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultron's review of 5781541, line by line.

Comment thread tools/firmware/size_check.py Outdated
Comment on lines +71 to +72
elif flash_origin <= addr < flash_origin + flash_len:
flash += size

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor | Correctness

Fail on allocated sections that fall outside both FLASH and RAM instead of skipping them

The loop only counts a section if its address lies in the RAM or FLASH window and drops every other allocated section without a message. Sections in other regions (CCM SRAM, backup SRAM, a second RAM bank) are therefore left out of the budget. Their flash-resident initial values are left out too. An image can pass {image}_size_test while really being over budget. The VCU linker script has only RAM and FLASH, so this doesn't bite today. It will when a board adds a region.

Suggested change
elif flash_origin <= addr < flash_origin + flash_len:
flash += size
elif flash_origin <= addr < flash_origin + flash_len:
flash += size
else:
raise ValueError(
f"allocated section at 0x{addr:x} ({size} bytes) is outside FLASH and RAM; "
f"extend size_check.py to account for it")
🤖 Prompt for AI agents
In tools/firmware/size_check.py around lines 71-72:
The loop over alloc_sections ignores sections whose address is in neither the FLASH nor the RAM window, so they escape the budget. Add an else branch that raises ValueError naming the address and size, so the test fails loudly until the region is handled. Add a case to size_check_test.py with a section at 0x10000000.

A section in another region (CCM SRAM, a second RAM bank) was skipped,
so the budget could pass on an undercount. It's now an error naming the
section and its address.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

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

🔇 Additional comments: 15
.github/workflows/autonomy.yml: 1

25-28: LGTM!

.github/workflows/bevo.yml: 1

16-19: LGTM!

.github/workflows/docs.yml: 1

20-23: LGTM!

.github/workflows/lint-format.yml: 1

6-9: LGTM!

.github/workflows/simulation.yml: 1

26-29: LGTM!

.github/workflows/telemetry.yml: 1

26-29: LGTM!

tools/firmware/README.md: 1

26-26: LGTM!

Also applies to: 79-84, 166-166, 171-190

.github/workflows/presubmit.yml: 1

6-7: LGTM!

Also applies to: 9-9, 66-71

tools/ubsan/BUILD.bazel: 1

1-13: LGTM!

tools/ubsan/trap_test.cpp: 1

1-21: LGTM!

README.md: 1

99-99: LGTM!

mkdocs.yml: 1

52-52: LGTM!

tools/README.md: 1

13-13: LGTM!

tools/ubsan/README.md: 1

1-32: LGTM!

tools/firmware/size_check.py-74-74: 1

74-74: Major · Functional Correctness · Heavy lift

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Account for section placement in the size budget.

If two FLASH sections occupy offsets 0–999 and 1900–1999 in a 2048-byte region, the checker reports 53.7% and passes an 85% budget. The image extends through 97.7% of the region. GNU ld can introduce gaps when it aligns output sections. Calculate the occupied extent from section addresses; use load addresses for initialized RAM data stored in FLASH. (sourceware.org)


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d9daa3b and 78f7ac1.

Files selected for processing: 18
  • .bazelrc
  • .github/workflows/autonomy.yml
  • .github/workflows/bevo.yml
  • .github/workflows/docs.yml
  • .github/workflows/lint-format.yml
  • .github/workflows/presubmit.yml
  • .github/workflows/simulation.yml
  • .github/workflows/telemetry.yml
  • README.md
  • mkdocs.yml
  • tools/README.md
  • tools/firmware/BUILD.bazel
  • tools/firmware/README.md
  • tools/firmware/size_check.py
  • tools/firmware/size_check_test.py
  • tools/ubsan/BUILD.bazel
  • tools/ubsan/README.md
  • tools/ubsan/trap_test.cpp
Files skipped from review as they are similar to previous changes: 1
  • .bazelrc

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

The check hardcoded FLASH and RAM, so an F4 using CCMRAM or an H7 with
DTCMRAM and RAM_D1..D3 either failed outright or went uncounted. Now it
budgets whatever regions the linker script declares and prints a usage
line per region.

Each section counts against the region it runs from and, read from the
ELF's program headers, the region it's loaded from when that differs.
That covers .data and code copied to CCM or ITCM without naming them.
ORIGIN expressions are now refused like LENGTH ones, and
size_budget_overrides gives a region meant to be full its own budget.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
size_check now prints its per-region usage as a markdown table, and
presubmit copies each image's table from its size test log onto the
run's summary page, even when the test fails. Memory use is visible on
every PR without opening the test log.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@raorjun
raorjun merged commit cca2fa9 into main Oct 27, 2026
14 checks passed
@raorjun
raorjun deleted the arjun/ci-hardening-main branch October 27, 2026 03:22
raorjun pushed a commit that referenced this pull request Oct 31, 2026
Resolves the one conflict, in tools/firmware/README.md: keep main's
-Werror note for the app library (#184) and this branch's recursive
App/**/ globs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai coderabbitai Bot mentioned this pull request Nov 10, 2026
3 tasks done
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.

3 participants