Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. What this changesThis PR replaces reclaimable directory locking for shared Git history prefetches with kernel locking, a directory fallback, and a bounded legacy-owner wait. Example: Two linked worktrees run git log --stat against different cold historical files while a stale legacy lock marker exists.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep this PR open: the earlier timeout finding is resolved and the Linux runtime evidence is sufficient, but the kernel and fallback mutexes can admit concurrent fetches into the same object store. Priority: P2 Decision needed
Before merge
Findings
Agent review detailsHow this fits togetherThe agent Git PATH shim discovers missing historical blobs in shared partial clones, coordinates their prefetch, and then executes the requested Git command with the existing offline-search policy. flowchart TD
A[Agent Git command] --> B[Git PATH shim]
B --> C[Discover missing blobs]
C --> D[Wait for legacy owner]
D --> E[Acquire prefetch mutex]
E --> F[Recheck and fetch blobs]
F --> G[Execute requested Git command]
Technical reviewBest possible solution: Keep serialization in the existing prefetch owner with one interoperable mutex and an owner-approved recovery contract for systems lacking descriptor-lock support. Do we have a high-confidence way to reproduce the issue? The supplied real-Git trace demonstrates the original reclaim overlap and corrected Linux serialization; source inspection independently establishes that mixed kernel and fallback callers remain mutually uncoordinated. Is this the best way to solve the issue? Kernel locking removes the reclaim race within the existing owner, but an independently named directory fallback defeats shared serialization when callers have different locking-tool availability. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6ad60f571591. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +41, Tests +386. Total +427 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 17, 2026, 12:39 PM ET / 17:39 UTC (Revision 2). |
The git shim serialised lazy history hydration with a mkdir directory lock, an owner pid file, a thirty-second attempt bound and a kill-based reclaim. That protocol unlinks and re-creates the lock: a waiter that decides an owner is dead removes the record and the directory, so it can remove the lock a successor has just created and two callers can then fetch into one object store at the same time. Replace the protocol with a kernel lock on a file the shim never unlinks: flock(1) on the open descriptor on Linux, lockf(1) elsewhere. With no unlink there is no reclaim step and no interval in which two callers both believe they own the lock. A directory marker left by an older shim is still read so an in-place upgrade keeps its ordering; a stale record is ignored, never reclaimed. Test: six linked worktrees race two disjoint object sets through a wrapper that journals fetch boundaries, and the journal must alternate enter and leave.
kill -0 only shows that a pid exists, never that it is still an old shim. A leftover pid record whose pid was reused by a long-lived process of the same user made every content search spin on the marker for good. The previous candidate kept the wait after the kernel lock, so N callers queued for k x 30 s. Move the bounded wait before the kernel lock so parallel callers time out together, and give the prefetch up when it expires: non-show content searches take the failed-preparation path, running offline with the budget error instead of starting a competing lazy fetch beside the old owner. Show keeps its speculative native fallback. Run the kernel open and lock in a nested subshell so a failed exec falls back instead of ending the prefetch. Keep a portable mkdir mutex, without the old reclaim step, for systems where flock or the lockf descriptor form is unavailable. Cleanup only removes the record while the process still owns the pid file. The fallback directory lives in the git-common-dir, not in a linked worktree's .git file. If the owner is killed before cleanup, stop every process that may use it and remove it with rm -r "$(git rev-parse --git-common-dir)/openclaw-history-blobs.lock.fallback". The kernel lock and this mutex are different paths, so environments that resolve different binaries do not exclude each other. Test: a legacy marker holding a live pid must return, a marker that disappears before the bound must release the wait and fetch, a stale marker with a delayed reclaim must serialise two readers, a failed or missing flock must fall back, two fallback readers must serialise and remove the marker, and an orphaned fallback marker must expire without removing it. The timeout tests drive the 300-iteration wait through a fake sleep wrapper instead of real 30 s waits; the real 30 s and 45 s measurements stay in the proof script.
f2dd84f to
a097fae
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Could a maintainer clarify two compatibility requirements before I revise the lock?
|
Related: #198531
What Problem This Solves
Concurrent
git log -Sandgit blamehistory reads can start overlapping blob fetches into one shared object store when an older shim'sopenclaw-history-blobs.lockmarker is present, and a leftover marker whose pid was reused by an unrelated live process makes every content search wait on it forever.User Impact
Agents in linked worktrees share one history-prefetch lock: one fetch runs at a time, and a stale legacy marker costs at most 30 s per invocation instead of blocking every later search. The bounded wait now runs before the kernel lock, so N parallel callers wait 30 s together rather than k x 30 s in lock order. When the wait expires, that invocation skips the prefetch: non-show content searches run offline and exit 2 with the budget guidance, while
showkeeps its speculative native fallback. The marker is never removed, so the 30 s cost repeats while the pid lives. There is no user-visible UI change.Why This Change Was Made
prepare_blobsserialised prefetches with amkdirdirectory lock plus an ownerpidfile. That protocol removes and recreates the lock pathname: a waiter that decides the owner is dead deletes the record and the directory, so it can delete the lock a successor has just created and two callers can then fetch into the same object store at once. A leftoverpidvalue that now belongs to a live process also resets the attempt counter forever. In the base, a live old owner reset that counter and the wait had no bound.The lock is now a kernel lock on a file the shim never unlinks. The open and the lock run in a nested subshell so a failed
execcannot end the caller and the fallback stays reachable:The kernel lock file stays in
.gitas an empty file; it is never removed. With no unlink there is no reclaim step and no interval in which two callers both believe they own the lock. The descriptor is opened inside theprepare_blobssubshell, so the kernel releases the lock when the subshell exits and no cleanup trap is needed.An old shim cannot see the kernel lock: an old process that starts while a new prefetch is running can still create its directory marker and fetch beside it. The upgrade window is one-sided. The new side reads the old marker before taking the kernel lock and serves a live owner first; that orders the common case without changing processes that are already running. A live old owner with a large batch used to wait without bound; the new side ends the wait after 30 s, skips its own prefetch, and leaves the old owner to finish.
Because
kill -0only shows that a pid exists, the legacy wait keeps the 300-iterationsleep 0.1bound the directory lock had. It runs before the kernel lock, so parallel callers time out together instead of queueing for another 30 s each. A timed-out caller skips the prefetch;prepared_blobsis already set for non-show content searches, so they take the failed-preparation path (offline, exit 2, budget error) rather than starting a lazy fetch beside the old owner.showkeeps the speculative native fallback that #198531 gives it.If
flockorlockf -sis missing, or the platform rejects the descriptor form, the shim falls back to anmkdirmutex without the old reclaim step. Cleanup removes the record only while the process still owns the pid file, so it cannot delete a successor's lock. If the fallback owner is killed before cleanup, the directory stays permanently; every later prefetch on that path waits 30 s and skips until it is removed. The directory lives in the git-common-dir, not in a linked worktree's.gitfile. Stop every process that may use it, then remove it withrm -r "$(git rev-parse --git-common-dir)/openclaw-history-blobs.lock.fallback". This keeps a clean system working instead of turning every content search into exit 2. Thelockf -s fdform exists in FreeBSD since December 2023; the minimum macOS version is UNKNOWN, and older userlands take the fallback.The kernel lock and the fallback mkdir mutex are different paths. Two environments that share a
.gitbut resolve different binaries, for example a container with a bind mount and its host, do not exclude each other; the old directory marker is the only cross-environment signal.Scope: two files, +450/-23. The shim replaces the twenty-line reclaim protocol with the kernel lock, the portable fallback, and the bounded legacy read; the history test adds the stale-marker race, the fallback cases, the release-before-limit path, and the updated legacy timeout. The reproduction script stays out of the diff and is in the collapsed block below.
Evidence
Environment: ephemeral Ubuntu 26.04.1 sandbox (kernel 6.12.114, node v24.22.3, git 2.53.0). Base
22614d5b0e81fc68cbbbf6bdcdd34301a3e02658; patch applied on a clean tree;git write-tree=12ab4e144960048691edd2a96aaaab64ab492b51.Focused tests:
node scripts/run-vitest.mjs run src/infra/agent-git-shim.history.test.ts --maxWorkers=1node scripts/run-vitest.mjs run src/infra/agent-git-shim.test.ts --maxWorkers=1node scripts/run-tsgo.mjs -p tsconfig.core.json --incrementalnode scripts/run-format.mts --checkoxlint --config .oxlintrc.jsonon the shim and the history testcheck-test-lines-ratchet.mtscheck-max-lines-ratchet.mtsgit diff --checkThe timeout tests use a fake
sleepwrapper to assert the 299-iteration bound and the release-before-limit path without real 30 s waits; the real 30 s and 45 s measurements are in the proof script below.Behavior, before and after. Real shim, real Git subprocesses, two linked worktrees, local
file://fixture; no network, credentials, or private paths. A path wrapper journals every fetch boundary and holds the fetch open long enough that an overlap cannot hide inside a few milliseconds. The reclaim runs use the same dead marker and the same delayedrmon both shims, so the comparison is symmetric. The journal is ordered by append order, not by wall-clock timestamps.enter,enter,leave,leave). This is the failure the kernel lock removes.rm: the dead pid is ignored, the kernel lock serialises the two readers (enter,leave,enter,leave), so the old reclaim window is gone.git log -S: after 30,472 ms the prefetch is skipped, the command exits 2, printsOpenClaw: content search could not finish within the shared partial-clone blob budget; command stopped without lazy fetching..., and creates no pack.kill -0succeeds, so the command did not return and was killed by a hard 45 s timeout.The trace is reproducible with the script in the collapsed block below; save it outside the checkout, pass the base ref as the first argument (or set
OPENCLAW_BASE), and run it from the repository root. The script prints the journal, the elapsed times, and the exit codes for all four runs.Not run: macOS and FreeBSD
lockf -s 9(only Linux executed; the descriptor form is documented by Apple and FreeBSD, and the fallback covers older userlands); Windows is not materialised for this shim.Reproduction script (history-lock-proof.mjs)