Skip to content

perf(gateway): release decoded workspace tree inputs before worker settlement - #183087

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-workspace-manifest-input-20261025
Oct 25, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-workspace-manifest-input-20261025

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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 await removals); 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 both createWorkspacePatch → prepareWorkspaceTreeInput and the direct tree-input owner.

Evidence

  • Retention regression: red on base (both original input and entries retained), green with the fix (both collected). Candidate regression: 487 ms.
  • Node focused tests: 67 passed across workspace-manifest-worker.test.ts, workspace-manifest.test.ts, workspace-reconcile.test.ts, and workspace-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.
  • Changed-file oxfmt, changed-file oxlint, pnpm tsgo:scripts, and git diff --check: passed.
  • Independent subagent review (autoreview route unavailable): no actionable P0–P2 findings. The configured autoreview provider selector did not match the operator configuration; no configuration was changed.
  • The retention regression also passes under the default Bun test runtime (255 ms).
  • Broad proof: PR CI.

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.

Mode / metric (n=5 per side) Baseline Candidate Mean paired delta
Direct owner, queued retained heap 22.100 MiB 0.126 MiB −21.974 MiB (−99.43%)
Direct owner, active retained heap 22.072 MiB 0.098 MiB −21.974 MiB (−99.56%)
Recovery, queued retained heap 48.803 MiB 48.802 MiB −0.001 MiB (neutral)
Recovery, active retained heap 48.771 MiB 48.770 MiB −0.001 MiB (neutral)
Direct owner, queued / active ArrayBuffer counter 15.946 / 15.946 MiB 15.946 / 15.946 MiB unchanged
Recovery, queued / active ArrayBuffer counter 16.008 / 16.008 MiB 16.008 / 16.008 MiB unchanged
Both modes, queued / active external-byte delta 15.946 / <0.001 MiB 15.946 / <0.001 MiB unchanged
Direct owner, process peak RSS 942.177 MiB 937.270 MiB −4.907 MiB (−0.52%; context)
Recovery, process peak RSS 990.054 MiB 969.284 MiB −20.770 MiB (−2.10%; context)

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 arrayBuffers can 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 tree aa7dfcc8ac322b96845b31ab170434bf61843f78, empty patch, and identical pack SHA-256 92a15b9ae6bab4611abe1c36766899c89b44f3d835f5feac74c632361ed433aa. 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 createWorkspacePatch call are timed. No forced GC, tracing, allocation sampling, or intentional blockers; NODE_OPTIONS and NODE_V8_COVERAGE are 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 mode latency 80000 on each side. Usage is documented in the script header; the perf README is unchanged. Baseline is 7bddc5d70497; candidate runtime differs only by the two await removals.

Recovery wall time, n=5 per side Baseline Candidate Delta
p50 12.085732 s 11.690160 s −3.27%
Mean 12.111790 s 11.906550 s −1.69%
Range 10.944128–13.255648 s 11.197301–12.819195 s context
Pair Baseline (s) Candidate (s)
1 12.804312 12.819195
2 13.255648 11.414018
3 12.085732 12.412075
4 11.469130 11.690160
5 10.944128 11.197301

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: writeRawWorkspaceTree is the only production caller of prepareWorkspaceTreeInput; 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 createWorkspacePatch to 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 7bddc5d70497 and pushed with force-with-lease (git range-diff marks both unchanged). Follow-up head bf04d0e774d4237a238fb20b73920204452209ee adds 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.

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T01:41:58.264957Z bf04d0e New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts size: M labels Oct 25, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@steipete
steipete force-pushed the steipete/perf-workspace-manifest-input-20261025 branch from 5ee68ad to 49fed09 Compare October 25, 2026 01:21
@steipete
steipete force-pushed the steipete/perf-workspace-manifest-input-20261025 branch from 49fed09 to a356293 Compare October 25, 2026 01:35
@steipete
steipete merged commit ad0450a into main Oct 25, 2026
164 checks passed
@steipete
steipete deleted the steipete/perf-workspace-manifest-input-20261025 branch October 25, 2026 02:22
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The direct-owner benchmark reports 22.100 MiB of retained heap while queued.
  • After: The candidate reports 0.126 MiB with identical output; recovery-owned entry retention remains unchanged.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A correct, minimal simplification with useful owner-level retention evidence and green exact-head validation; whole-Gateway memory impact remains unmeasured.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; supplied owner-level benchmarks exercise real workspace workers and Git output, while the collection regression holds the pool boundary.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Large pending workspace operations keep decoded inputs alive after the worker request has already been encoded.
Reason: The maintainer-authored direction removes unnecessary retention with no production machinery growth, and the evidence carefully limits the benefit to adapter-owned objects.

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
Reviewed head: bf04d0e774d4237a238fb20b73920204452209ee

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied measurements exercise production owners and workers rather than a complete Gateway reconciliation session.
Agent review details

How this fits together

Gateway 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]
Loading

Technical review

Best 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

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source 0, Tests +63, Other +260. Total +323 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 64 1 +63
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 260 0 +260
Total 3 326 3 +323

Labels

Label changes:

  • add P2: This is a bounded memory-lifetime improvement; the evidence establishes no crash, data loss, or urgent production regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This is a bounded memory-lifetime improvement; the evidence establishes no crash, data loss, or urgent production regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 24, 2026, 10:21 PM ET / October 25, 2026, 02:21 UTC.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant