Skip to content

perf(process): avoid rescanning exited runs - #128080

Merged
steipete merged 1 commit into
mainfrom
codex/perf-process-registry-exited-current
Aug 23, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-process-registry-exited-current

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The process supervisor retains exited run records for diagnostics. Every completed run currently rescans the entire registry solely to recount those exited records, making repeated process completion quadratic before the 2,000-record retention cap and leaving an unnecessary full retained-set scan afterward.

Why This Change Was Made

The registry now maintains one exact private exited-record count across additions, replacements, state transitions, effective finalization, and pruning. Pruning still follows Map insertion order, so the oldest created exited records leave first; live records, detached snapshots, first terminal metadata, the default cap, and all public types remain unchanged.

User Impact

Long-running OpenClaw processes that supervise many commands spend less CPU finalizing completed runs. There is no user-visible behavior or configuration change.

Evidence

  • Deterministic complexity probe on exact current main: 500/1,000 completions visited 125,250/500,500 registry values before the change and 0 after it.
  • Exact base/candidate semantic differential: 1,934-byte snapshots were byte-identical (SHA-256 530bb25abb5d22d3f8f4becdd42b0e6c4cf1006421950e533b7d698644bf098c) across out-of-order exits, repeated pruning, replacements, state transitions, detached snapshots, missing IDs, output touches, and idempotent finalization.
  • Node 24.15 owner microbenchmark, 250,000 add/finalize operations × 9 alternating rounds: median 2,085.947 ms → 286.546 ms (7.28×, 86.26% reduction). This is a registry-owner microbenchmark, not an end-to-end throughput claim.
  • Full process-supervisor suite: 11 files / 149 tests passed (exact base: 11 files / 147 tests passed).
  • node scripts/check-changed.mjs -- src/process/supervisor/registry.ts src/process/supervisor/registry.test.ts
  • pnpm build
  • Fresh bundled Codex Sol/high autoreview after a clean TruffleHog scan: no accepted/actionable P1+ findings, patch correctness 0.97.
  • Test-audit retained behavior-level coverage for insertion-order retention and every count-maintenance path; the implementation-coupled iteration-count probe remains external evidence rather than a committed test.

AI-assisted: yes. @steipete reviewed the owner path, invariant, diff, and verification evidence and understands the change.

@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 23, 2026
@steipete
steipete marked this pull request as ready for review August 23, 2026 02:19
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Aug 23, 2026
@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 22, 2026, 10:26 PM ET / August 23, 2026, 02:26 UTC.

ClawSweeper review

What this changes

The PR maintains an exact private count of exited process-run records so finalization avoids repeatedly scanning the retained registry.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open. The private counter is maintained across the registry’s write paths, preserves insertion-order pruning, and introduces no concrete review finding; this active maintainer-owned PR should proceed through normal exact-head checks.

Priority: P3
Reviewed head: 361fbb629a198826d173afa675b74866131363dd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary optimization with behavior coverage and no supported correctness or security finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; the PR body additionally provides benchmark and suite evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; the PR body additionally provides benchmark and suite evidence.
Evidence reviewed 6 items Current-main performance path: The base implementation invoked pruning from finalization and counted every exited record by scanning the full registry before deleting old records.
Owner-boundary repair: The candidate keeps the count private to the registry, updates it for replacement and state transitions, and decrements it exactly when pruning an exited record.
Runtime caller coverage: The sole production owner adds newly created runs, uses state updates only for starting/running/exiting lifecycle changes, and sends all terminal paths through finalize.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

pnpm openclaw --help
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128080-yi5jD1/target$ pnpm openclaw --help
$ node scripts/run-node.mjs --help
pnpm openclaw --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 110.89 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 13.4s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 3956ms (slowest: built plugin control-plane loads 3333ms)

OpenClaw 2026.8.1 (361fbb6) — All your chats, one OpenClaw.

Usage: openclaw [options] [command]

Options:
  --container ‹name›   Run the CLI inside a running Podman/Docker container named ‹name› (default: env OPENCLAW_CONTAINER)
  --dev                Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)
  -h, --help           Display help for command
  --log-level ‹level›  Global log level override for file + console
… output truncated …

Assertions:

  • PASS expect_output: Usage:

How this fits together

The process supervisor records command-run lifecycle events and retains completed records for diagnostics. Terminal transitions feed the registry, which prunes old exited records while callers can still retrieve detached snapshots.

flowchart LR
A[Process lifecycle events] --> B[Supervisor]
B --> C[Run registry]
C --> D[Exited record count]
D --> E{Retention cap exceeded?}
E -->|Yes| F[Prune oldest exited records]
E -->|No| G[Retain diagnostic records]
F --> H[Run status lookup]
G --> H
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed because the review found no actionable defect in this active PR.
Agent review details

Security

None.

PR surface

Source +4, Tests +38. Total +42 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 17 13 +4
Tests 1 46 8 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 63 21 +42

Review metrics

Metric Value Why it matters
Production vs test LOC production +17/-13 (net +4); tests +46/-8 (net +38) The small production increase is the count invariant that removes the repeated scan; the larger test change exercises its mutation paths.

Technical review

Best possible solution:

Keep the count as private registry-owned state and land it once the exact PR head has normal green checks.

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

Yes, source-reproducible with high confidence: current main scans every registry value during terminal pruning. This read-only review did not execute the benchmark.

Is this the best way to solve the issue?

Yes. Keeping the count in the registry that owns every record mutation is the narrowest maintainable solution; moving the optimization into supervisor callers would duplicate lifecycle policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a38b88ae03e8.

Labels

Label changes:

  • add P3: This is a small internal performance optimization with no configuration or user-visible behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; the PR body additionally provides benchmark and suite evidence.

Label justifications:

  • P3: This is a small internal performance optimization with no configuration or user-visible behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; the PR body additionally provides benchmark and suite evidence.

Evidence

What I checked:

Likely related people:

  • Vyctor H. Brzezowski: Introduced both the registry and its supervisor integration in the preceding merged change. (role: initial process-supervisor registry author; confidence: high; commits: 43710901ae78; files: src/process/supervisor/registry.ts, src/process/supervisor/supervisor.ts)
  • steipete: History shows extensive recent work on the supervisor lifecycle and cancellation paths. (role: frequent process-supervisor contributor; confidence: high; commits: ee8149848753, 8bfb4a550e68, 4cea6daf5afd; files: src/process/supervisor/supervisor.ts)

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.

Copy link
Copy Markdown
Contributor Author

Land-ready review complete for exact head 361fbb629a198826d173afa675b74866131363dd.

The process registry is the canonical mutation owner, and the private exact exited-record count is the best fix: it removes the full retained-set recount while preserving detached snapshots, first-terminal metadata, the 2,000-record cap, live-record retention, and Map insertion-order pruning. Native review artifacts validate as READY FOR /prepare-pr with zero findings. Judged diff: production +17/-13 (net +4), tests +46/-8 (net +38); the small production growth is the minimum explicit bookkeeping across the existing add, state-transition, finalize, and prune paths.

Verification:

  • Exact-head CI: run 32612582585 — green.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 128080 — passed in hosted_exact_or_recent_parent mode for the exact reviewed head. No separate Testbox lease/run was dispatched because the exact hosted CI already satisfied the gate.
  • node scripts/run-vitest.mjs src/process/supervisor — 11 files / 149 tests passed (exact base: 147).
  • node scripts/check-changed.mjs -- src/process/supervisor/registry.ts src/process/supervisor/registry.test.ts — passed.
  • pnpm build — passed.
  • git diff --check — passed.
  • Exact base/head semantic differential — byte-identical 1,934-byte output, SHA-256 530bb25abb5d22d3f8f4becdd42b0e6c4cf1006421950e533b7d698644bf098c.
  • Structural probe — retained-record visits for 500/1,000 completions: 125,250/500,500 on base, 0/0 on head.
  • Owner benchmark — 250,000 add/finalize operations x 9 rounds: 2,085.947 ms to 286.546 ms median (7.28x; owner microbenchmark only).
  • Fresh TruffleHog plus bundled Codex Sol/high autoreview — no accepted/actionable P1+ finding. Deslop and test-audit found no blocker.

ClawSweeper reviewed this exact head, found no correctness or security issue, rated patch quality platinum hermit, and agreed the private registry-owned count is the best solution. It published no Rank-up moves: section. Its sole before-merge item says no repair lane is needed and asks for normal maintainer/exact-head review; native review, green exact-head CI, and prepare gates satisfy that item.

Known proof gap: no live process smoke was run. This is private behavior-neutral in-memory accounting; exact semantic differential, every mutation-branch regression, the full supervisor suite, build, hosted CI, and prepare gates directly cover the changed contract.

Ready to merge.

@steipete
steipete merged commit 794a198 into main Aug 23, 2026
300 checks passed
@steipete
steipete deleted the codex/perf-process-registry-exited-current branch August 23, 2026 02:40

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

2 participants