Skip to content

fix(update): keep a launched candidate's restart failure free of a data-risk mark - #201894

Merged
fuller-stack-dev merged 5 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-evidence-marks-restart
Nov 22, 2026
Merged

fuller-stack-dev merged 5 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-evidence-marks-restart

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Problem

After a migrated update, finishUpdate holds rollbackBlockedReason = state-migrated-no-rollback for the rest of the run. completeUpdateCommandResult stamps any later status: error with that block as dataAtRisk. The run then ends with "Keep the Gateway stopped: data at risk (state-migrated-no-rollback)".

The commonest error at that point is a restart health failure. The candidate started and answered as the new version, then missed core readiness inside the budget: a slow sidecar, a refused agent database, a plugin reload. That candidate is running on the state it migrated. Nothing shows the state was damaged. Yet the run records a data risk, and the guidance tells the operator to keep a running Gateway stopped. Since #201668, openclaw update repair can verify consistent state and record a receipt that resolves the mark, but only after extra verification, and only after the operator has first been given misleading guidance. The mark comes from the restart failing, not from anything observed about the data.

The same failure also printed Rollback: reinstall OpenClaw <previous version> ... from the restart verifier, even though older code cannot read the migrated state.

This is audit entry 1 ("blanket rollbackBlockedReason stamp"), for its highest-traffic producer: the restart.

Rule

A data-at-risk mark needs positive evidence. After restart-health-failed, the block is released only on launch evidence read after readiness failed:

  • the native service runtime still reports the process that answered. This reuses readFailedUpdateGatewayState, which keeps the recorded identity only while the same PID is still running, so a candidate that exited or was replaced during polling is no evidence;
  • that process owns every listener on the Gateway port (fresh port inspection, the restart inspector's ownership rule). A version answered by another process on any bind address is no evidence, and neither is an unattributed listener;
  • that process's recorded version equals the candidate's version, with no build mismatch, and its recorded build equals the candidate's build whenever the update knows it;
  • the version it replaced is known and differs.

When it is released:

  • the result is the restart-health failure (readyz-unhealthy). Restart stays unsafe (runtime-verification-failed), with no dataAtRisk;
  • rollback is not attempted. It would hand the migrated state to a build that cannot read it. rollbackOutcome records not-attempted: state-migrated-no-rollback, so status and report readers keep the migration fact.

While any rollback block is set, or the recorded rollback outcome is a refusal (the final-recovery pass), the restart verifier drops the reinstall advice. It prints Rollback: unavailable; update state was migrated, ... for state-migrated-no-rollback, or Rollback: unavailable; rollback safety could not be verified, ... for rollback-state-unverified (for example, PostgreSQL state with no pre-activation baseline).

Everything else keeps the mark exactly as before:

Restart observation Before After
Candidate still running with its PID and owning the port, answered as the new version, health failed data at risk, rollback attempted (and refused by the migration check) restart-health failure, no data risk, no rollback
Restart accepted, but no process ran (queued task, start never happened) data at risk data at risk
Restart command failed data at risk data at risk
Candidate answered, then exited while readiness was polled data at risk data at risk
Another process replaced the one that answered data at risk data at risk
A different process owns the port that answered data at risk data at risk
Port busy, listener owner unattributed data at risk data at risk
Managed PID owns one bind address, another process owns a second data at risk data at risk
Update knows the candidate build, answer named none data at risk data at risk
Match flag left by an earlier observation, wrong version data at risk data at risk
Port answered as the candidate, but no service PID (including after a Gateway-triggered update recorded its own PID) data at risk data at risk
Same version, different build data at risk data at risk
Version unchanged by the update, or previous version unknown data at risk data at risk
Split-root update (original-service compensation) data at risk data at risk (unchanged path)
Runtime or record unreadable data at risk data at risk

An accepted restart or "start attempted" is not treated as launch evidence. That gap is why #201529 was closed.

Change

  • update-command-verification.ts owns the recorded activation facts and the restart failure report:
    • releaseLaunchedState applies the rule above. When it releases the block, it records the not-attempted: state-migrated-no-rollback rollback outcome in the run ledger, where status and final recovery read it (result.rollbackOutcome ??= recorded.verification.rollbackOutcome). If that record fails, the block stays.
    • The health-fact producer now always writes pid. Before, a PID-less observation omitted the key, so the merge kept the previous process's PID.
    • The failure advice honors the rollback refusal.
  • update-command-post-update.ts: forwards rollbackBlockedReason to the restart, and one call after the existing activationVerified branch skips rollback when the block is released. Three lines, so the file stays within its 700-line cap after main's growth.
  • update-command-service-context-types.ts: the restart parameter type. The restart verifier receives it through main's existing parameter spread; update-command-service.ts is unchanged.
  • scripts/tests/update-restart-module-outcome.mjs: the vm fixture exposes the new export from the real verification module, as it already does for its siblings.

No config key, stored field, schema value or exit code changes. rollbackOutcome.reason is free text, and this reuses the existing reason. The only text change is the verifier's rollback line, shown only when a block is set.

What is left to a person

For the converted case:

  • The run ends as a restart-health failure. The existing next step names openclaw update repair, openclaw gateway status --deep and openclaw triage.
  • Repair is no longer blocked by a data-risk mark it cannot clear.
  • Whatever makes the candidate unhealthy (a channel, an agent database, a plugin) still needs its owner's fix. The readiness report names it.

For the cases that keep the mark, the existing steps remain. They stay manual because no running build has been shown to own the migrated state, and starting one automatically is exactly what the mark exists to prevent.

Evidence

Exact base 0eb6488cd3c, head b1407681922. The recordings are from that head. Later commits only merge main (including #201668 and #200578) and move the rollback-outcome record into the verification owner. That move is covered by the ledger assertions in the same tests, which pass on the final head. The same test files run at both. Only the four product files above are swapped.

Each guard is mutation-proven. With the guard removed, the named control fails:

Guard removed Failing control
live runtime re-read (recorded snapshot only) candidate exited, process replaced
listener owned by the managed PID listener not owned, listener unattributed
every listener owned (any one is enough) listener shared
known previous version previous version unknown
candidate build required when known build not answered
version equality (match flag only) stale match flag
versionMatch !== false build mismatch
serviceRunning === true candidate exited (recorded)
service PID no service PID
version changed version unchanged
split-root exclusion split-root contract test
producer clears pid clears an earlier process's PID when the running service reports none
refusal-aware rollback advice offers the previous version only while rollback is allowed (refusal=restart)
recorded refusal honored in final recovery ... (refusal=recorded)
refusal-specific wording ... (refusal=unverified)

Checks on head:

  • pnpm tsgo:core and pnpm tsgo:core:test pass.
  • oxlint and oxfmt are clean.
  • The line-cap ratchet passes; update-command-post-update.ts stays within 700.
  • Affected suites, 10 files, 0 failures: update-command-post-update-repair, -post-update-recovery, -post-update, -verification, -service, -database-rollback, -lifecycle, -original-service, test/scripts/update-restart-module-outcome, test/scripts/eager-import-closure. These ran on the same product tree before the rebase over unrelated main commits (UI locales, automations, Doctor image candidate, Gateway history, plugins). None of them touch update, port, restart or daemon code.

Review so far:

  • An independent review found no blocker. Its findings are addressed: the stale PID merge, keeping the migration fact on record, the split-root path, the unchanged version, and weak assertions.

  • ClawSweeper round 1 found two P2s, both addressed. Facts read before readiness polling could describe a candidate that had since exited; the live re-read now covers that. The verifier printed reinstall advice despite the refusal; that is now refusal-aware.

  • ClawSweeper round 2 (patch tier C) found three more, all addressed. A version answer was not tied to the managed PID; the listener ownership check now does that. The final-recovery verifier pass still offered reinstall; it now honors the recorded refusal. The base comparison said "rolled back"; it now says the finalizer calls a rollback that the migration check refuses.

  • ClawSweeper round 3 (last round) found four. All four are fixed in this head, because each one either dropped the mark on ambiguous evidence or printed a false message. A version answer could come from a non-owned listener on another bind address; every listener must now be owned. An unknown predecessor version passed the "changed" check; it now has to be known. A version answered without a build passed while the update knew the build; the build is now required. "State was migrated" was printed for the PostgreSQL no-baseline refusal; that refusal now has its own wording.

Follow-ups (not in this PR)

  • Hidden listener (rating round 4, P2): when process visibility is restricted, lsof can return only the managed user's listener and omit another user's listener on a different address. If that hidden listener answered the version probe, the ownership check still passes. Attributing the reply needs the Gateway's health reply to name its PID or boot identity per listener, which is a protocol change. That is a decision for Jason, so it is not done here.

  • PostgreSQL without a pre-activation baseline (round 4, P2): the first restart-verifier pass still offers "reinstall the previous version", which the rollback owner later refuses. Base prints the same line in the same state; this PR neither introduces nor widens it.

  • Real-path proof of the restart verifier feeding this check. The finalizer tests fake the restart outcome and write the facts the verifier would record. The producer-side PID behavior and the advice are tested on the real verifier.

  • A real Docker cell (see below).

  • The remaining audit catch-alls, by owner: migration/rollback (update-command-rollback.ts default and catch, update-command-database-backup.ts rollback-start and assertRollbackSafe), Doctor classifier and preflight (doctor-maintenance-inspection.ts), Git legacy pre-Doctor mark (update-runner-git.ts), and service recovery admission (update-command-service-recovery.ts).

Not proven

No real Docker cell. This PR's proof is unit and mutation tests only: red on base, green on head, and every guard mutation-killed. No packaged update with a live, write-loaded Gateway exercises this path. Within the agreed one-hour bound I tried these environment-level faults (no product test hook):

  • Startup that never completes (for example a plugin or sidecar that hangs): rejected. The updater classifies a still-starting Gateway as readiness-pending, not restart-health-failed, so it never reaches this path.
  • Child-runtime loss (removing the Node binary after the candidate starts): rejected. It is timing-dependent, and the runtime owner schedules its own restart.
  • An isolatable second agent whose database belongs to main: the most promising. Readiness reports agent-database:<id> with coreReady: false while the Gateway owns its port and answers its version, and real agent-schema migrations exist between v2026.11.6 and main. I wired it into an update-matrix harness copy and built head and base packs. It was not run: the Docker lock was taken by release-critical cells, then the session was interrupted. Two things remain unverified: the fault was never observed, and the update's Doctor might refuse or repair that database before the restart.

The unit tests run the real finishUpdate, rollback selection, run ledger, live-runtime and port re-read, final recovery and guidance code. Only the service manager, the restart outcome, the rollback executor and the port inspection are faked.

@clawsweeper

clawsweeper Bot commented Nov 19, 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 cli CLI command changes scripts Repository scripts size: S labels Nov 19, 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. 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head fdc7a75b3c0ce089be6712ae54ed7c7d0a8cc3cf, but the PR head is now 4bac5b6b1ef269a9af8bbef144c11e9b85667c3d. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-11-19T15:00:03.296Z sha fdc7a75 :: needs maintainer review before merge. :: none

@fuller-stack-dev
fuller-stack-dev force-pushed the fix/update-evidence-marks-restart branch from fdc7a75 to c4cafa0 Compare November 19, 2026 15:18
@fuller-stack-dev
fuller-stack-dev force-pushed the fix/update-evidence-marks-restart branch from c4cafa0 to b5595fa Compare November 19, 2026 15:52
…ta-risk mark

After a migrated update, a restart health failure was stamped with the
migrated-state block as data at risk and a rollback was attempted, even
when the candidate was running and had answered as the new version.

Release the block only on launch evidence read after readiness failed:
the native service still runs the process that answered, that process
owns every listener on the Gateway port, its recorded version equals the
candidate's with no build mismatch (and its build matches when known),
and the version it replaced is known and differs. The run then ends as
a restart-health failure, restart unsafe, no data risk, and rollback not
attempted (recorded as state-migrated-no-rollback). Split-root updates keep their existing path.

While rollback is refused, including in the final-recovery pass where
the refusal is recorded as the rollback outcome, the restart verifier no
longer advises reinstalling the previous version, and names whether the
state was migrated or rollback safety could not be verified.

Health observations now always write the PID, so a PID-less observation
no longer inherits an earlier process's PID through the verification merge.
@fuller-stack-dev
fuller-stack-dev force-pushed the fix/update-evidence-marks-restart branch from b5595fa to b140768 Compare November 19, 2026 16:27
@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review November 19, 2026 16:27
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 21, 2026
…arks-restart

# Conflicts:
#	src/cli/update-cli/update-command-service.ts
… its owner

main grew update-command-post-update.ts to its line cap. The verification owner now records the not-attempted rollback outcome in the run ledger, where status and final recovery read it, so the finalizer adds one call line.
@fuller-stack-dev
fuller-stack-dev merged commit 648619c into openclaw:main Nov 22, 2026
153 of 154 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the fix/update-evidence-marks-restart branch November 22, 2026 04:31
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 22, 2026
…9388 stage 5)

Absorbs openclaw/openclaw main b949a1c
(62 commits past the absorbed 5a3e6b1, which is the merge-base) into
a329243, so openclaw#129388's presentation can fast-forward. rerere was off
for the merge; nothing arrived pre-staged.

7 content conflicts:
- Generated, regenerated rather than hand-merged: config-baseline counts
  and sha256 (config:docs:gen; core 2668 + fork 17 = 2685) and gateway
  predicates.js (gateway:validators:gen). Node 24.21.0 and Bun 1.4.4
  write byte-identical output.
- src/infra/worker-cpu.ts: upstream openclaw#202507 moved WorkerCpuHandle and
  WorkerMemoryMessage into worker-cpu-types.ts, which makes the fork's
  Pick<> line-cap edit (57703db) moot; upstream's type move is taken
  unchanged. The Worker launch composes both edits: upstream's
  process-generation file resolution (openclaw#202495/openclaw#202507, skipped for eval
  sources) and the fork's reviewed compiler policy published at launch
  (2a10009). They touch disjoint inputs (filename vs execArgv and
  environment data). Upstream's shared worker host starts its one
  physical Worker through createCpuTrackedWorker, so it publishes the
  same policy.
- update-cli.fresh-doctor.test: openclaw#203194 (prepared releases and a
  resident launcher) deleted the two Git current-process tests; the
  fork's cliArgs config-validate matcher lived in one of them and goes
  with it. The fork's isGatewayCommand install matcher stays (merged
  cleanly) and the now-unused cliArgs import is dropped.
- update-cli.target-schema.test: openclaw#203194 deleted the four trailing Git
  in-place tests; every fork compiler-flag matcher (5780288 and
  earlier) lived in them. The file now equals upstream's.
- update-command-definition-recovery.test-support: both imports kept
  (the fork's isCliCommand/isGatewayCommand, upstream openclaw#201894's
  releaseLaunchedState); upstream's 199 added lines carry no positional
  argv matchers.

Refs openclaw#129388

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 23, 2026
…ta-risk mark (openclaw#201894)

* fix(update): keep a launched candidate's restart failure free of a data-risk mark

After a migrated update, a restart health failure was stamped with the
migrated-state block as data at risk and a rollback was attempted, even
when the candidate was running and had answered as the new version.

Release the block only on launch evidence read after readiness failed:
the native service still runs the process that answered, that process
owns every listener on the Gateway port, its recorded version equals the
candidate's with no build mismatch (and its build matches when known),
and the version it replaced is known and differs. The run then ends as
a restart-health failure, restart unsafe, no data risk, and rollback not
attempted (recorded as state-migrated-no-rollback). Split-root updates keep their existing path.

While rollback is refused, including in the final-recovery pass where
the refusal is recorded as the rollback outcome, the restart verifier no
longer advises reinstalling the previous version, and names whether the
state was migrated or rollback safety could not be verified.

Health observations now always write the PID, so a PID-less observation
no longer inherits an earlier process's PID through the verification merge.

* refactor(update): record the launched candidate's rollback outcome at its owner

main grew update-command-post-update.ts to its line cap. The verification owner now records the not-attempted rollback outcome in the run ledger, where status and final recovery read it, so the finalizer adds one call line.
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…ta-risk mark (#201894)

* fix(update): keep a launched candidate's restart failure free of a data-risk mark

After a migrated update, a restart health failure was stamped with the
migrated-state block as data at risk and a rollback was attempted, even
when the candidate was running and had answered as the new version.

Release the block only on launch evidence read after readiness failed:
the native service still runs the process that answered, that process
owns every listener on the Gateway port, its recorded version equals the
candidate's with no build mismatch (and its build matches when known),
and the version it replaced is known and differs. The run then ends as
a restart-health failure, restart unsafe, no data risk, and rollback not
attempted (recorded as state-migrated-no-rollback). Split-root updates keep their existing path.

While rollback is refused, including in the final-recovery pass where
the refusal is recorded as the rollback outcome, the restart verifier no
longer advises reinstalling the previous version, and names whether the
state was migrated or rollback safety could not be verified.

Health observations now always write the PID, so a PID-less observation
no longer inherits an earlier process's PID through the verification merge.

* refactor(update): record the launched candidate's rollback outcome at its owner

main grew update-command-post-update.ts to its line cap. The verification owner now records the not-attempted rollback outcome in the run ledger, where status and final recovery read it, so the finalizer adds one call line.

Release adaptation: Retain stable Git restart behavior; use the existing exact listener-ownership helper and explicitly pass the rollback refusal through the stable verifier call.

Companion audit: No later same-path or PR follow-up in pinned main. Main-only Git release-link changes are not applicable; release uses its existing in-place update flow.

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

Labels

cli CLI command changes P1 High-priority user-facing bug, regression, or broken workflow. scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant