Files
boxmaker/docs/plans/M5a/16-memoryd-no-slicing.md
T
kyleandClaude Opus 5.5 d707be072d M5a plan: tasks 16 and 17, the review's nits
Task 16: memoryd takes the day and the month of a time with str::get, never a
slice. Task 17: repeated error lines in memoryd, proto, brokerd and bxctl
written once. Neither changes behaviour. Both were applied to a scratch tree
from 5f82260: the gate passes with 936 tests, and four mutations of the new
helpers are caught by the existing tests. The README runs with OPENCODE_MODEL.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 16:41:44 -07:00

2.9 KiB

M5a task 16: memoryd takes the day and the month with get, not by slicing

Branch: m5a (run git switch m5a; git status --short must be empty, otherwise stop) Commit subject: memoryd: the day and the month of a time with get, never a slice

Goal

No behaviour change. Four files of memoryd cut the day (2026-09-24) or the month (2026-09) out of to_rfc3339() with a slice such as &rfc[..10]. AGENTS.md forbids indexing that can go out of range in library code. The time is always long enough, so none of these can panic today, but two of them rely on that without a check. All five places become str::get with a fallback, which cannot panic whatever the string is. Found in the M5a review (2026-09-24).

Files

  • Modify: crates/memoryd/src/notes.rs, crates/memoryd/src/journal.rs, crates/memoryd/src/review.rs, crates/memoryd/src/recall.rs, docs/implementer-log.md
  • No test changes: the existing tests cover every line changed.

The edits, exactly

Nothing else in these files changes. Leave the comments above each line as they are.

1. crates/memoryd/src/notes.rs, in minute, the two lines

    let head = if s.len() >= 16 { &s[..16] } else { &s };
    format!("{head}Z")

become the one line

    format!("{}Z", s.get(..16).unwrap_or(&s))

2. crates/memoryd/src/journal.rs, in append, the five lines

    let day = if rfc.len() >= 10 {
        &rfc[..10]
    } else {
        "0000-00-00"
    };

become

    let day = rfc.get(..10).unwrap_or("0000-00-00");

and, further down in the same function, the line

    let month = &day[..7];

becomes

    let month = day.get(..7).unwrap_or("0000-00");

Leave &all[all.len().saturating_sub(count)..] in log as it is: its start is never past the end.

3. crates/memoryd/src/review.rs, in submit, the line

    let day = &rfc[..10];

becomes

    let day = rfc.get(..10).unwrap_or("0000-00-00");

4. crates/memoryd/src/recall.rs, in recall, the line

    let month = &rfc[..7];

becomes

    let month = rfc.get(..7).unwrap_or("0000-00");

Steps

  • 1. Make the five edits. Run cargo fmt --all.
  • 2. Check none is left. grep -nE '\[\.\.[0-9]+\]' crates/memoryd/src/*.rs prints nothing.
  • 3. Run the tests. cargo test -p memoryd: every suite passes.
  • 4. Run the gate. make gate. Expected last line: gate: ok, with 936 tests, the same as before this task.
  • 5. Log and commit. git add crates/memoryd docs/implementer-log.md && git commit

Done when

  • make gate prints gate: ok, and step 2's grep prints nothing.

Stop and report if

  • Any line quoted above is not in the file exactly as shown.
  • Any test fails. This task changes no behaviour, so a failure means an edit is wrong; do not change a test.