Repository navigation
fix(claude-memory): bound the frontmatter strip's byte limb in memory-dir-stats - #2042
Conversation
…-dir-stats The audit skill's M1 index-size check bounded its frontmatter block by grammar and by line count but never by weight, and markdown prose opening `Note:` or `Important:` is a well-formed `key:` mapping entry. A MEMORY.md opening with a `---` thematic break, carrying one long paragraph, and reaching any later `---` had that paragraph stripped however much it weighed: a 26,020-byte index reported 5 loaded bytes, disarming a [FAIL]-severity gate on its 25KB limb exactly as the line cap already prevented on the 200-line limb. Bounds the block a third way, by `fmbytecap` bytes of held content. The 1KB cap is calibrated against what real frontmatter weighs — Claude Code stamps only a `modified` scalar — so a real block still strips whole, while the residue it leaves is the smaller share of M1's two limits (1KB of 25KB, against 20 lines of 200). Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HbtPzLRe1yBavNpsmv5Tum
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
Claude finished @kyle-sexton's task in 1m 12s —— View job Security review complete
Scope reviewed: the 5 files changed in this PR ( Findings: none. This PR only touches
No CRITICAL, IMPORTANT, or SUGGESTION-level security findings on this diff. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c9c5a4ac5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…characters awk's length() counts characters under a multibyte locale, so a heavy multibyte frontmatter line slipped under fmbytecap and resurrected the under-count the cap exists to stop. LC_ALL=C on the awk pass pins byte semantics; a 900-character / 1800-byte fixture now guards it. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HbtPzLRe1yBavNpsmv5Tum
…ory-frontmatter-byte-cap # Conflicts: # plugins/claude-memory/.claude-plugin/plugin.json # plugins/claude-memory/CHANGELOG.md
|
Claude finished @kyle-sexton's task in 3m 42s —— View job Review complete
Scope: the 5 files changed in this PR, diffed against The core logic change — a third Two maintainability findings, posted inline:
No other correctness, architecture, or test-coverage issues found in |
|
Claude finished @kyle-sexton's task in 1m 13s —— View job Security review complete
Scope reviewed: all 5 files changed in this PR, diffed against Findings: none. What changed
Security-relevant properties checked
No CRITICAL, IMPORTANT, or SUGGESTION-level security findings on this diff. (One cosmetic note outside this review's scope: |
|
Claude has reviewed this PR 3 times. The lane skips further automatic reviews after 5; deleting this comment resets the count. |
SC2292 on the [ ] test in the WIDE generator; an arithmetic for-loop replaces it. No behavior change; suite green. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HbtPzLRe1yBavNpsmv5Tum
|
Claude finished @kyle-sexton's task in 1m 25s —— View job Security review complete
Scope reviewed: the 5 files changed in this PR, diffed against Findings: none. What changed since the prior security pass on this PRThe only new commit since the last full review is Re-verified properties (unchanged from the earlier review, spot-checked directly)
No CRITICAL, IMPORTANT, or SUGGESTION-level security findings on this diff. |
|
Claude finished @kyle-sexton's task in 6m 55s —— View job Review complete
Scope: all 5 files changed in this PR, as of HEAD Core logic is sound. The third One correctness finding, verified independently (posted inline on Two findings carried over from the prior review pass, still unresolved (both re-flagged inline, since the intervening commit only touched the test file):
No other correctness, architecture, or test-coverage issues found in |
…ndent, changelog predecessor The multibyte fixture had been re-encoded to a four-byte mojibake sequence that exceeded the cap in characters as well as bytes, guarding nothing; it is now ASCII octal escapes, 600 reps (600 chars under the 1024 cap, 1200 bytes over it). The version line regains its 2-space indent, and the entry parenthetical cites the immediate predecessor 0.5.9. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HbtPzLRe1yBavNpsmv5Tum
|
Claude finished @kyle-sexton's task in 1m 10s —— View job Security review complete
Scope reviewed: all 5 files changed in this PR, diffed against Findings: none. What changed since the last security passThe only new commit,
Re-verified properties (unchanged from earlier passes, spot-checked directly against current HEAD)
No CRITICAL, IMPORTANT, or SUGGESTION-level security findings on this diff. |
|
Claude finished @kyle-sexton's task in 1m 43s —— View job Review complete
Scope: all 5 files changed in this PR, as of HEAD All three carried-over findings are now resolved. I independently re-checked each:
Core logic (
I was not able to execute No new findings. Nothing outstanding from this or prior review passes. |

No linked issue
Summary
memory-dir-stats.shbounds the frontmatter block it strips from the M1 index-size counts by grammar (blank lines andkey:mapping entries only) and by line count (fmcap = 20), but never by weight. Markdown prose openingNote:,Important:, orTODO:is a well-formed mapping entry, so aMEMORY.mdthat opens with a---thematic break, carries one long paragraph, and reaches any later---had that paragraph stripped however much it weighed.M1 is a
[FAIL]-severity size gate that a low count always passes, so the shape disarmed the gate's 25KB limb outright — the same disarming the line cap already prevents on the 200-line limb (memory-dir-stats.test.sh's "a key:-shaped runaway is bounded by length").Fix shape chosen: (a), a byte cap analogous to
fmcapfmbytecap = 1024bytes of held block, checked alongside the existing line and grammar bounds. The existing abandon path re-emits the held lines as content and lets the current line fall through to fence/comment handling, so no new branch was needed.Why (a) over (b), accepting the residual. The motivating case is not a
MEMORY.mdwith genuinely huge YAML frontmatter — for that, reporting the post-strip figure is arguably correct under M1's own post-strip reading, which is the whole of (b)'s argument. The motivating case is that the grammar misparses ordinary markdown prose as frontmatter. That is the identical risk classfmcapalready exists to bound; the line limb bounded it and the byte limb did not. (b) would accept an unbounded under-count on a[FAIL]gate whose own documented direction (criteria.mdM1 Provenance) is to guess toward counting: "an over-count can only make the gate fire early on a file near its limit, while an under-count stops it firing at all."Why 1KB. The cap's job is to separate plausible real frontmatter from misparsed prose, so it is calibrated against what real frontmatter weighs, not against 25600. Claude Code stamps only a
modifiedscalar (~40 bytes) and never adds frontmatter to a file that has none; even a generous hand-written twenty-entry block runs to a few hundred bytes. 1KB clears both by a wide margin.Coherence with the M1 25KB limb. Every bound leaves a residue — a misparsed block still strips up to the cap before the bound ends it. 1024/25600 is 4%, tighter than the line limb's own residue of 20/200 = 10%, so the new bound is strictly no looser than the bound it is modeled on. It is also the same order as the ~1% CRLF discrepancy M1 reading 4 already accepts as immaterial.
LC_ALL=Cwas deliberately not added: the reported byte count already comes fromwc -con awk's output and is byte-exact regardless of locale. The locale would only affect the new cap, which is a bound rather than a measurement, and changing it would alterindex/substr/character-class semantics on every existing path. The cap is measured in characters — byte-exact for the ASCII a memory-index frontmatter is made of, and merely looser (still finite) otherwise. The script comment records that.The script's direction sentence ("They bound the block by shape and by line count, never by bytes — a short
key:-shaped block ... is stripped whatever those entries weigh") became flatly false and was rewritten;criteria.mdM1 reading 1 gained the byte limb, andcriteria.mdbumped 1.5.2 → 1.5.3 alongside.Test plan
The script has a self-contained regression harness (
memory-dir-stats.test.sh), so this matches the plugin's existing bar rather than declaring a coverage gap. Cases were added next to the existing line-bound case, as its byte sibling:a heavy one-line runaway is bounded by weight/... counts every line— the reproduction fixture, expectations written as the file's ownraw_bytes()/raw_lines()so nothing may be stripped.frontmatter under the weight cap still strips— fifteenkey: valueentries totalling ~709 bytes, proving the fix cannot regress into never stripping.Before (26,020-byte
MEMORY.md:---/ oneNote: xxx…line /---/body):After:
Gates run from the worktree, all green:
memory-dir-stats.test.sh— 63/63 checks pass (was 60 before the three new assertions)scripts/check-changelog-parity.sh --check— passscripts/check-changelog-parity.sh --check-bump origin/main— passscripts/check-changed-skills.sh origin/main— 3 skills checked, 0 failedscripts/check-shell-portability.sh origin/main— no unexcused GNU-only constructsscripts/check-silent-skips.sh— passmarkdownlint-cli2 "plugins/claude-memory/**/*.md"— 0 errorsshellcheckon both changed shell files — cleanRelated
Refs #1989 row 250 — third surfacing of the byte-limb question. The tracking issue carries many rows, so this PR closes no issue on merge. The G4 grammar narrowing (0.5.7) reduced exposure by making fewer shapes parse as frontmatter, but left the byte limb unbounded; this closes it.
Version:
plugins/claude-memory0.5.7 → 0.6.0 (behavior change), centrally allocated. A sibling PR from the same batch claims 0.5.8, so the gap in this plugin's changelog is expected rather than a missing release.