Skip to content

fix(structure): no stdin-piped hashing and no unbounded Git calls in the commit hook - #168

Merged
kaanozhan merged 1 commit into
mainfrom
fix/structure-hook-hash-in-process
Oct 1, 2026
Merged

kaanozhan merged 1 commit into
mainfrom
fix/structure-hook-hash-in-process

Conversation

@kaanozhan

Copy link
Copy Markdown
Owner

During a commit on 2026-10-01, the pre-commit hook (update-structure.js --staged) blocked the commit for 170 s:

  • git hash-object --stdin, called by STR-02c's mirror step to hash the tracked map on disk, sat in read() waiting for stdin to close, while node waited inside spawnSync.
  • Killing the stuck subprocess let the commit finish, with "mirror": "failed" recorded.
  • The same command outside a commit (0.3 s) and a 1 MB-map commit in a temporary repository (0.4 s) did not reproduce it, so the root cause looks environmental. A commit hook must never hang the commit either way.

Changes (scripts/structure-commit.js)

  • blobId(bytes, like): Git's blob id computed in process (sha1("blob <len>\0" + bytes), or sha256 when compared with a 64-hex id). It replaces the three hash-object --stdin calls that piped the whole map through Git: the disk-vs-staged check in mirrorToDisk, repairPathspecIndex, and reconcileTrackedMap. No filters applied to --stdin before either, so the result is identical.
  • Every git() call has a 60 s limit (SIGKILL). A stuck call fails the run with reason git-timeout, the hook's || true lets the commit through, and the receipt records it, so check-freshness reports that the commit kept the previous map.

Tests

  • blobId equals git hash-object for empty, JSON and binary/UTF-8 bytes, and follows a SHA-256 id.
  • A fake git that sleeps fails within the limit with git-timeout.
  • npm test: 1111 passing.

@kaanozhan
kaanozhan merged commit 774beb2 into main Oct 1, 2026
2 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.

1 participant