fix(graph): self-heal tree-sitter deps on existing installs from session start#326
Conversation
Prepares ensureGraphDeps to run unattended from session hooks: - Ownership-safe install lock: mkdir lockdir with an owner token; release only removes our own lock, stale reclaim (30 min) re-acquires instead of clobbering a live owner, and the lock mtime is refreshed before npm and before the heal so a long install is not reclaimed mid-flight. - The ready marker is deleted BEFORE any repair mutation and re-stamped only after BOTH npm install and the native heal succeed, keyed by spec set + platform + arch + Node ABI - a crash mid-repair leaves no marker. - Heal is strict: a missing ensure-tree-sitter script is a failure, and the script runs with HIVEMIND_STRICT_POSTINSTALL=1 so a failed bindings load exits non-zero instead of stamping a broken install as ready. - Offline backoff: a failed attempt is recorded (.graph-deps.attempt) and retried at most every 6h, so network-less machines do not spawn an npm install on every session; the satisfied fast path never touches it and spawns no subprocess at all.
The graph auto-build hook resolves tree-sitter from the shared ~/.hivemind/embed-deps, but ensureGraphDeps only ran from 'graph init' and 'embeddings install' - installs that predate #323 never run either, so their graph-on-stop hook degrades to a skip forever (verified on a real machine: 0 tree-sitter packages, every session end logging "build threw: Cannot find package 'tree-sitter'"). Spawn a detached graph-deps worker from the claude-code and codex session-start-setup paths, before the credentials gate (provisioning is local): the hook returns immediately (the 120s async allowance never bounds the npm install), the install lock serializes concurrent sessions, and the codex setup worker now spawns unconditionally with credentialed remote setup still gated inside the worker.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (12)
📝 WalkthroughWalkthroughGraph-dependency provisioning now uses readiness markers, locking, retry backoff, and strict native healing. Claude Code and Codex session hooks launch a bundled detached worker before credential-gated setup, with tests covering provisioning and spawn behavior. ChangesGraph dependency provisioning
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Coverage ReportScope: files changed in this PR. Enforced threshold: 90% per metric (per file via
File Coverage — 5 files changed
Generated for commit e27118f. |
Problem
#323 provisions tree-sitter into the shared
~/.hivemind/embed-deps, butensureGraphDepsonly runs fromhivemind graph initandhivemind embeddings install. Installs that predate #323 never run either, so the graph-on-stop auto-build stays dead forever. Verified on a real machine running deployed 0.7.138: 0 tree-sitter packages in embed-deps and every real session end loggingbuild threw: Cannot find package 'tree-sitter'.Fix
Commit 1 — harden
ensureGraphDepsfor unattended use:HIVEMIND_STRICT_POSTINSTALL=1so a failed bindings load can't stamp a broken install as ready.Commit 2 — self-heal wiring:
graph-deps-worker(claude-code + codex bundles) spawned from session-start-setup BEFORE the credentials gate (provisioning is local). The hook returns immediately — the 120s async allowance never bounds the npm install; the lock serializes concurrent sessions.CLI paths (
graph init,installEmbeddings) keep callingensureGraphDepsinline as before.Validation (real harness)
Fresh sandbox HOME with empty embed-deps, real interactive claude session with this build via
--plugin-dir:gate: FIRE, snapshot json written) — on a machine state that pre-fix could never auto-build.tscclean,npm run buildclean (new worker bundled for cc + codex).cli-bundle-runtimeenv flake fails (its baregraphexit-code assumption; unrelated).codex reviewof the diff: initial round's 5 blockers (lock ownership, marker invalidation on repair, heal false-success, 120s hook cap vs sync npm, offline retry storm) all addressed as above.Session Context
Session transcript
Summary by CodeRabbit
New Features
Bug Fixes