Repository navigation
fix(native): offload staged file creation and publication - #1052
Conversation
Dispatch POSIX staged opens and atomic renames through native libuv tasks, retain descriptor ownership through publication settlement, and keep small buffer writes asynchronous under storage contention. Co-authored-by: steipete <[email protected]>
|
🦞👀 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. |
Pin the two native tasks and asynchronous content write in create/write resource budgets. Warm the default libuv pool before syscall counting so allocator CPU probes are excluded with the existing startup work. Preserve all filesystem syscall counts exactly. Co-authored-by: steipete <[email protected]>
|
Codex review: needs changes before merge. What this changesThis PR moves POSIX staged creation and publication onto native workers and removes synchronous small-buffer writes. Example: Root.create('config.json', '{}') runs on slow shared storage.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 3 items remain Keep open: main still performs synchronous native staging I/O, and this useful fix introduces two publication-lifecycle regressions that need repair. Priority: P1 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherRoot writes and advanced staged-file APIs pass content into a retained-directory owner, which creates a private file, writes and synchronizes it, atomically publishes it, and returns verified receipts. flowchart TD
A[Root or advanced API] --> B[Retained staging owner]
B --> C[Native worker queue]
C --> D[Descriptor relative filesystem operations]
D --> E[Identity permissions and durability checks]
E --> F[Publication receipt]
B --> G[Cleanup after settlement]
Technical reviewBest possible solution: Keep worker dispatch in the existing staging owner while snapshotting publication policy at invocation and serializing assertCurrent with pending publication. Do we have a high-confidence way to reproduce the issue? Current main directly executes native creation, rename, and small-buffer writes synchronously; the report supplies attributed production stalls and describes real-binding before/after regressions, but no target code was run during this review. Is this the best way to solve the issue? Offloading these operations through existing NativeTask and shared write owners addresses the remaining blocking calls, provided publication ordering and input capture retain their existing semantics. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 67dee5ef4c03. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
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, 5:32 AM ET / 09:32 UTC. |
|
Independent verification of the merged repair at Rebuilt base The committed measurement driver now accepts separate source-built package/native artifacts. The synthetic fixture has 62,000 files / 1,116,000,000 logical bytes on APFS. No real user data or database fixture was used; these file owners do not access databases. This is owner-level evidence, not a whole-Gateway or btrfs reproduction. For 1 KiB Root.write with 100 ms injected IO delay (five single-write samples), timer responsiveness improves while the owner still waits for IO and durability:
Five interleaved A1/B/A2 timing passes, 50 warm-ups and 100 operations per batch; separate five A/B allocation passes. Medians below are batch means. The shared host was heavily loaded (peak 1-minute load 84), so these are not isolated throughput measurements:
The blocking/count improvement is clear, but the Root.create total-CPU increase (+41–43%) and elapsed increases are real measured tradeoffs, not a claim of universal throughput improvement. This verification completed after the source merge; explicit acceptance or a quieter Linux comparison belongs in the release/dependency-uptake decision. No npm release or dependency bump was performed. Runtime delta is net +17 LOC: existing native-task dispatch entry points and binding types, offset by deletion of the synchronous buffer shortcut/options. No cache, new manager, configuration, or schema. |
POSIX
Root.write/Root.createreturned promises while their staged-file open and publication still ran synchronously on the JavaScript thread. On shared storage under I/O contention, these calls stalled the Team Gateway main thread for 5–13 seconds, delaying liveness heartbeats and causingagent.waittimeouts.Production evidence after the R9b symbol attribution deployment (2026-10-31):
write@@openclaw/fs-safe:133 → publish@:340 → [native]; the native self sample carried 12,994.5 ms.runPinnedWriteNative@:76 → write@:133 → create@:116 → #prepare@:259 → [native]at staged creation.The owner calls are
src/native-staged-file.ts:277(createStagedFile) and:342/:344(replace/no-replace rename) on v0.27.0. Creation usesopenat(O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC, 0600); publication uses the existing retained-parent rename primitives. File and directory fsync already use asynchronous Node APIs. A separate small-buffer fast path usedwriteSync.Dispatch staged creation and publication through the existing N-API
AsyncTask/NativeTaskpattern and use asynchronous writes for small buffers. Retain descriptors through rename settlement and all durability/verification fences so concurrent cleanup cannot close or recycle a worker's descriptors. Reuse the existing native primitives and JS-thread error conversion, preserving flags, atomicity, no-replace fallback provenance, permission checks and durability ordering. Public promise APIs are unchanged. Synchronous admission, metadata/permission checks, cleanup, and generic synchronous rename owners retain their existing contracts; this does not claim every filesystem operation is nonblocking.Validation:
UV_THREADPOOL_SIZE=1, a real FIFO open holds the pool until a JS timer releases it; staged create/replace/no-replace must queue without blocking that timer. Two updated small-buffer cases also fail on base source and pass after the fix.git diff --checkpassed.scoped-clean.A changelog entry is included because CONTRIBUTING.md and docs/contributing.md require one for user-visible operational fixes. No version bump, tag, npm publication, or OpenClaw dependency bump is included. Maintainers must publish the next fs-safe patch through the documented protected-tag release flow before OpenClaw can consume this fix.
Requested by @steipete
Work sessions
Discussion, implementation and verification