Skip to content

feat(bench): §9 benchmarks.md results appender (PR-J3) - #55

Merged
jensholdgaard merged 7 commits into
mainfrom
feat/ourios-bench-benchmarks-md
May 26, 2026
Merged

feat(bench): §9 benchmarks.md results appender (PR-J3)#55
jensholdgaard merged 7 commits into
mainfrom
feat/ourios-bench-benchmarks-md

Conversation

@jensholdgaard

@jensholdgaard jensholdgaard commented May 26, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the --update-benchmarks-md path — the last unwritten piece of the report module. A bench run with the flag folds its results into docs/benchmarks.md §9.

Lands

  • src/report.rsupdate_status_section(md, results) -> String, a pure transform. It maintains one block per (git_sha, hardware_kind) pair inside a marker-delimited, bench-managed region under a ### Results sub-heading:
    • RFC0006.4: re-running on the same (sha, hw) rewrites that block in place — no duplicate sub-headings.
    • RFC0006.6: a partial --gates run replaces only the gates it measured (a1/c1/c2 that are Some), leaving previously recorded rows for the other gates intact.
    • Prose outside the BENCH-RESULTS markers is never touched; the region is regenerated wholesale from parsed-then-merged blocks, so the parser only ever reads its own output.
  • src/main.rs--update-benchmarks-md reads docs/benchmarks.md, calls the transform, writes it back (was a "not implemented" warning).
  • src/lib.rs — re-exports update_status_section.

Tests (pure &str transforms, per the §6 "temp markdown file" strategy)

  • first run creates the Results block + preserves prose;
  • rerun on same (sha, hw) rewrites in place, no dup heading (RFC0006.4);
  • C1-only rerun preserves the prior A1 row byte-for-byte (RFC0006.6);
  • missing ## 9. anchor is a Report error.

Verified end-to-end

--update-benchmarks-md on the seed corpus writes a valid §9 table:

#### `2877230` on `baseline-8vcpu-32gib` — updated 2026-05-26

| Gate | Measurement | Target | Verdict |
| --- | --- | --- | --- |
| A1 | delta 0.002× (ourios 0.018× / zstd-19 8.470×) | ≥ 3.0× | FAIL |
| C1 | 1.000000 (77/77 non-lossy; lossy 0.0000) | 100.000% | PASS |

mdbook build renders it, and the run leaves the committed docs/benchmarks.md untouched in this PR (results blocks are committed deliberately by a maintainer, not by the bench during CI).

Test plan

  • cargo fmt --all --check — clean.
  • cargo clippy --all-targets --all-features -- -D warnings — clean.
  • cargo test --all-features267 passed (+4 §9 appender tests).
  • mdbook build — clean.
  • Manual --update-benchmarks-md round (above).

Maturity stage

Remaining for RFC 0006 red → green: only the RFC0006.7 reproducibility test (still #[ignore]'d). All three gates + CLI + JSON + §9 appender are done.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Fully implemented the --update-benchmarks-md option to rewrite the benchmarks document’s Status section, inserting or updating results and merging new runs into the managed Results block.
    • Deterministic ordering and preservation of previously reported gates on partial runs.
  • Bug Fixes
    • Now errors instead of silently skipping when the Status anchor or managed markers are missing, corrupt, or inconsistent.
  • Tests
    • Added tests for initial insertion, in-place updates, partial-run merges, and error cases.
  • Documentation
    • Updated CLI help text to describe the rewrite behavior.

Review Change Stack

Implements the `--update-benchmarks-md` path — the last
unwritten piece of the `report` module. A bench run with the
flag now folds its results into `docs/benchmarks.md` §9.

Lands:

- `src/report.rs` — `update_status_section(md, results) ->
  String`, a pure transform. It maintains one block per
  `(git_sha, hardware_kind)` pair inside a marker-delimited,
  bench-managed region under a `### Results` sub-heading:
  - **RFC0006.4**: re-running on the same `(sha, hw)` rewrites
    that block in place — no duplicate sub-headings.
  - **RFC0006.6**: a partial `--gates` run replaces only the
    gates it measured (`a1`/`c1`/`c2` that are `Some`),
    leaving previously recorded rows for the other gates
    intact.
  Prose outside the `BENCH-RESULTS` markers is never touched;
  the region is regenerated wholesale from parsed-then-merged
  blocks, so the parser only ever reads its own output.
- `src/main.rs` — `--update-benchmarks-md` now reads
  `docs/benchmarks.md`, calls `update_status_section`, and
  writes it back (was a "not implemented" warning). Thin file
  I/O around the pure transform.
- `src/lib.rs` — re-exports `update_status_section`.

Tests (colocated in report.rs, pure `&str` transforms per the
§6 "temp markdown file" strategy):
- first run creates the Results block + preserves prose;
- rerun on same (sha, hw) rewrites in place, no dup heading
  (RFC0006.4);
- C1-only rerun preserves the prior A1 row byte-for-byte
  (RFC0006.6);
- missing `## 9.` anchor is a `Report` error.

Verified end-to-end: `--update-benchmarks-md` on the seed
corpus writes a valid §9 table, `mdbook build` renders it, and
the run leaves the committed `docs/benchmarks.md` untouched in
this PR (results blocks are committed deliberately, not by the
bench during CI).

Verification (CLAUDE.md §6.6):
- cargo fmt --all --check — clean.
- cargo clippy --all-targets --all-features -- -D warnings —
  clean.
- cargo test --all-features — 267 passed (was 263; +4 §9
  appender tests).
- mdbook build — clean.

Remaining for RFC 0006 `red → green`: only the RFC0006.7
reproducibility test (still `#[ignore]`'d). The §9 appender +
all three gates + the CLI are now done.

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

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Implements end-to-end markdown benchmark reporting: adds update_status_section to parse/merge ResultsFile gate rows into a managed ### Results region under ## 9. Status, wires the updater into the CLI to read/write docs/benchmarks.md, and adds tests for insertion, updates, partial merges, and error cases.

Changes

Markdown Benchmark Results Updater

Layer / File(s) Summary
CLI integration and public API
crates/ourios-bench/src/main.rs, crates/ourios-bench/src/lib.rs
Adds BENCHMARKS_MD_PATH, imports and re-exports update_status_section, replaces the previous --update-benchmarks-md stub with update_benchmarks_md which reads docs/benchmarks.md, applies the updater, writes the file, prints confirmation, and propagates errors as BenchError.
Markdown update contract and core logic
crates/ourios-bench/src/report.rs
Module docs, managed-region markers, GateRow/Block types, and pub fn update_status_section(md: &str, results: &ResultsFile) -> Result<String, BenchError> parse existing blocks, merge new results by (git_sha, hardware_kind), format gate rows (A1/C1/C2), perform C2 consistency checks, and produce a rendered managed region.
Parsing helpers
crates/ourios-bench/src/report.rs
parse_region, parse_header, and parse_row locate the managed region, extract per-block headers (sha, hw, date), and parse gate table rows into internal GateRow structures (A1/C1/C2 only).
Deterministic rendering and splicing
crates/ourios-bench/src/report.rs
render_region emits stable per-(sha,hw) blocks including only present gate rows; splice_region replaces an existing managed region or anchors a new ### Results under ## 9. Status, returning BenchError::Report for missing anchors or corrupt markers.
Markdown updater test suite
crates/ourios-bench/src/report.rs
Tests for first-run insertion under ## 9. Status, in-place rewriting without duplicate sub-headings, partial-gate reruns preserving prior rows, and error handling for absent section anchors, corrupt markers, malformed headers, inconsistent C2 state, malformed timestamps, multiple managed regions, and byte-for-byte preservation of prose outside markers.

Sequence Diagram

sequenceDiagram
  participant ResultsFile
  participant update_status_section
  participant parse_region
  participant render_region
  participant splice_region
  participant MarkdownFile
  ResultsFile->>update_status_section: provide ResultsFile
  update_status_section->>parse_region: parse existing managed region (if any)
  update_status_section->>update_status_section: merge gate rows for (git_sha, hardware_kind)
  update_status_section->>render_region: render deterministic managed region
  render_region->>splice_region: produce spliced markdown fragment
  splice_region->>MarkdownFile: replace or insert managed region in docs/benchmarks.md
Loading

Possibly related PRs

  • jensholdgaard/ourios#48: Documentation RFC that specifies the §9 managed-region contract this PR implements.
  • jensholdgaard/ourios#54: Introduces C2 accumulator/result wiring that the updater now reads and validates for C2 consistency.
  • jensholdgaard/ourios#53: Adds the original CLI plumbing and the prior warning-only --update-benchmarks-md flag that this PR activates end-to-end.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through markdown, nibbling at the rows,
Merged gates by sha and board where stable order grows.
Tests kept me honest, markers snug and neat,
Now benchmarks tuck in under section nine — how sweet! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature: implementing the benchmarks.md results appender with section §9 marker support.
Description check ✅ Passed The description comprehensively covers all required template sections with detailed technical implementation notes, test coverage, and verification results.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ourios-bench-benchmarks-md

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

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
crates/ourios-bench/src/main.rs (1)

10-13: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update stale “not implemented yet” docs for --update-benchmarks-md.

Line 10 and Line 64 still claim this path is unimplemented, but Line 154 now executes it. This makes module docs and CLI help misleading.

Also applies to: 63-65

🤖 Prompt for 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.

In `@crates/ourios-bench/src/main.rs` around lines 10 - 13, The module docs and
CLI help still state that the `--update-benchmarks-md` path is “not implemented
yet” even though the flag is executed at runtime; update the comments at the top
of main.rs (around the module doc comment at lines ~10 and the help text near
line ~64) to remove “not implemented yet” and instead describe the actual
behavior performed when `--update-benchmarks-md` is passed (i.e., that the
markdown appender runs and JSON results are written) so the CLI help and module
documentation match the code path executed later (the `--update-benchmarks-md`
handling around line ~154).
crates/ourios-bench/src/lib.rs (1)

11-13: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Refresh crate docs that still say markdown appender is pending.

Line 11 and Line 91 state this path is not implemented, but it is now wired in the binary and publicly re-exported.

Also applies to: 89-91

🤖 Prompt for 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.

In `@crates/ourios-bench/src/lib.rs` around lines 11 - 13, Update the crate-level
documentation text that still says the markdown appender is pending: remove or
reword the sentences referencing the unimplemented `--update-benchmarks-md` path
and the pending markdown appender, and instead document that the appender is now
wired in the binary and publicly available; update the mention near
`write_results_json` (and any adjacent comment blocks around the
`--update-benchmarks-md` flag) to reflect the implemented behavior and re-export
so users know the feature is present.
🧹 Nitpick comments (1)
crates/ourios-bench/src/report.rs (1)

337-362: ⚡ Quick win

Consider detecting malformed marker state to avoid silent corruption.

If REGION_BEGIN exists but REGION_END was manually deleted, the current logic falls through to the first-run path and appends a new region—creating duplicate BEGIN markers and corrupting the file further.

Detecting this edge case upfront would fail fast with a clear error instead:

♻️ Suggested validation
 fn splice_region(md: &str, region: &str) -> Result<String, BenchError> {
+    let has_begin = md.contains(REGION_BEGIN);
+    let has_end = md.contains(REGION_END);
+
+    if has_begin != has_end {
+        return Err(BenchError::Report {
+            detail: format!(
+                "docs/benchmarks.md has mismatched BENCH-RESULTS markers (begin={has_begin}, end={has_end}); \
+                 fix manually or regenerate the file"
+            ),
+        });
+    }
+
     if let (Some(begin), Some(end_rel)) = (
         md.find(REGION_BEGIN),
         md.find(REGION_END).map(|e| e + REGION_END.len()),
     ) {
🤖 Prompt for 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.

In `@crates/ourios-bench/src/report.rs` around lines 337 - 362, In splice_region,
add validation for mismatched region markers: if md.find(REGION_BEGIN).is_some()
but md.find(REGION_END).is None (or vice versa), return a BenchError::Report
with a clear message about malformed BEGIN/END markers instead of falling
through to the "first run" path; update the error text to mention the exact
marker names (REGION_BEGIN/REGION_END) and that the file may be corrupted so the
caller can fail fast—make this check at the top of splice_region before the
existing begin/end replacement logic that uses REGION_BEGIN and REGION_END.
🤖 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.

Outside diff comments:
In `@crates/ourios-bench/src/lib.rs`:
- Around line 11-13: Update the crate-level documentation text that still says
the markdown appender is pending: remove or reword the sentences referencing the
unimplemented `--update-benchmarks-md` path and the pending markdown appender,
and instead document that the appender is now wired in the binary and publicly
available; update the mention near `write_results_json` (and any adjacent
comment blocks around the `--update-benchmarks-md` flag) to reflect the
implemented behavior and re-export so users know the feature is present.

In `@crates/ourios-bench/src/main.rs`:
- Around line 10-13: The module docs and CLI help still state that the
`--update-benchmarks-md` path is “not implemented yet” even though the flag is
executed at runtime; update the comments at the top of main.rs (around the
module doc comment at lines ~10 and the help text near line ~64) to remove “not
implemented yet” and instead describe the actual behavior performed when
`--update-benchmarks-md` is passed (i.e., that the markdown appender runs and
JSON results are written) so the CLI help and module documentation match the
code path executed later (the `--update-benchmarks-md` handling around line
~154).

---

Nitpick comments:
In `@crates/ourios-bench/src/report.rs`:
- Around line 337-362: In splice_region, add validation for mismatched region
markers: if md.find(REGION_BEGIN).is_some() but md.find(REGION_END).is None (or
vice versa), return a BenchError::Report with a clear message about malformed
BEGIN/END markers instead of falling through to the "first run" path; update the
error text to mention the exact marker names (REGION_BEGIN/REGION_END) and that
the file may be corrupted so the caller can fail fast—make this check at the top
of splice_region before the existing begin/end replacement logic that uses
REGION_BEGIN and REGION_END.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f8f3e4f9-bcb3-4549-b49b-5adf0b1299f9

📥 Commits

Reviewing files that changed from the base of the PR and between 2877230 and 7bd27b7.

📒 Files selected for processing (3)
  • crates/ourios-bench/src/lib.rs
  • crates/ourios-bench/src/main.rs
  • crates/ourios-bench/src/report.rs

Copilot AI 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.

Pull request overview

Implements the missing --update-benchmarks-md workflow in ourios-bench by adding a pure markdown transform that merges a bench run’s results into docs/benchmarks.md §9 within a marker-managed region, and wiring the CLI flag to read/transform/write the doc.

Changes:

  • Added update_status_section(&str, &ResultsFile) -> Result<String, BenchError> to parse/merge/render the §9 managed results region, including tests for first-run insertion, in-place rewrite, partial-gate merge, and missing-anchor error.
  • Implemented the --update-benchmarks-md code path in the binary to update docs/benchmarks.md on demand.
  • Re-exported update_status_section from the crate API.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/ourios-bench/src/report.rs Adds the pure §9 markdown region parser/merger/renderer and associated unit tests.
crates/ourios-bench/src/main.rs Wires --update-benchmarks-md to read/transform/write docs/benchmarks.md.
crates/ourios-bench/src/lib.rs Re-exports update_status_section for use by the binary (and others).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/ourios-bench/src/report.rs Outdated
Comment thread crates/ourios-bench/src/report.rs Outdated
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread crates/ourios-bench/src/report.rs Outdated
Comment thread crates/ourios-bench/src/main.rs
Comment thread crates/ourios-bench/src/lib.rs
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread crates/ourios-bench/src/report.rs Outdated
Comment thread crates/ourios-bench/src/report.rs Outdated
Comment thread crates/ourios-bench/src/report.rs Outdated
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread crates/ourios-bench/src/report.rs Outdated
Comment thread crates/ourios-bench/src/report.rs
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread crates/ourios-bench/src/report.rs Outdated
Comment thread crates/ourios-bench/src/report.rs
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread crates/ourios-bench/src/report.rs
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread crates/ourios-bench/src/report.rs
@jensholdgaard
jensholdgaard merged commit a9cc4ec into main May 26, 2026
9 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