Skip to content

fix(state): prevent retained deleted agents from blocking Gateway startup - #200284

Merged
roboclaw-bot merged 1 commit into
mainfrom
roboclaw/ur-200271-retained-startup
Nov 16, 2026
Merged

roboclaw-bot merged 1 commit into
mainfrom
roboclaw/ur-200271-retained-startup

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes #200271: Gateway startup can crash-loop when a completed agent deletion intentionally retained an older database.

User Impact

Active agents can start while the deleted agent’s retained files stay byte-for-byte unchanged. Pending deletions keep their existing behavior. Active-agent and shared-state validation, refusal behavior, and permanent-purge capabilities are unchanged.

Why This Change Was Made

The startup copy-and-swap path added by #198389 (ef930ebbad771ae219e033f8c5b59a12b5445ffb) inventories physical agent stores without consulting deletion completion. Startup now consumes the deletion journal owner’s existing retained-ID query and excludes completed retained agents from both upgrade selection and shadow copying. No new schema, registry, fallback, or configuration is added.

The simplification pass keeps this decision with the existing deletion owner. Necessary scope: production +22/-6 lines, tests +103 lines, documentation +3 lines. Test growth is below the 400-line allocation threshold.

Evidence

  • Red base: unchanged production at 48cd549b1c48653061ec312e35fef62d13df62cf plus the regression: timeout 120s pnpm test src/state/state-upgrade.test.ts --maxWorkers=1 -t 'startup retained deletion' — 2 failed, 1 passed, 7 skipped; both completed-retention cases reject with no such module: vec0 from generic fallback. The pending-deletion control passes with today’s schema refusal/fallback failure.

  • Green fix: timeout 120s pnpm test src/state/state-upgrade.test.ts --maxWorkers=1 — 10 passed, 0 failed; 56.95 s command wall time (54.59 s Vitest duration; 13.394 s summed test time). Covers completed retention alone, completed retention beside a shared-state upgrade, and the pending-deletion control. CI seconds are not yet available.

  • Real SQLite, the existing v26 schema fixture, a retained session row, and a real vec0 virtual table reproduce the reported fallback error. Current-schema active stores are present. Retained database bytes and directory contents remain unchanged after the fixed upgrade; the active store bytes also remain unchanged.

  • Targeted lint and TypeScript compiler diagnostics: timeout 120s pnpm exec oxlint --type-aware --type-check --threads=1 --tsconfig config/tsconfig/oxlint.core.json src/state/state-upgrade.ts src/state/state-upgrade.test.ts — exit 0, zero diagnostics. A temporary negative control reported TS2322 and was removed.

  • timeout 30s pnpm exec oxfmt --check src/state/state-upgrade.ts src/state/state-upgrade.test.ts docs/install/updating.md and timeout 20s git diff --check pass. Commit hooks also pass.

  • Local ClawSweeper is unavailable. Independent autoreview, Codex, P0–P2, reviewed the full local candidate against 48cd549b1c48653061ec312e35fef62d13df62cf: scoped-clean, no actionable findings. Candidate diff SHA-256: 165afa0f222e905c275028524a56758567fd7f0b550f5723b66b0baa8103814a; committed without further code changes as db8faf1c6e41d7f83616ec570c4204eda24d4058. One hosted review will be requested if none is already pending.

  • Live upgrade from latest stable (Crabbox AWS Linux, Node 24.19.0):

    • Setup: npm [email protected] (d843d6a), isolated state. Created agents keeper and retired, started the stable Gateway, then called agents.delete {agentId: "retired", deleteFiles: false} and stopped it cleanly. The journal row was cleanup_completed=1, delete_files=0, phase=retiring; state was v22 and agents were v27. One tarball snapshot was used for both runs.
    • Base 48cd549b (red): startup listed agents/retired/.../openclaw-agent.sqlite v27 for upgrade. It logged State upgrade chain failed at agent-schema: .../retired/... is at schema 27 after the chain, expected 42, then fell back to the generic copy and set aside 7 rows. The retained database was rewritten (its sha256 changed) and its .seal was removed. The stores had no vec0 tables, so this run finished on the degraded generic-copy path instead of the reporter's no such module: vec0 exit. The vec0 crash is covered by the in-process regression above.
    • PR head db8faf1c (green): the upgrade inventory listed only state v22, keeper v27 and main v27. Startup reported State upgraded ... by migration chain: no fallback, no rows set aside. /healthz returned 200 {"ok":true,"status":"live"} and /readyz returned 200 {"ready":true,"coreReady":true,"failing":[]}. After the upgrade, state was v40 and keeper/main were v42. The retained retired database and seal were byte-identical (sha256 6616c54a… / 0a5e3ed5… before and after), and its journal row was unchanged. agents list shows main and keeper, and config (gateway.port) was preserved.
    • Both leases were stopped. The first box lost its worker connection mid-run and was replaced; the red evidence comes from that first box and the green evidence from the replacement, both from the same stable setup steps.

Limits: no live macOS launchd reproduction. The live stable-to-head proof above used stores without vec0 tables; the vec0 exit path is covered by the in-process regression with a real vec0 table. Broad checks are left to PR CI under the production-host restrictions.

Reported by @hannesrudolph

Work sessions

Linked for team reference; these sessions aren’t public.

@clawsweeper

clawsweeper Bot commented Nov 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 docs Improvements or additions to documentation size: S labels Nov 16, 2026
@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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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 Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR excludes completed retained-agent deletions from startup upgrade discovery and copying.

Example: Agent retired has a completed deletion with delete_files=0 and a retained schema-v26 database containing a vec0 table.

  • Before: Startup selects the retained database for migration, then can fail with no such module: vec0.
  • After: Startup skips the retained agent while continuing upgrades for active and shared stores.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch has no identified correctness finding, but the supplied test-only evidence does not satisfy the required shipped-behavior and upgrade proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A completed agent deletion that intentionally retained old files can prevent all active agents on that Gateway from serving.
Reason: The maintainer-authored direction restores an existing retention and readiness contract with a narrow repair; permanent purge remains separate from the startup defect.

Regression provenance

Regression provenance — verified: source commit ef930ebbad77 by Ayaan Zaidi; canonical PR #198389 (blame-to-merge-commit).

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this focused repair addresses a reported Gateway startup regression and restores documented retained-agent behavior; no introduced code defect was found.

Priority: P1
Reviewed head: db8faf1c6e41d7f83616ec570c4204eda24d4058

Before merge

  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted Gateway startup evidence with a completed retained v26 vec0 store, including retention beside a required shared-state upgrade, and a latest-stable upgrade preserving settings and data.
Agent review details

How this fits together

Gateway pre-bootstrap inventories SQLite state before normal readers start, runs necessary migrations in a private copy, and publishes validated changes through the existing durable swap owner.

flowchart TD
  A[Gateway startup] --> B[Database discovery]
  C[Deletion journal] --> B
  B --> D[Completed retained agents excluded]
  B --> E[Active and shared upgrade targets]
  E --> F[Private copy and Doctor]
  F --> G[Validation and durable swap]
Loading

Technical review

Best possible solution:

Keep completed retained stores outside startup migration and copying through the existing deletion journal owner, preserving active-store validation and pending-deletion handling.

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

Current source establishes retained-store misclassification and the validation-to-fallback path, supported by the reporter’s native failure trace and the PR’s reported red-base regression; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch fixes selection at the startup owner using the deletion owner’s existing query, and each production hunk serves the preservation invariant without adding parallel state or unnecessary machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit ef930eb adds src/state/state-upgrade.ts:139 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ef930ebbad77; files: src/state/state-upgrade.ts)

PR surface

Source +16, Tests +103, Docs +3. Total +122 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 22 6 +16
Tests 1 103 0 +103
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 128 6 +122

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported current-main regression prevents an affected Gateway from starting and repeatedly retries migration until operator intervention.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.

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 November 16, 2026, 5:53 PM ET / 22:53 UTC.

@roboclaw-bot
roboclaw-bot merged commit e3f8a67 into main Nov 16, 2026
146 checks passed
@roboclaw-bot
roboclaw-bot deleted the roboclaw/ur-200271-retained-startup branch November 16, 2026 23:56
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…de (openclaw#200284)

Startup state upgrade no longer selects or copies agent stores whose deletion completed with files retained (deletion journal: cleanup_completed=1, delete_files=0). Their older schema made the startup migration chain fail. That triggered the generic-copy fallback, which rewrote the retained database or exited with "no such module: vec0" and crash-looped the Gateway. Active agents, shared state and pending deletions keep their existing validation.

Proof: real-SQLite red/green regression (with a vec0 table); exact-head CI green; live Crabbox upgrade from npm 2026.11.4. On base the chain failed and fell back to the generic copy, rewriting the retained store. On the PR head the migration chain succeeded, /readyz was ready, and the retained store and seal were byte-identical.

Fixes openclaw#200271
Reported-by: @hannesrudolph

Co-authored-by: steipete <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 18, 2026
…de (#200284)

Startup state upgrade no longer selects or copies agent stores whose deletion completed with files retained (deletion journal: cleanup_completed=1, delete_files=0). Their older schema made the startup migration chain fail. That triggered the generic-copy fallback, which rewrote the retained database or exited with "no such module: vec0" and crash-looped the Gateway. Active agents, shared state and pending deletions keep their existing validation.

Proof: real-SQLite red/green regression (with a vec0 table); exact-head CI green; live Crabbox upgrade from npm 2026.11.4. On base the chain failed and fell back to the generic copy, rewriting the retained store. On the PR head the migration chain succeeded, /readyz was ready, and the retained store and seal were byte-identical.

Fixes #200271
Reported-by: @hannesrudolph

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

Release adaptation: preserve complete deletion snapshots, configured/registered surviving owners, pending deletions and symlink handling; read through the existing raw discovery handle. Uses independently reviewed release repair 15d2d80470374795c9e45c51e6228b3674798fc804c5841e82f3e36e9fe8053a.

(cherry picked from commit e3f8a67)

Co-authored-by: RomneyDa <[email protected]>
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
…aw#194058)

Failed-update triage now captures the operator's environment before managed candidate admission, so a coding agent installed only on the operator's PATH is still offered when the Gateway service's PATH differs. Restores the operator-environment contract from openclaw#134490 and keeps the launch confirmation from openclaw#143139.

Proof: shipped CLI on isolated Linux (Crabbox) with a running systemd Gateway: accept launches the operator-only agent, decline starts nothing, base 18bee8e reports no agent found; published 2026.11.1 upgrades to the fix with settings intact.

Co-authored-by: TorstenW <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: steipete <[email protected]>

(cherry picked from commit 7c702c3)

Release adaptation: Capture invoking operator env before candidate admission, forward to interactive triage only; preserve latest target selectors, confirmation and lease cleanup ordering. Exact three authorized production paths plus real lifecycle regression.

Follow-up dispositions: ad4863d fix: preserve the running installation when an agent updates its Gateway (openclaw#201570); dc73ec0 fix: let updates finish when another tool briefly reads OpenClaw's databases (openclaw#202541); d07b530 fix: clarify PostgreSQL schema upgrades for Git installs (openclaw#202098); e60ea9f test(update): add a Git release upgrade-survivor scenario (openclaw#201956); 2ef6f7b fix(update): build and serve Git releases outside node_modules (openclaw#201917); dbc1aa0 fix: keep the openclaw command and Gateway working after updating a pnpm install (openclaw#201735); f5e7641 fix: Git checkout updates across a schema change no longer end as post-update-failed after the new release starts (openclaw#201600); 2183caf fix: Git checkout updates no longer fail before the new release starts on a schema change or a busy database (openclaw#201463); 47e8649 fix: explain why Doctor cannot restore a scheduled job’s account (openclaw#201550); 8f2cfd4 fix: remove updater-only restrictions from agent maintenance guidance; cb5cfb2 fix: keep a doubtful killed-update recovery on the repair path (openclaw#201361); 24cb734 fix: keep carried-over scheduled jobs running after updates (openclaw#200653); d1276e1 feat(doctor): check OpenClaw ID member roles and honor an optional roles default (openclaw#197785); 0a39956 fix: finish updates when another tool reads OpenClaw's databases during the update (openclaw#201330); ea1c9d5 fix(update): settle remounted package publications before admission (openclaw#201336); 66b5212 fix(update): isolate malformed retained-install markers (openclaw#201199); 7e79c83 fix: let the next update finish a killed source checkout update (openclaw#201009); d905d8a fix: let the next update finish a killed update after the machine restarted (openclaw#200994); fdf0c95 fix: let the next update finish a killed update that had already installed the new version (openclaw#200866); 0c19bcd chore(release): close out 2026.11.5 on main (openclaw#200577); a1940e0 fix(matrix): keep explicit recovery available during deferred migration (openclaw#200805); 18b4776 improve: explain package baseline drift during updates (openclaw#200802); 1ad4cad fix(doctor): reclaim macOS updater runtimes blocked by non-updater processes (openclaw#200732); 427c857 fix: keep one missing archived transcript from blocking every update (openclaw#200733); 802e3f7 fix(update): keep valid cold archives from blocking updates (openclaw#200659); 23fca1a fix: let the next update continue after a killed update when nothing is left to repair (openclaw#200680); 3afe212 fix: let Doctor publish unchanged plugin migrations in any order (openclaw#200658); f65e4db fix(doctor): reclaim runtimes blocked by unrelated Linux processes (openclaw#200657); dab086c fix(update): let candidate Doctor read plugin dependencies from the staged package (openclaw#200595); 3447bee fix(update): keep updates going when the predecessor writes during its stop (openclaw#200569); 0ce9c77 fix: let the next update settle a package publication that a killed update left behind (openclaw#200550); ae31ea3 fix(update): repair handoffs in the journal-pinned lease store (openclaw#200532); 74020ea fix: continue updates when initial SQLite capture is stale (openclaw#200328); 6747b1e feat(update): run Git checkout installs from releases behind the release link (openclaw#199706); e3f8a67 fix(state): keep completed retained agent stores out of startup upgrade (openclaw#200284); 3c512c5 fix(gateway): move managed update lease operations off the main thread (openclaw#200169); ea69fcb chore(release): close out 2026.11.4 on main (openclaw#199956); 618bf31 fix(state): bound startup upgrade copies and pruning to owned state (openclaw#199929); e4a3093 perf(update): replace the candidate canary with a runtime contract check (openclaw#198268); 5dbf569 fix(update): plugin failures never fail an update or Gateway health; 764761e fix(update): refuse missing host prerequisites in one line and record a cause per attempt; 4c4fef4 fix(ui): update dialog claims installation before progress is confirmed (openclaw#199254); 136e1f6 fix(update): retrying an update from a dev checkout is refused after a killed update (openclaw#198673); 3bd03da fix(update): avoid duplicate database copies while the Gateway is stopped (openclaw#198148); 68a839b fix: isolate held agent databases until explicit restoration (openclaw#198180); e333f7e chore(ci): drop retired test-lines allocation records (3/3) (openclaw#197657); fd6fa47 fix: converge Gateway updates with environment-only service overrides (openclaw#196371); 7cf5e75 fix: clarify split-install updates and blocked Doctor repairs (openclaw#196342); 6ff8c86 fix(update): retain lazy sqlite catalog generation (openclaw#197095); 930e1f7 fix: keep stable updates and recovery free of premature migrations (openclaw#196474); a15f737 fix: preserve external plugin data during update rehearsal (openclaw#196301); 92798ae fix: updates survive interrupted heartbeat runs (openclaw#195656); c1e55e2 fix(update): restore LaunchAgent registration after repair contention (openclaw#195406); 715c610 fix(doctor): repair retained ISO session end timestamps (openclaw#194685); 689cfc8 fix(update): reclaim dead closing triage repair leases (openclaw#194503); 86bc89e fix(doctor): keep standing Codex parameter advice out of retirement blockers (openclaw#193650); 691bc8d fix(backup): read the backup engine without copying the live database (openclaw#194234); 000542f fix(backup): backups and updates fail on slow storage when a header probe batch misses its deadline (openclaw#194239); 31a65d5 fix(update): skip --no-lazy-fetch on Git versions without it (openclaw#194198); e45e99d fix(update): preserve dev update sources in tag-only Git clones (openclaw#193109)

Validation: Baseline2 intended operator-agent failures/32 controls passed; candidate34/34passed (194058-green.log). Accept launches synthetic operator-only CLI with expected env, decline starts nothing. Isolated updater flow, not live systemd/upgrade qualification.

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

Labels

docs Improvements or additions to documentation P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Startup migrates completed retained-agent stores and crashes with vec0 error

1 participant