Skip to content

improve(update): reduce POSIX package backup cleanup overhead - #188479

Open
roboclaw-bot wants to merge 2 commits into
mainfrom
openclaw/posix-journal-reader-pr-v2
Open

roboclaw-bot wants to merge 2 commits into
mainfrom
openclaw/posix-journal-reader-pr-v2

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #184658 (supporting research only; this does not diagnose or close the native Windows delay).

What Problem This Solves

POSIX npm updates do avoidable work while removing the previous installed package during final cleanup.

User Impact

Updates driven by a version containing this change spend less work retiring package backups, without changing configuration or migration requirements.

The installed updater owns this cleanup: installing the fixed candidate cannot accelerate an already-running older updater. Native Windows uses a different activation path and is not covered. The measured improvement below is for one cleanup phase, not total update time.

Why This Change Was Made

Reuse the existing admitted SQLite reader for one artifact's removal rather than opening a new journal connection for every removed entry. Every callback still reads the current journal record and checks object identity and live executor authority. Each read releases its snapshot; the retained connection closes on success or error before settlement or archival.

There is no cached authorization decision, reduced check frequency, deferred cleanup, or deadline change. Shared removal cadence, Windows compensation, updater-runtime retention, and terminal-output ordering remain unchanged. This isolates a POSIX-only cost found while supporting DonnieFi's investigation, not a competing Windows repair.

Evidence

The following commands and measurements were executed by Codex in Mert Başar's isolated Linux/WSL2/Docker environment. RoboClaw verified the source transfer and reused those receipts; it did not rerun or claim independent execution of the tests.

Measured baseline: a0f10e38dea4244cfb22ad3f63139ef540e51587. Original measured candidate: d64336801477b849cb019c4bf721eedfdc5a6c3a. The transferred candidate files match their recorded SHA-256 values.

Qualified cleanup measurements

Node 24.22.1, five serial interleaved baseline/candidate pairs, fresh process and fixture for each sample, the same committed 2,000-file / 40-directory workload, warm/uncontrolled filesystem caches, no profiler in this series.

Retirement metric Baseline Candidate
Median wall time 2,324.893 ms 1,704.147 ms (−26.70%)
p95/max wall time 2,499.576 ms 1,858.149 ms
Median process CPU 2,464.444 ms 1,886.597 ms (−23.45%)
p95/max process CPU 2,739.229 ms 1,981.209 ms
Journal connections opened/closed, each sample 2,091 / 2,091 35 / 35
Journal preparations, each sample 8,343 2,178
Fresh current-record reads, each sample 2,084 2,084

No recorded median/p95 metric regressed by 20% or more. With five samples, nearest-rank p95 is the maximum, not a robust tail estimate. The original stronger preparation-scaling criterion is only partly met: the existing per-read journal-mode preparation remains. Total preparations are not constant.

The workload exercises real publication/retirement owners with private synthetic trees and an inert recovery-runtime fixture. It does not measure whole-update latency or establish a Windows/macOS improvement.

Reproducible workload and focused-test receipt

With supported Node 24.22.1 selected on PATH, the committed opt-in measurement entrypoint is:

OPENCLAW_BENCH_RETIREMENT=1 OPENCLAW_VITEST_RUNTIME=node \
  node scripts/run-vitest.mjs \
  src/infra/package-update-journal-retirement.perf.test.ts --maxWorkers=1

The comparison retained this same workload for both variants, changing only the two production files between their pinned baseline and candidate versions. Source files were restored afterward.

Recorded focused-suite output:

Test Files  5 passed (5)
     Tests  80 passed | 4 skipped (84)

The three added journal cases passed: intervening committed intent, replaced journal inode, and scope-end disposal. The four skips are existing macOS-only non-root ownership cases. Existing SQLite-owner proof covers snapshot-lock release and writer visibility. Targeted typecheck, lint, formatting, and patch checks passed on the donor candidate.

Packaged CLI boundary and retained limits

  • Published stable 2026.10.8 → candidate completed with matching build identity and durable run, readiness HTTP 200, preserved synthetic durable conversation, and intended incognito cleanup. This is compatibility proof; cleanup in that first hop still belongs to the old installed driver.
  • A candidate-driven explicit replacement completed with update/status exit 0 and durable succeeded/finished. CLI packageActivation.phase was complete. Function coverage bound to the original driver PID 84 recorded 3 executions of createAssertionReader. This is execution coverage, not a CPU profile.
  • The second wrapper nevertheless exited 1: its final path-only assertion incorrectly treated a retained completed control journal as pending recovery. That failure receipt is preserved. Separate offline reconciliation used the recorded CLI completion and pinned source contract; it is not a clean wrapper rerun. An earlier npm download timeout occurred before product execution and is also retained.
  • The canonical package build/integrity check passed on a Node 26.7.0 build host; qualifying tests and packaged CLI execution used 24.22.1. The build emitted an untriaged, out-of-scope Control UI budget warning (1,247.0 vs 1,246.7 KiB). Historical Node 26.7 measurements/profiles are not the headline runtime qualification.
  • Independent in-session review found no actionable production/durability findings; its benchmark opt-in/platform-guard finding was addressed. The optional external autoreview helper did not run, because transmission of unpublished code to its configured service was not authorized. No clean result from that tool is claimed.
  • Native macOS/Windows execution and broad PR CI are not claimed. Full retained logs stay private; the source-bound results and limitations needed for review are summarized here.

CI follow-up: inventory callback identity

The original database-worker CI leaf failed because moving the existing validation callback changed its lexical operation name. The follow-up changes only the file-scoped reviewed entry from openJournal.withDatabase.validate to openJournal.validate; existing CLI-only caller evidence, thresholds, guards, production code, and benchmark bytes are unchanged.

RoboClaw ran the affected checks on Node 24.22.1: 124 tests passed across 3 inventory/ratchet/registry files, scoped format/lint and diff checks passed, and one normal pnpm check:database-worker-ratchet --base a0f10e38dea4244cfb22ad3f63139ef540e51587 invocation passed (T1 169 → 168; T1-compat 15 → 15). This is an original-branch-base comparison, not a replay of the failed CI merge. The prior CI failure remains recorded; newly triggered current-head CI is pending. Original cleanup measurements and packaged CLI proof remain attributed to the donor candidate above and were not rerun.

Worked on by

Work sessions

The discussion and local implementation/verification sessions are private and are intentionally not linked at the requester's explicit direction. The source-bound evidence is summarized above; importing and publishing the candidate is not claimed as a new test execution.

Worked on by:
- @MertBasar0

Co-authored-by: MertBasar0 <[email protected]>
OpenClaw-Publication: 9325bc99-61df-45b5-9dc8-2e07104315c6
@clawsweeper

clawsweeper Bot commented Oct 30, 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.

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review October 30, 2026 15:38
@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. 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. 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 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses a SQLite journal connection during each package-backup removal while preserving fresh intent and authority checks.

Example: Retiring a previous package containing 2,000 files across 40 directories on Node 24.22.1.

  • Before: The reported workload opened 2,091 journal connections and had a median retirement time of 2,324.893 ms.
  • After: The reported workload opened 35 journal connections and had a median retirement time of 1,704.147 ms, with the same 2,084 current-record reads.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct optimization with quantified work reduction and relevant packaged CLI evidence; the failed wrapper assertion limits the strength of the otherwise useful proof.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Submitted Node 24.22.1 evidence exercises the real retirement owners and a candidate-driven packaged CLI replacement, recording successful update/status completion and execution of createAssertionReader. The wrapper's separate path-only assertion failure is disclosed and consistent with retained completed-journal behavior. The current-head delta changes only inventory metadata, so the production evidence remains applicable.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: POSIX npm updates spend avoidable time repeatedly opening the journal while deleting the previous package.
Reason: The maintainer-authored direction has a measurable benefit, preserves existing behavior, and accurately excludes native Windows and whole-update latency claims.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it provides a measured POSIX cleanup improvement that current main lacks, with no actionable correctness finding.

Priority: P2
Reviewed head: b5c787f8b183fb61d68fbc1ac8d30d9f0f0af27b

Before merge

None.

Findings

None.

Agent review details

How this fits together

The POSIX package-publication owner removes obsolete package artifacts after activation; its journal supplies current intent, while the executor and filesystem owners enforce authority and object identity.

flowchart TD
  A[Installed updater] --> B[Publication owner]
  B --> C[Scoped assertion reader]
  C --> D[SQLite operation journal]
  B --> E[Executor authority checks]
  B --> F[Filesystem removal owner]
  F --> G[Obsolete package artifacts]
Loading

Technical review

Best possible solution:

Use the existing rollback reader for each artifact-removal scope while retaining fresh journal reads and all existing mutation checks.

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

Current-main source shows a new journal connection for each removal assertion, and the submitted interleaved workload quantifies that overhead; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch uses the existing reader and publication owners, removes repeated connection admission, and preserves current-record checks without introducing cached authorization or another cleanup path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Publication retirement and fresh intent checks keeps the original intent (b107d4a: Durable package publication and interrupted-update recovery require current intent and exact artifact custody.)
  • Reusable SQLite observation keeps the original intent (8bb889e: Reduce repeated ownership-check overhead by retaining a connection without retaining an observation's snapshot or authority.)
  • Snapshot-lock release keeps the original intent (5dbb579: Release SQLite snapshot locks so Bun-run updaters can commit through their existing writer.)
  • Database-worker inventory classification keeps the original intent (d5c2462: Record the journal's existing CLI-only database operations; the changed entry follows the validation callback's new lexical location without changing its classification.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Introduced change and scope: The pinned introduction adds scoped journal-reader reuse to retirement. The subsequent commit changes only the inventory callback name; production code and benchmark inputs remain unchanged from the earlier reviewed head. (src/infra/package-update-publication-owner.ts:571, b5c787f8b183)
  • Fresh observations and bounded lifetime: Each reader invocation checks journal identity, opens its own read snapshot, reads and decodes the current record, and releases the snapshot. Errors close the handle; the removal scope disposes it before subsequent transitions or settlement. (src/infra/sqlite-existing-database.ts:28, b5c787f8b183)
  • Existing authority and removal owners retained: The publication assertion still invokes live executor authority before checking journal intent and package identities. Recursive removal retains its existing assertion callback at the filesystem mutation boundary. (src/infra/package-update-publication-owner.ts:136, b5c787f8b183)
  • Submitted performance and CLI evidence: The public body reports five interleaved baseline/candidate pairs, reduced connection and preparation work, and candidate-driven packaged CLI completion with three executions of createAssertionReader. It preserves the wrapper's failed path-only assertion and distinguishes stable-to-candidate compatibility from execution by the new updater. (b5c787f8b183)
  • Current main still performs repeated opens: Current main retains the per-callback journal.assertCurrent path. Its intervening journal change adds read-only recovery inspection and does not implement scoped retirement-reader reuse. (src/infra/package-update-publication-owner.ts:138, 0a5426f67f6a)
  • Existing reader provenance: The verified patch for fix(update): reduce CPU time in repeated ownership checks #156757 introduced the reusable rollback reader for repeated ownership checks. This PR applies that existing owner rather than adding another connection manager. Some older SQLite blobs were unavailable to local history searches; GitHub commit evidence supplied the introduction. (src/infra/sqlite-existing-database.ts:28, 8bb889e8c841)

Likely related people:

  • Peter Steinberger: Raw commit b107d4a adds src/infra/package-update-publication-owner.ts:124 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b107d4af14d7; files: src/infra/package-update-publication-owner.ts)

PR surface

Source +10, Tests +162, Other 0. Total +172 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 25 15 +10
Tests 2 162 0 +162
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 5 188 16 +172

Review metrics

Metric Value Why it matters
Production versus validation growth Production +25/-15 LOC; tests and opt-in benchmark +162/-0 LOC The small production increase adapts an existing reader; validation growth includes the committed 128-line measurement workload and three distinct reader-lifecycle cases.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A measured improvement to one POSIX update-cleanup phase has useful but limited impact and does not establish an urgent workflow failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-30T15:56:32.644Z sha 6b59ce4 :: needs maintainer review before merge. :: none

Reviewed November 2, 2026, 3:50 PM ET / 20:50 UTC (Revision 2).

Worked on by:
- @MertBasar0

Co-authored-by: MertBasar0 <[email protected]>
OpenClaw-Publication: 7cd9d2a6-7c1e-40fe-9ffe-976c71699351
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 30, 2026
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Nov 2, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 2, 2026
@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Nov 9, 2026

This branch has not been deployed

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

Labels

clawtributors PR from a clawtributor 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: 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