Skip to content

fix: keep large Git reads and cancellation responsive - #146499

Merged
steipete merged 2 commits into
mainfrom
codex/git-worker-adversarial-hardening
Sep 13, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/git-worker-adversarial-hardening

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Related: #146252, #146273

What Problem This Solves

Fixes delayed Git cancellation and avoidable memory/latency spikes when concurrent diffs or stopped cloud-session artifacts inspect large repositories.

User Impact

Canceled work waiting for a ref writer settles promptly, and large repository inspections keep the Gateway responsive. Existing preview limits, checkpoint validation, snapshot formats and active-process cleanup are preserved. No configuration, database schema or migration change is required.

Why This Change Was Made

Pending ref admission releases its callback and inputs on cancellation while preserving queue order. Once a writer starts, cancellation still joins its cleanup. All three low-level Git transports preserve their structured canceled-result contract; started authority errors are neither swallowed nor replayed.

Concurrent diff callers receive independent mutable containers while sharing immutable patch strings. Stopped-session diff/list/get requests inspect manifests in the existing Git content pool and return changed metadata and an optional bounded preview. The Gateway retains subprocess custody, checkpoint binding and current ownership checks. Retired full-reader/parser facades are removed.

Private benchmark IPC captures main/worker CPU and allocation profiles, periodic CPU/heap samples, and incomplete segments on retirement. Native thread IDs are queried inside inspector targets rather than inferred from their separate target IDs. These outputs are explicit benchmark artifacts, not runtime persistent state.

Evidence

The paired targeted Blacksmith Testbox run passed 14/14 jobs at bf235b8d688d83983aef30a63b20c369e5aa5cc8, against fdf2853f4860e65f7b1a44096647e8adfd89c13d (which already contains #146273). It includes both pinned builds, all three cancellation transports, all four CPU/heap identity/retirement cases, 143-response live Gateway parity, paired real Git cancellation, six 250k-artifact response sequences and 5,000-cancellation GC. All 123 original evidence files were independently checksum-verified; the lease is stopped.

For twelve operations over a 250,000-entry, 71 MB artifact manifest:

Metric Baseline Candidate
Main event-loop maximum, unprofiled 791.15 ms 29.51 ms
Main event-loop p99, unprofiled 776.99 ms 17.45 ms
Operation elapsed time, unprofiled 12.314 s 12.070 s
Peak RSS, unprofiled 1098.7 MiB 1240.0 MiB
Main-thread CPU, separate CPU pass 10.606 s 1.208 s
Main allocation traffic, separate heap pass 8.381 GB 46.4 MB

The inventory worker accounts for 8.342 GB of sampled allocation traffic: the expensive work moves off the main thread; total artifact allocation is approximately unchanged. This is the real SQLite/checkpoint, Git worker, authority and artifact owner boundary, not live cloud-runner or full artifact RPC dispatch.

The earlier 21/21-job broad run tested 73b11dbff81e9200e8a89f7ccdf61440750cc345, including four B/C/C/B 60-second soaks, idle retirement/restart and snapshot restoration. It completed 28,514 unprofiled Gateway requests; all 16,753 non-outage readiness probes returned 200. Gateway heap profiles showed main allocation traffic 1069 → 868 MiB and all-isolate traffic 1218 → 1024 MiB. An actual-cache 20-caller probe reduced retained diff allocation 30.34 MB → 0.19–0.44 MB while preserving independent mutations.

No throughput improvement is claimed. The two baseline soaks ran at 112.96/110.36 requests per second and candidate at 110.86/107.10; candidate process CPU was somewhat higher. Main-side Git subprocess creation remains the largest sampled stack. The approximately 131–141 MiB higher peak RSS on the extreme artifact fixture is accepted for the responsiveness gain within the existing bounded pool; idle retirement is verified, while memory-constrained production hosts remain unmeasured. Canceled caller objects collect promptly, but ordered queue bookkeeping remains until drain: about 9.57 MB per 5,000 slots.

Revision and Validation Notes

Current head 2745c491940d47239658f07cf43d3ea4c6afe150 is refreshed onto main bf95f2b23c63. All 27 Git/profiling source and test files match the targeted bf235b8 proof byte for byte; documentation retains newer main content. Broad measurements remain attributed to 73b11db. That older profiler mislabeled inspector target IDs as native thread IDs; only raw stacks/aggregates and main/process counters are used from it. The corrected targeted profiles independently map all fourteen worker captures to native statistics.

The refreshed toolchain passed the full private-QA artifact build, core/UI types, targeted lint, 143 Git/worker tests with two platform skips, and six real-Gateway tests covering delegation, partial refresh, catalog publication and agent-file saves. Independent review through P2 found no actionable source defect. Final PR CI is green on the published head. Its initial attempt had two unchanged Discord recording-backlog timeouts; all 272 files / 3,820 tests then passed in an unchanged Linux/Node 24 Testbox replay, and one exact failed-job retry passed. Assertions and deadlines were unchanged. The original timeout remains unreproduced; a controlled minimized Vitest mock-factory race is a separate supported follow-up, not a claimed fix. The diagnostic lease is stopped and verified completed.

Earlier CI exposed inherited main budget failures and outdated synchronous-discovery fixture assumptions. Current main owns those repairs; duplicate branch fixes were dropped during refresh. An older instrumented run reproduced an unrelated passive desktop disconnect without recovering its close reason. It remains a separate unresolved follow-up; this PR changes no desktop implementation, and subsequent published-head CI passed the unchanged node and SSH desktop proof.

Persistent compatibility is unchanged: v1/v2 checkpoint recovery, bounds, checksum rejection and current-owner validation are covered. The automated serialized-state warning refers to explicit benchmark outputs, not a Gateway store. No deployment is included in this PR.

@steipete
steipete marked this pull request as ready for review September 12, 2026 21:26
@clawsweeper

clawsweeper Bot commented Sep 12, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 8:40 PM ET / September 13, 2026, 00:40 UTC (Revision 6).

ClawSweeper review

What this changes

The PR makes queued Git cancellation responsive, moves stored repository inspection into existing background workers, reduces diff copying, and adds private worker profiling.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful follow-up that current main and the latest release do not implement. No actionable introduced defect was found, and the previous review's tradeoff has an explicit disposition in the PR body.

Priority: P2
Reviewed head: 2745c491940d47239658f07cf43d3ea4c6afe150

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A sound, useful patch with strong bounded production-path evidence and an explicitly accepted resource tradeoff.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Captured paired Testbox results exercise real Git cancellation, actual diff-cache isolation, and the SQLite/checkpoint-to-worker artifact boundary, showing prompt cancellation and lower event-loop stalls. Six central production files match the proof revision; full cloud RPC coverage is not claimed, and raw-log access was a reviewer-side limitation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Captured paired Testbox results exercise real Git cancellation, actual diff-cache isolation, and the SQLite/checkpoint-to-worker artifact boundary, showing prompt cancellation and lower event-loop stalls. Six central production files match the proof revision; full cloud RPC coverage is not claimed, and raw-log access was a reviewer-side limitation.
Evidence reviewed 9 items Current main still has the reported cancellation mechanism: At fetched main, ref admission awaits the keyed queue without accepting an abort signal. Main also retains the full checkpoint reader and structured cloning of coalesced diff responses.
Latest-release check: The v2026.9.4 implementation also waits directly on the ref queue without cancellation admission; the central fix is not already shipped.
Cancellation preserves execution ownership: Queued cancellation clears the waiting callback and settles its caller; admitted execution remains joined. The transport wrapper distinguishes pre-admission cancellation from errors thrown after execution admission, preserving authority errors.
Findings None None.
Security None None.

How this fits together

Gateway repository requests read Git checkouts and stored cloud-session artifacts to produce diffs and file previews. Background workers process large inventories while the Gateway retains subprocess execution, ownership checks, and cleanup.

flowchart TD
  A[Repository requests] --> B[Gateway ownership checks]
  B --> C[Bounded Git workers]
  C --> D[Gateway Git subprocesses]
  D --> E[Git checkouts and stored artifacts]
  E --> C
  C --> F[Diffs and bounded previews]
  G[Cancellation] --> D
Loading

Before merge

  • Resolve merge risk (P1) - The extreme artifact fixture adds approximately 131–141 MiB peak RSS; memory-constrained production hosts remain unmeasured despite the explicitly accepted responsiveness tradeoff.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +157, Tests +346, Docs 0, Other +279. Total +782 across 28 files.

View PR surface stats
Area Files Added Removed Net
Source 12 452 295 +157
Tests 12 480 134 +346
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 290 11 +279
Total 28 1223 441 +782

Review metrics

Metric Value Why it matters
Production versus test growth Runtime +157 lines; benchmark tooling +279; tests +346 Growth is justified by cancellable admission, worker-side artifact projection, and private profiling, with existing parsers extracted rather than duplicated.
Large-artifact measurements Event-loop maximum 791.15→29.51 ms; peak RSS 1098.7→1240.0 MiB The captured paired measurements establish a responsiveness benefit with a memory cost, without claiming increased throughput.

Stored data model

Persistent data-model change detected: serialized state: scripts/lib/gateway-bench-profile-preload.ts, serialized state: scripts/lib/gateway-bench-worker-profile.ts, unknown-data-model-change: scripts/lib/gateway-bench-worker-profile.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Retain the documented memory tradeoff (recommended)
    Proceed under the existing explicit acceptance of higher extreme-fixture RSS for lower event-loop stalls, with worker bounds and idle retirement preserved.

Technical review

Best possible solution:

Keep the existing bounded worker and subprocess owners, preserve checkpoint compatibility, and retain the documented acceptance of the measured memory cost.

Do we have a high-confidence way to reproduce the issue?

Yes: current main's ref queue cannot settle a canceled waiting caller until its predecessor finishes; the PR records paired real-Git reproduction. This read-only review did not execute that scenario.

Is this the best way to solve the issue?

Yes: the patch extends existing queue, worker, and checkpoint owners while preserving ordering, active cleanup, mutable response isolation, and stored formats.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b78d651e03ce.

Labels

Label justifications:

  • P2: This improves cancellation and responsiveness for repository-heavy workloads without evidence of an emergency regression.
  • merge-risk: 🚨 availability: The measured additional peak memory could pressure smaller hosts even though the worker pool remains bounded.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Captured paired Testbox results exercise real Git cancellation, actual diff-cache isolation, and the SQLite/checkpoint-to-worker artifact boundary, showing prompt cancellation and lower event-loop stalls. Six central production files match the proof revision; full cloud RPC coverage is not claimed, and raw-log access was a reviewer-side limitation.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured paired Testbox results exercise real Git cancellation, actual diff-cache isolation, and the SQLite/checkpoint-to-worker artifact boundary, showing prompt cancellation and lower event-loop stalls. Six central production files match the proof revision; full cloud RPC coverage is not claimed, and raw-log access was a reviewer-side limitation.

Evidence

What I checked:

  • Current main still has the reported cancellation mechanism: At fetched main, ref admission awaits the keyed queue without accepting an abort signal. Main also retains the full checkpoint reader and structured cloning of coalesced diff responses. (src/infra/git-exec.ts:103, b78d651e03ce)
  • Latest-release check: The v2026.9.4 implementation also waits directly on the ref queue without cancellation admission; the central fix is not already shipped. (src/infra/git-exec.ts:17, 3a9d69db306c)
  • Cancellation preserves execution ownership: Queued cancellation clears the waiting callback and settles its caller; admitted execution remains joined. The transport wrapper distinguishes pre-admission cancellation from errors thrown after execution admission, preserving authority errors. (src/infra/git-exec.ts:103, 2745c491940d)
  • Artifact validation and authority remain with existing owners: The worker returns projected metadata and an optional bounded preview. Existing manifest, tree-mode, payload-checksum, pinned-base, and accepted-manifest checks remain; the host checks current ownership before Git execution and before returning results. Recovery still uses the existing guarded SQLite acceptance operation. (src/gateway/worker-environments/session-repository-checkpoints.ts:105, 2745c491940d)
  • Captured real behavior evidence: The supplied PR body, source revision 02257c1af55ab6e56b29e960df69fb61801be0f06a8431b49432bc0798cf3da9, records paired real-Git cancellation, live Gateway parity, actual-cache isolation, and SQLite/checkpoint artifact runs. For the 250,000-entry fixture it reports event-loop maximum 791.15→29.51 ms and peak RSS 1098.7→1240.0 MiB. It explicitly accepts the memory tradeoff and limits the artifact claim to the production owner boundary rather than full cloud RPC dispatch. (bf235b8d688d)
  • Proof revision continuity: GitHub blob identities at the targeted proof revision match the reviewed checkout for all six independently checked central files: ref admission, Git transports, diff cache, artifact inventory, checkpoints, and worker profiler. The inventory blob is 5cc36f01d4813d22659e45eec3997001327360fd. (src/gateway/worker-environments/workspace-result-inventory.runtime.ts:1, bf235b8d688d)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-09-12T21:43:55.195Z sha 73b11db :: blocked before merge. :: none
  • reviewed 2026-09-12T22:24:59.474Z sha bf235b8 :: blocked before merge. :: none
  • reviewed 2026-09-12T22:39:12.519Z sha bf235b8 :: blocked before merge. :: none
  • reviewed 2026-09-12T22:58:04.956Z sha 660bfd2 :: blocked before merge. :: none
  • reviewed 2026-09-13T00:05:12.214Z sha 2745c49 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Sep 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Sep 12, 2026
@steipete
steipete force-pushed the codex/git-worker-adversarial-hardening branch from 660bfd2 to c241f63 Compare September 12, 2026 23:47
Release queued callers without waiting for unrelated ref writers while keeping active execution joined. Share immutable diff text and project stored artifacts in the existing Git content pool with parent-owned validation and subprocesses.

Extend private benchmark profiling to worker isolates and remove retired reader/parser facades. Preserve checkpoint formats and current recovery contracts.
@steipete
steipete force-pushed the codex/git-worker-adversarial-hardening branch from c241f63 to 2745c49 Compare September 12, 2026 23:54
@openclaw-barnacle openclaw-barnacle Bot removed the app: web-ui App: web-ui label Sep 12, 2026
@steipete
steipete merged commit e1d0d8d into main Sep 13, 2026
332 of 334 checks passed
@steipete
steipete deleted the codex/git-worker-adversarial-hardening branch September 13, 2026 00:56
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
* fix: keep large Git reads and cancellation responsive

Release queued callers without waiting for unrelated ref writers while keeping active execution joined. Share immutable diff text and project stored artifacts in the existing Git content pool with parent-owned validation and subprocesses.

Extend private benchmark profiling to worker isolates and remove retired reader/parser facades. Preserve checkpoint formats and current recovery contracts.

* fix: preserve Git cancellation results and worker profile identity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL 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