Skip to content

fix(update): cleanup stalls when many artifacts share a large manifest - #174103

Closed
shoaibulhaque wants to merge 1 commit into
openclaw:mainfrom
shoaibulhaque:fix/cleanup-manifest-recheck
Closed

shoaibulhaque wants to merge 1 commit into
openclaw:mainfrom
shoaibulhaque:fix/cleanup-manifest-recheck

Conversation

@shoaibulhaque

@shoaibulhaque shoaibulhaque commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #174072

What Problem This Solves

Fixes prolonged Gateway downtime during update cleanup when many recovery artifacts share a large migration manifest.

User Impact

Cleanup can validate a shared manifest once, without repeating whole-file parsing and serialization for every artifact reference.

Why This Change Was Made

The post-confirmation inventory has already read the current manifests. Reuse those snapshots and compare each distinct migration run once before continuing with the per-reference ownership checks. Selection, destination verification, and final artifact checks still run through their existing owners.

Evidence

  • Added a retirement regression with real migration files. The base code reads the shared manifest five times after confirmation; the fix reads it once and retires the selected originals.
  • Added a confirmation-time metadata change test. Cleanup rejects the changed manifest and retains the originals.
  • Recovery mutation suite: 18 passed, 39.6 seconds wall time. This existing suite exercises real migration, SQLite, and retirement I/O. This is local wall time; it is not a CI runtime measurement.
  • Doctor test graph typecheck, targeted Oxlint, oxfmt, and git diff --check: passed. GitHub production types, test types, lint, and the openclaw/ci-gate check also passed on the reviewed head.

Installed CLI behavior proof

Verified on Linux x86_64 with Node v24.18.0 and synthetic data only. The baseline is the npm-installed OpenClaw 2026.10.4 (383c124). The fixed CLI is a local package built from this PR's exact head, ad229d086746bd5f46cc3f9181c1dc9edccb8377, using the repository's package script, then installed in a separate prefix. Its version output is OpenClaw 2026.10.4 (ad229d0). This package was not published.

The fixture contains 1,200 legacy sessions, 2,400 transcript events, and one unknown original that must remain protected. Both independent states were imported through the installed v2026.10.4 Doctor command, with no import issues. The legacy source files are byte-identical. Manifests were produced by the importer and were not edited. Different absolute state paths make the manifests slightly different sizes: 2,343,888 bytes for the baseline and 2,394,358 bytes for the fixed run.

Commands used, with each binary pointing to its separate installation:

# Import each isolated state with the released CLI.
OPENCLAW_STATE_DIR="$STATE" OPENCLAW_CONFIG_PATH="$CONFIG" \
  "$RELEASE_CLI" doctor --session-sqlite import --session-sqlite-all-agents --json

# Preview, then time the complete cleanup process with the matching CLI.
OPENCLAW_STATE_DIR="$STATE" OPENCLAW_CONFIG_PATH="$CONFIG" \
  "$CLI" update cleanup --dry-run --json
OPENCLAW_STATE_DIR="$STATE" OPENCLAW_CONFIG_PATH="$CONFIG" \
  /usr/bin/time -f '%e' "$CLI" update cleanup --yes --json

The runs were sequential on the same host, without overlapping cleanup work:

Installed CLI Manifest bytes before cleanup Elapsed wall time Exit
Released v2026.10.4 / 383c124 2,343,888 35.51 s 0
PR head / ad229d0 2,394,358 4.44 s 0

These times include process startup, ownership checks, verification, disposal receipts, and removal. This is one synthetic run per version, not the reporter's 13 MB inventory or a general benchmark.

Both actual cleanup reports returned status: "complete". Selected fields from the fixed report:

{
  "status": "complete",
  "totals": {
    "candidateBytes": 0,
    "verificationRequiredBytes": 0,
    "protectedBytes": 48,
    "blockedBytes": 0,
    "removedBytes": 514801,
    "removedFiles": 1201
  }
}

The preview selected 1,201 originals totaling 514,801 bytes. Cleanup removed all of them, left the 48-byte unreferenced original protected, and retained the migration manifest with disposal receipts.

Preservation was checked before cleanup, after cleanup, and again after CLI readback. Read-only SQLite checks showed identical canonical row hashes for all six history tables, including 1,200 session nodes, 1,200 session windows, and 2,400 transcript events. PRAGMA quick_check returned ok. Configuration and protected-original hashes were also identical at all three points:

config SHA-256:
570754922e34343f2f3ce0c643f1ba5ea29d3e2a35c76ef886b284e0fa15bb7f
protected original SHA-256:
2774a09541fd2fcb4fe0bb1eecd0ac384ffc32983199255b982ce7821f52015e
transcript_events SHA-256, before and after fixed cleanup:
fc6df9ffb73f3b9862d3bcdfa657c8d2fa91fb9b18195039605eead09c3c47cc

The installed release CLI then read the cleaned state with sessions --all-agents --limit all --json and returned count=1200, totalCount=1200, hasMore=false.

Verification limits: the fixed package's separate sessions command returned a generic CLI failure, so the readback above used the installed release CLI; it is not a claim that the fixed package passed session listing. The runtime-only build also lacks some plugin-SDK declaration exports, which the package script's final release-qualification check reported. Its generated package installed and ran cleanup successfully without payload or dependency-metadata edits. This is behavioral proof for cleanup, not release qualification. Initial restricted-sandbox attempts refused ownership inspection before removing any files; completed timings used normal host process permissions.

Fixed package SHA-256: b33730977e42e74464d82079fc376510f784b852913c482026cb9e7d129d4883.

Cleanup re-read, parsed, and serialized the same migration manifest for
every artifact reference after confirmation. Large migration runs could
keep the stopped Gateway offline for minutes before any file was removed.

Compare each distinct run once against the manifest snapshots already read
by the post-confirmation inventory. Keep the per-reference ownership and
final artifact checks in their existing paths.

Add retirement regressions for bounded manifest reads and confirmation-time
metadata changes that must preserve the originals.

Validation: 18 recovery mutation tests; doctor test graph typecheck;
targeted Oxlint and oxfmt; independent P0-P2 review; git diff --check.

Fixes openclaw#174072
@clawsweeper

clawsweeper Bot commented Oct 16, 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 commands Command implementations size: S labels Oct 16, 2026
@shoaibulhaque
shoaibulhaque marked this pull request as ready for review October 16, 2026 10:17
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment 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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Compare each shared recovery manifest once after confirmation while retaining existing artifact and ownership checks.

Example: Multiple recovery artifacts reference one migration manifest.

  • Before: The supplied regression records five manifest reads after confirmation.
  • After: Cleanup reads the manifest once and retires the selected originals.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused repair with installed-entry-point proof, existing-state preservation evidence, meaningful regression coverage, and successful exact-head gates.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The prior proof request is satisfied by exact-head installed cleanup output on Linux using release-created migration state: selected originals were removed, an unknown original remained protected, and configuration and history hashes stayed intact. Release-CLI readback confirms preserved sessions; the fixed package's separate listing failure and incomplete release qualification limit those additional claims without invalidating the cleanup scenario.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Cleanup repeatedly processes large shared manifests while the Gateway must remain stopped.
Reason: The change removes demonstrated redundant work within the existing owner and preserves user-visible cleanup decisions, consent, and safety checks.

Merge readiness

✅ Ready for maintainer review

This PR fixes a concrete cleanup performance defect still present on current main; no actionable correctness or security findings remain.

Priority: P2
Reviewed head: ad229d086746bd5f46cc3f9181c1dc9edccb8377

Before merge

None.

Findings

None.

Agent review details

How this fits together

The update cleanup CLI passes recovery inventory and consent to the Doctor retirement owner, which verifies offline ownership and preserved history before removing eligible rollback originals and recording disposal receipts.

flowchart TD
  A[Update cleanup CLI] --> B[Recovery inventory]
  B --> C[Offline ownership and confirmation]
  C --> D[Compare distinct manifests]
  D --> E[Verify destinations and originals]
  E --> F[Dispose originals and persist receipts]
Loading

Technical review

Best possible solution:

Land this focused optimization through the existing retirement owner while preserving cleanup eligibility and disposal safeguards.

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

Current-main source establishes repeated whole-manifest work per reference, and the contributor supplies a release-versus-head installed-CLI comparison; this read-only review ran no target code.

Is this the best way to solve the issue?

Reusing the post-confirmation inventory directly removes the repeated work without adding another owner, changing persisted formats, or weakening final artifact checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Post-confirmation recovery manifest verification keeps the original intent (78d2d91: Verify that recovery mappings remain unchanged after consent before retiring originals under exclusive offline ownership.)
  • Retirement mutation test organization keeps the original intent (fix(ci): run command tests across their allocated workers #154088: Split Doctor SQLite coverage into operation-specific files while preserving distinct recovery and mutation contracts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Focused introduced change: The pinned introduction diff replaces per-reference manifest reads with distinct-run comparisons against the post-confirmation inventory; per-reference ownership and final artifact checks remain. (src/commands/doctor-session-sqlite-retirement.ts:273, ad229d086746)
  • Inventory shares one run per manifest: Inventory reads each manifest into one run object and attaches that same object to its move references, making object-identity deduplication valid. (src/commands/doctor-session-sqlite-recovery-inventory.ts:147, ad229d086746)
  • Current main retains the defect: Fetched main still synchronously reads, parses, and serializes the complete manifest for every reference. (src/commands/doctor-session-sqlite-retirement.ts:277, b4ce369de7e8)
  • Original cleanup intent and feature history: The original merged cleanup implementation established conservative preservation, consent, and resumable disposal. This optimization preserves that intent. Feature history identifies Peter Steinberger as its principal contributor; an extended follow-history search encountered an unavailable old blob, while scoped history and current-main blame remained available. (src/commands/doctor-session-sqlite-retirement.ts:277, 78d2d914db75)
  • Installed cleanup and existing-state preservation: The full PR body supplies installed-CLI output for the exact head on Linux with Node 24.18.0, using states imported by released v2026.10.4. Cleanup removed 1,201 selected originals, retained the protected original, preserved configuration and history hashes, and retained readable history through the release CLI. Separate fixed-package session-listing and release-qualification limitations are explicitly disclosed. (ad229d086746)
  • Retirement safety coverage: Added tests exercise real migration and retirement I/O, bound repeated manifest reads, and retain originals when manifest metadata changes during confirmation; existing tests cover destination mutations, aliases, and interrupted disposal. (src/commands/doctor-session-sqlite.retirement-mutations.test.ts:26, ad229d086746)

PR surface

Source +6, Tests +51. Total +57 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 13 7 +6
Tests 1 51 0 +51
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 64 7 +57

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #174072
Summary: This PR implements the reported per-reference manifest comparison repair.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The defect prolongs Gateway downtime during optional operator-run recovery cleanup, with a bounded affected workflow.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster 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-16T10:33:54.546Z sha ad229d0 :: needs real behavior proof before merge. :: none

Reviewed October 16, 2026, 7:28 AM ET / 11:28 UTC (Revision 2).

@shoaibulhaque

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated the PR body with installed-CLI cleanup evidence for the reviewed head: 35.51 s on released v2026.10.4 versus 4.44 s on the locally packaged and installed fix. Both runs removed 1,201 selected originals while retaining the protected original. Before/after database row hashes, settings, and protected-file hashes match; all 1,200 sessions remain readable with the release CLI. The body includes command output, fixture sizes, and the package/readback limitations.

@clawsweeper

clawsweeper Bot commented Oct 16, 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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
steipete added a commit that referenced this pull request Oct 16, 2026
…rmation (#174249)

openclaw update cleanup --yes re-read and re-serialized the whole session-SQLite migration manifest once per artifact reference while the Gateway was stopped (O(references x manifest); ~9 minutes for a 13 MB manifest with ~7,500 references). The confirmation re-check now compares each distinct manifest once against the already-read inventory, keeping the changed-during-confirmation safety. Production net -1 LOC. Live: cleanup removed 33 originals and preserved SQLite, config, and the protected file byte-for-byte. Supersedes #174103, thanks @shoaibulhaque.

Fixes #174072

Co-authored-by: Shoaib <[email protected]>
@steipete

Copy link
Copy Markdown
Contributor

Thanks for this! We landed the fix in #174249 (a09c26b), which supersedes this PR and credits you as co-author: update cleanup now compares each recovery manifest once during confirmation instead of once per reference.

@steipete steipete closed this Oct 16, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…rmation (openclaw#174249)

openclaw update cleanup --yes re-read and re-serialized the whole session-SQLite migration manifest once per artifact reference while the Gateway was stopped (O(references x manifest); ~9 minutes for a 13 MB manifest with ~7,500 references). The confirmation re-check now compares each distinct manifest once against the already-read inventory, keeping the changed-during-confirmation safety. Production net -1 LOC. Live: cleanup removed 33 originals and preserved SQLite, config, and the protected file byte-for-byte. Supersedes openclaw#174103, thanks @shoaibulhaque.

Fixes openclaw#174072

Co-authored-by: Shoaib <[email protected]>
hilsbos pushed a commit to hilsbos/openclaw that referenced this pull request Oct 22, 2026
…rmation (openclaw#174249)

openclaw update cleanup --yes re-read and re-serialized the whole session-SQLite migration manifest once per artifact reference while the Gateway was stopped (O(references x manifest); ~9 minutes for a 13 MB manifest with ~7,500 references). The confirmation re-check now compares each distinct manifest once against the already-read inventory, keeping the changed-during-confirmation safety. Production net -1 LOC. Live: cleanup removed 33 originals and preserved SQLite, config, and the protected file byte-for-byte. Supersedes openclaw#174103, thanks @shoaibulhaque.

Fixes openclaw#174072

Co-authored-by: Shoaib <[email protected]>
(cherry picked from commit a09c26b)
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

[Bug]: update cleanup --yes re-reads the whole migration manifest per reference (O(refs × manifest)) — minutes of CPU with the Gateway stopped

2 participants