Repository navigation
perf(gateway): release decoded workspace tree inputs before worker settlement - #183087
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. |
5ee68ad to
49fed09
Compare
49fed09 to
a356293
Compare
|
Codex review: needs maintainer review before merge. What this changesThis PR removes two unnecessary awaits so decoded workspace tree inputs can be collected before worker settlement. Example: Prepare tree input for 80,000 synthetic files while workspace workers are occupied.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open for landing: it makes a focused lifetime improvement, preserves existing worker contracts, and introduces no actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway workspace reconciliation encodes manifest entries, submits them to the existing Git worker broker, and consumes the resulting Git tree input for rollback and recovery. flowchart TD
A[Workspace reconciliation] --> B[Tree input adapter]
B --> C[Encoded manifest payload]
C --> D[Git worker broker]
D --> E[Workspace computation worker]
E --> F[Git tree input file]
F --> G[Rollback patch and journal]
Technical reviewBest possible solution: Land the two-await simplification while preserving journal-owned entries and the existing broker lifecycle. Do we have a high-confidence way to reproduce the issue? Current main suspends both adapter frames after encoding; the submitted regression reports base failure and candidate success for collection during a held operation, but this review executed no target code. Is this the best way to solve the issue? Removing the two awaits is the smallest complete adapter-lifetime fix: it reuses existing owners, retains async rejection semantics, and leaves legitimate recovery retention intact. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1554158d47d5. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource 0, Tests +63, Other +260. Total +323 across 3 files. Added test files: 0. View PR surface stats
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 24, 2026, 10:21 PM ET / October 25, 2026, 02:21 UTC. |
…ttlement (openclaw#183087) * perf(gateway): release decoded workspace tree inputs before worker settlement * test(perf): observe workspace encoding without a lint suppression * test(perf): measure untraced workspace recovery latency
What Problem This Solves
Workspace tree-input adapters keep decoded manifest inputs reachable until the worker finishes, even after encoding and transferring the worker request. Large queued operations unnecessarily extend the lifetime of those objects.
User Impact
Pending tree-input preparation can release entries once the caller no longer needs them. Reconciliation bytes, recovery journals, cancellation, and errors remain unchanged. Recovery callers still retain entries that their journals need; this is not a claim that all pending recovery memory disappears.
Why This Change Was Made
Return the existing promise from two async adapters instead of suspending their frames with
return await. Keeping the functions async preserves rejected-promise behavior for encoding errors. Current main already transfers encoded payloads at admission and dispatch, so this adds no transfer path, cache, coalescing, or transport policy.Gateway runtime LOC delta: 0 (two
awaitremovals); the required reproducible benchmark adds 261 tooling lines, and the regression adds 64 net test lines. The regression checks collection of the original objects during a deterministically held worker operation and unchanged rejection propagation. The standalone benchmark exercises 80,000 synthetic files through bothcreateWorkspacePatch → prepareWorkspaceTreeInputand the direct tree-input owner.Evidence
workspace-manifest-worker.test.ts,workspace-manifest.test.ts,workspace-reconcile.test.ts, andworkspace-reconcile-recovery.test.ts. First three worker/reconcile files took 97.45 s including a cold runtime artifact build; manifest schema file took 0.96 s.pnpm tsgo:scripts, andgit diff --check: passed.Completed memory measurements
Node 26.12.1, 80,000 synthetic empty files with distinct manifest paths/digests, four occupied workspace worker slots, fixed 16-CPU affinity and 8 GiB memory limit. Five serial alternating baseline/candidate samples per mode (20 total). Setup and guarded waits are excluded. Base source:
c28e83983a1f; rebasing did not change the measured manifest/recovery/broker owners. No production data was used. These are owner-level retention runs, not whole-Gateway latency or GC-throughput gates.Values below are means; retained memory is the forced-GC delta above the warmed process before input construction. RSS includes all worker isolates.
Direct-owner queued retained-heap ranges: baseline 22.094–22.102 MiB, candidate 0.120–0.128 MiB. Recovery queued ranges: baseline 48.803–48.803 MiB, candidate 48.802–48.804 MiB. Peak-RSS ranges: owner 936.543–947.688 → 926.469–945.223 MiB; recovery 983.352–996.824 → 930.777–994.113 MiB.
Every queued sample had four active blocker tasks plus one queued manifest; every active sample had one manifest task. Base/applied recovery tree preparation stayed sequential. This does not establish duplicate identical production requests, and unique destination paths/refs must not be coalesced by workspace alone. The existing broker retains a queued payload and transfers it at dispatch; raw
arrayBufferscan still count transferred backing stores, while external bytes drop back to baseline. No native-buffer reduction is claimed.All ten direct-owner outputs had SHA-256
c4276dcfb84b72beb58f4bf799bf555389b4958960b6da5c9b468c350ced84d2. All ten recovery outputs had treeaa7dfcc8ac322b96845b31ab170434bf61843f78, empty patch, and identical pack SHA-25692a15b9ae6bab4611abe1c36766899c89b44f3d835f5feac74c632361ed433aa. A final smoke of the lint-clean instrumentation reproduced the owner result and same output hash.Timing context and limits
Instrumented pre-release duration (includes entry construction and forced GC): owner 165.52 → 143.70 ms; recovery 291.25 → 303.92 ms. Instrumented total pending duration: owner 5.367 → 5.960 s (+11.05%, ranges 3.626–6.310 → 4.168–7.468 s); recovery 11.421 → 15.960 s (+39.75%, ranges 10.099–13.058 → 11.772–21.713 s). These serial runs include forced GC, deliberate blocking, and changing shared-host I/O contention. They are not matched untraced latency proof; the adverse timings are reported, not discarded, and no latency improvement is claimed. The completed untraced follow-up below covers this gap; the instrumented durations remain historical context.
This is a zero-runtime-LOC simplification with a proven owner-retention improvement and neutral rollback-patch-construction retained memory. It does not establish removal of a large production recovery holder: the caller legitimately retains entries for the journal. After deployment, look for decoded inputs no longer retained solely by these adapter frames; expect journal-owned arrays and transferred-buffer accounting to remain. No timeout, queue policy, schema, or transport internals changed.
Untraced recovery latency follow-up
Acceptance rule was recorded before running: five serial alternating baseline/candidate fresh-process pairs of the same 80,000-file workload, identical outputs, and no reproducible latency regression (20% worsening is a stop). Node 26.12.1 on Linux, exclusive quiet-slot lock and existing production-load guard, 16 interleaved CPUs, 8 GiB limit, identical placement within each pair and alternate placement across pairs. Worker startup is warmed/excluded; input construction and the complete
createWorkspacePatchcall are timed. No forced GC, tracing, allocation sampling, or intentional blockers;NODE_OPTIONSandNODE_V8_COVERAGEare unset. An exploratory local series was stopped and excluded after recovering the original Linux-host requirement.Reproduction:
node --import ./scripts/tsx.mjs scripts/perf/workspace-manifest-retention.ts <scratch> prepare 80000, then modelatency 80000on each side. Usage is documented in the script header; the perf README is unchanged. Baseline is7bddc5d70497; candidate runtime differs only by the two await removals.All ten outputs match the earlier tree, empty-patch, and pack hashes. The prior 11.421 → 15.960 s (+39.75%) rise is not reproduced. This is no speedup claim: paired differences are mixed and the mean change is only −0.205 s. The earlier durations included forced GC and deliberate blocking, and did not reserve an exclusive measurement slot; changing shared-host I/O/CPU contention was confounded with the edit. The new comparison removes deliberate instrumentation/blocking and reserves a benchmark slot, but cannot separately attribute the old rise to GC instrumentation versus contention. No comparable latency regression appears in the untraced workload.
Holder ownership, overlap, and liveness
Tree-input overlap:
writeRawWorkspaceTreeis the only production caller ofprepareWorkspaceTreeInput; each invocation has a random ref and private output repository/path, and base/applied preparations are sequential. Recovery entry owners serialize per environment. Same workspace alone is not equivalent work: source root/tree, destination path, ref, and entries all matter. See tree preparation and recovery serialization.Other manifest overlap: independent forks of one source checkpoint can overlap identical staged-manifest reads. Separate PR #183128 joins only those pending reads, keyed by all request inputs, cwd, environment digest, and signal identity, with invalidation at the existing ref writer. Its interleaved work-count regression reduces ten physical reads to six for ten callers with six identities. It does not change this PR or claim to remove the tree-input holder.
Queue/hang bound: Git worker admission supplies a 30-minute deadline. The pool arms it before enqueue, and host exchanges retain the original deadline. Queued expiry removes/rejects the task; worker exit also rejects. Timeout is a typed visible error, with a warning for a stalled host callback. Six existing owner tests passed for queued expiry, four host-wait deadline variants, and worker exit/OOM. Standard Git subprocesses use abort signals and deadlines (workspace commands: 10 minutes). The outer owner deliberately joins host callbacks and cleanup, so 30 minutes is not an unconditional wall-clock guarantee for arbitrary abort-ignoring callbacks or a stuck OS filesystem. No concrete standard-path indefinite wait was found; no speculative timeout was added.
48.8 MiB journal retention: the benchmark's recovery mode measures rollback-patch construction. The real apply caller needs both arrays after
createWorkspacePatchto write the journal, prepare targets, and recover if apply fails. Recovery replay also needs both sides for later conflict/final-state checks. Clearing caller-owned arrays at encoding would break recovery; streaming worker input alone would not release these journal owners. A different journal representation/lifecycle would be separate work. The measured rollback-patch-construction retained heap remains neutral.Full apply also retains the base/current manifests, reconciliation maps, and preflight facts across patch construction for later revalidation and directory application (apply owner). Those owners are outside the snapshot-construction benchmark; their contribution to the production total has not been quantified. The aggregate tree-input dominator does not identify request tuples or age, so it cannot establish duplicate equivalent work or a hang. Its retained size is not a measurement of memory this edit reclaims. After deployment, the expected signal is loss of retention solely through the two adapter frames; journal-owned arrays remain until their owner settles. The full large production holder is not claimed fixed.
Final validation and CI
The original two commits were rebased patch-identically onto main
7bddc5d70497and pushed with force-with-lease (git range-diffmarks both unchanged). Follow-up headbf04d0e774d4237a238fb20b73920204452209eeadds only the timing mode. Changed-file lint/format, script typecheck, diff check, and fresh independent review passed. Existing retention/reconcile proof above remains applicable; the six deadline/exit tests also pass.The earlier introduced lint-suppression issue was repaired by removing the suppression. Earlier inherited type errors are resolved by the rebase. Final-head CI is fully green: 69 passing, 56 skipped, no pending or failed checks, including the aggregate CI gate. No merge was attempted; the lead owns landing.