Repository navigation
fix(path): keep asynchronous canonicalization off the Node event loop - #1053
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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed2de0c62c
ℹ️ 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".
| // Missing prefixes, long link chains and errors retain the walker's contract. | ||
| } | ||
| } | ||
| const reads = resolvePrefix(input); |
There was a problem hiding this comment.
Preserve the anchored path when falling back to component traversal
On Node POSIX, if process.chdir() runs while the initial metadata probe is pending, a failed probe falls back to resolvePrefix(input), which anchors the relative input again using the new working directory. This can return a completely different file rather than the missing suffix in the originally requested directory. Reproduced by calling resolvePathPrefix('missing') from directory A and immediately changing to directory B containing that filename: the result reports B's existing file. Capture the absolute path once and pass that same path to the fallback walker.
Useful? React with 👍 / 👎.
|
Codex review: needs changes before merge. What this changesThis PR adds asynchronous prefix resolution and moves absolute-read canonicalization onto asynchronous Node filesystem APIs. Example: Resolve /srv/data/future/file.json while filesystem metadata is slow.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 2 items remain Keep this maintainer-authored PR open: asynchronous path resolution has clear value, but the fallback can resolve against the wrong directory and the new export breaks benchmark coverage. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherAdvanced path helpers turn caller-supplied paths into canonical path observations; guarded Root operations separately own authorization and filesystem effects. flowchart TD
A[Caller path] --> B[Advanced path API]
B --> C[Async existing path probe]
C --> D[Shared component walker]
C --> E[Runtime canonicalization]
D --> E
E --> F[Canonical path observation]
F --> G[Caller or guarded Root operation]
Technical reviewBest possible solution: Retain the shared traversal owner, anchor input once before awaiting, and register the new async API with the existing benchmark owner. Do we have a high-confidence way to reproduce the issue? Source shows both synchronous canonicalization on main and the introduced fallback race; the existing review supplies the same A-to-B working-directory scenario, but this read-only review ran no target code. Is this the best way to solve the issue? Sharing the existing walker and preserving runtime-specific canonicalization is appropriate, provided the fallback retains its initial path anchor and the export is integrated with benchmark coverage. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 92f296e85810. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Review metrics
LabelsLabel 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 Reviewed October 31, 2026, 3:38 PM ET / 19:38 UTC. |
What Problem This Solves
Fixes event-loop stalls when asynchronous path preflight waits on slow filesystem metadata:
resolveAbsolutePathForReadcurrently calls synchronous realpath, and prefix resolution offers only a synchronous component walk.User Impact
Consumers can await
resolvePathPrefixthrough the advanced API, and existingresolveAbsolutePathForReadcallers use asynchronous Node canonicalization. Sync prefix resolution remains available. Physical symlink traversal, raw missing suffixes, permission errors, and non-directory rejection retain their contracts.Bun POSIX canonicalization and Windows AppContainer fallback retain the existing synchronous native-realpath owner for platform compatibility; those fallback paths remain potentially blocking. No dependency or version change is included.
Why This Change Was Made
One walker owns traversal for both APIs. Synchronous calls execute their IO directly; the async fallback yields awaited IO operations. Node POSIX existing paths use kernel
lstatand canonicalization without separate ancestor inspections, with a target-search-permission check for final symlinks. A proven missing leaf with clean normalized spelling probes only to the nearest existing non-symlink directory. Dangling links, raw dot/separator forms, and uncertain failures retain the component algorithm.There is no cache or new authority policy: these are observations, and guarded Root operations still own later effects. Production source grows by 79 lines for the async API/driver, bounded fast paths, and preserved runtime-specific canonicalization behavior.
Evidence
The absolute-read regression fails against the original owner with
blocking realpathand passes with the fix. Nine focused path/security files passed: 123 tests, 5 platform skips, 1.12 seconds in the final source run. Coverage includes pending asynchronous metadata, physical symlink parents, raw missing suffixes, replaced aliases, direct dangling links outside the starting directory, permission-denied traversal, loops, non-directory errors, and absolute-read symlink policy.pnpm checkpassed file-size and filesystem-boundary lints and TypeScript compilation, then stopped at the missing Cargo/WASM toolchain; the local machine also lacks the pinned .NET SDK for the Windows helper. Full local check is incomplete. Final targeted TypeScript compilation, documentation examples, andgit diff --checkpassed. The public API manifest was regenerated by its owner. Independent Codex review found no actionable P0–P2 findings. Initial-head CI found the new export missing from benchmark coverage; the final head registers it, and the filtered runner passed all four prefix cases. Exact source head32a19880de089cef5a5a620fd49d46808eee7efchas 51 successful checks and 5 skipped, with no pending or failed checks. CI provides the full platform/build/package validation.Measurements
The final consumer scope moves only prefix canonicalization and sandbox raw-path resolution to async IO, reuses prepared prefixes within one owner invocation, and removes duplicate caller-side mutation checks while retaining the effect owner's guard. Git metadata lstat and ordinary-realpath handling retain their existing synchronous contract. There is no whole-Gateway zero-sync-filesystem claim.
Acceptance: five interleaved A1/B/A2 batches, 200 selections/batch; count prefix traversal and timer delay under injected 100 ms prefix latency, with allocation sampling and single delayed selections measured separately. Require nonblocking prefix IO, preserved security, and no material CPU/allocation/elapsed regression. The narrowed scope meets this rule; broader metadata conversion was rejected.
The combined source and prepared OpenClaw owner experiment uses 62,000 synthetic workspace files totaling 1.116 GB on APFS, Node 26.12.1/Darwin arm64. These are owner measurements, not a live Gateway or btrfs result. Source and consumer inputs were pinned for the final campaign.
Values are medians of five batch means. One synchronous Git lstat and two ordinary metadata realpaths remain per selection. These are JavaScript-call counters, not a complete kernel syscall census. Existing-root elapsed ranges were 0.254–0.375 / 0.257–0.553 / 0.243–0.338 ms for A1/A2/B. Nested-parent elapsed ranges were 0.272–0.397 / 0.237–0.695 / 0.240–0.532 ms for A1/A2/B. Missing-parent elapsed ranges were 0.269–1.212 / 0.248–8.088 / 0.259–0.886 ms for A1/A2/B. Nearest-rank batch p95 equals each range maximum with five samples. Allocation falls about 22–23% for the root shape and 16% for missing parents. Missing-parent elapsed median changes by 0–6%; main CPU improves and total CPU is flat or lower. No release, dependency change, or deployment is included in this source PR.
The retained synchronous API has its own committed control:
Five A1/B/A2 batches on Node 24.22.1/Darwin arm64, 1,000 resolutions each. Existing paths retain 7 lstat + 1 realpath; missing paths retain 8 + 1. Existing-path main CPU is 45.72/49.06 → 43.07 µs and elapsed 46.27/49.44 → 43.28 µs. Missing-path main CPU is 74.29/74.14 → 79.30 µs and elapsed 80.04/78.63 → 82.65 µs. Process CPU changes remain below 8% in these final controls. This isolates the synchronous API from the consumer's asynchronous scheduling tradeoff.
CHANGELOG.mdupdated when release-relevant