Skip to content

fix(amr): check the staged bytes after git add; read each folder once - #336

Merged
danielsimonjr merged 6 commits into
masterfrom
amr-staged-check
Nov 12, 2026
Merged

danielsimonjr merged 6 commits into
masterfrom
amr-staged-check

Conversation

@danielsimonjr

Copy link
Copy Markdown
Owner

Summary

  • AMR writer checks the staged bytes after git add: mode must be 100644/100755 (symlinks and gitlinks refused, also with core.symlinks=false); a staged oid that differs from the hash of the scanned bytes is size-checked with cat-file -s, then rescanned from cat-file blob with the same patterns. Every git call adds --no-replace-objects; the allow-list ignores inherited keys.
  • Secret patterns load once per writeAmrFiles / commitAmrEdits call.
  • planTarget reads each folder once per batch (5000 files in one folder: check loop 14.4 s -> 7.2 s; commitAmrEdits 54.6 s -> 48.5 s; git add 38 s unchanged).
  • Remaining gap (documented): a process writing the index between the check and git commit.

Tests

AMR suite 457 passed, 4 skipped. Mutation checks: removing the staged verify fails 7 tests, removing the mode check fails 4, removing the size check fails the grows-past-limit test. The full local suite timed out once in AmrSync F11 (1000+ relations), which takes 8.3 s on master and 9.0 s here when run alone; filed as a todo row.

Gates

typecheck, lint, tools:check-census, tools:check-duplicates, repo-tools check (30 claims), repo-tools docs check (2169/2169).

junior chain run: yes. Worker Haiku (claude-haiku-5-5): 1 of 1 candidate accepted after fixes (report generation redone with tools:deps). Challenger Haiku: 10 findings, 8 accepted by the reviewer. Reviewer Sonnet: 10 verdicts plus 3 own findings, fixes applied by Opus.

🤖 Generated with Claude Code

danielsimonjr and others added 6 commits November 12, 2026 13:11
…once

Close the gap between the secret scan and `git add`. After `git add`, the writer
compares the blob id of each staged entry with the hash of the bytes it scanned.
A matching id passes without a read. Any other id is read with `git cat-file`,
size first, and scanned again with the same check as the first scan. A symlink,
a gitlink or an unmerged entry refuses the commit with `stage-mismatch`.

GitRunner allows exactly `ls-files -s -z -- <paths>`, `cat-file -s <oid>` and
`cat-file blob <oid>`. `commitFiles` takes an optional verify hook. The hook runs
after `add` and before `commit`.

A write batch or a commit reads each folder once, not once per file. A refused
new file that became a symlink is removed as a link.

Not covered: a process that writes the index between that check and `git commit`.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
… map

f3c012c wrote the docs/architecture reports with repo-tools map. CI regenerates
them with tools:deps and fails the census on that output. This restores the
generator output; the diff against master is now 38/28 lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… pattern load)

- isAllowed reads only own keys of ALLOWED_OPTIONS, so constructor,
  __proto__ and toString are refused.
- Every git call adds --no-replace-objects, so a replace ref cannot
  change the bytes that cat-file reads in the rescan.
- commitAmrEdits loads the secret patterns once per call; a bad file
  gives bad-patterns with no path and stages nothing.
- Tests: sha256 repositories, core.symlinks=false swaps, an autocrlf
  secret, the case-variant split by file-system probe, and the
  size-limit path makes no cat-file blob call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
writeAmrFiles without opts.patterns loaded the patterns once per file and
again in the staged rescan. Load them once, refuse bad-patterns with no path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…load row

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
importAmr saved the storage file once per new entity. On a Windows CI runner the
F11 import test (1002 files) took 11 s and once ran past its 60 s limit. Batches
of up to 1000, with a one-by-one retry of a failed batch: 5.6 s -> 0.9 s here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danielsimonjr
danielsimonjr merged commit 2d91b57 into master Nov 12, 2026
9 checks passed
@danielsimonjr
danielsimonjr deleted the amr-staged-check branch November 12, 2026 20:11
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