Skip to content

fix: stop calling a Git update's later checkout failure data at risk once Doctor finished - #201529

Closed
fuller-stack-dev wants to merge 5 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-lock-and-read-failures-not-at-risk
Closed

fuller-stack-dev wants to merge 5 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-lock-and-read-failures-not-at-risk

Conversation

@fuller-stack-dev

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

Copy link
Copy Markdown
Member

Status: not ready, recommended for closing. The ClawSweeper round on this head found that clearing the mark after Doctor also removes the only signal that stops final recovery from restarting a checkout whose HEAD failed verification (update-command-failure-recovery.ts:187). That is a loosening this PR cannot defend with a negative control, so the change should not land as is. A correct version needs a restart-unsafe signal that final recovery honors without the data-risk label; that change belongs with the recovery/guidance owner.

What Problem This Solves

A Git (in-place checkout) update marks the run state-migrated-no-rollback as data at risk just before it starts Doctor. That is reasonable while Doctor might stop part way through a migration, but the mark stayed after Doctor had finished: if the checkout then failed a later check (Control UI assets missing, git rev-parse HEAD failing, HEAD not at the target SHA), the run said "Keep the Gateway stopped: data at risk (state-migrated-no-rollback)" although every migration had completed and the candidate checkout owns the state it left.

User Impact

User impact: a Git update whose Doctor finished and whose later asset or HEAD check fails no longer records data at risk. Code rollback is still refused (Doctor ran), the restart is still marked unsafe, and the run still fails with its own reason (ui-assets-missing, head-verification-failed, target-sha-mismatch). A failed or refused Doctor keeps the mark, as before.

Why This Change Was Made

Invariant: "data at risk" needs evidence. A Doctor that failed may have stopped part way (and its child refusals are not carried through the failed-step path), so it keeps the mark. A Doctor that finished leaves complete state; a later checkout check failure is not evidence about the data.

update-runner-git.ts: after Doctor returns a successful step, recovery becomes { serviceRestartSafe: false, reason: "state-migration-started" } without dataAtRisk. stateMigrationStarted stays set, so rollbackError still refuses code rollback.

History: the pre-Doctor mark came from #172784, which labeled every "cannot roll back" as data at risk.

Not shipped (reported, not changed):

  • Lock classifier (P1-1, GatewayLockError → gateway-state-unverified). An earlier version of this PR deferred lock errors by type. Review showed GatewayLockError is thrown both for contention and for owners the state lock cannot exclude: historical and legacy (2026.6.33) locks, an owner in another process namespace, an interrupted database port (DatabasePortRecoveryError), a live owner lease seen after taking the state lock. Deferring by type dropped those real marks, so that change is fully reverted. A correct split needs a typed error at each producer, and then a classifier that defers only the typed contention and inspection-timeout cases. That is a follow-up.
  • Doctor database preflight catch (P1-1, any error → incomplete-migration). The preflight reports a held recovery store and a failed read through the same untyped "readiness could not be verified" error, so the catch cannot tell them apart without a typed cause from openclaw-database-preflight.ts.
  • Removing the pre-Doctor mark entirely (P1-3 as audited). A Doctor child that refuses with an explicit data-at-risk verdict (for example a live legacy owner) exits nonzero; createPackageUpdateDoctorCompletion returns a failed step without that verdict. The pre-Doctor mark is what keeps such a failure stopped on the Git path today, so it stays until the verdict is carried through the failed step.

Update behavior for published updaters

The Git runner runs in the installed updater, so this applies from the next update driven by a fixed version. Marks shipped updaters already recorded are left to the guidance/repair owner (verification.recovery.dataAtRisk, finalize:data-at-risk). Package installs never had the pre-Doctor mark; Git release mode does not use this runner.

Evidence

Behavior checked with the real Git runner against a real git repository (Doctor writes state, then the named failure happens):

  • head-error, head-mismatch, ui-missing (Doctor finished): no dataAtRisk; rollback not attempted; candidate checkout and migrated state kept. Base: state-migrated-no-rollback.
  • Negative controls, unchanged: doctor-failed and doctor-threw keep state-migrated-no-rollback; doctor-data-at-risk keeps Doctor's own unreadable-state.

Terminal recordings (raw output, idle gaps capped at 1 s, 3x speed):

  • Base / red: product code at d6f628897ad with this PR's test → 3 failed (the three post-Doctor cases), 3 passed (the controls).
pr2b-base-red-d6f628897ad.mp4
  • Head / green: 63a64ae9531 → 6 passed.
pr2c-head-green-63a64ae9531.mp4

Full raw logs are not attached because the artifact store rejected uploads from this machine.

Commands and results
  • node scripts/run-vitest.mjs src/infra/update-runner-git.test.ts src/cli/update-cli.preactivation-inspection.test.ts: pass.
  • node scripts/run-oxlint.mjs src/infra/update-runner-git.ts src/infra/update-runner-git.test.ts: pass. pnpm tsgo:core:all: pass. git diff --check: clean.

Test file audited in full: update-runner-git.test.ts. One expectation changed: the three post-Doctor failures no longer expect the mark. No case removed.

Review: autoreview does not run on this machine. A fresh independent reviewer and ClawSweeper (rating F/F/F) read the earlier version; their findings are why the lock classifier change was reverted and the pre-Doctor mark kept for failed Doctors.

Not proven

Steps this change still leaves to a person, and why:

  • A post-Doctor asset or HEAD failure still stops the update with the Gateway down and restart marked unsafe; the checkout is not at a verified state. The recorded guidance names openclaw update repair and openclaw triage. Rerunning the update fixes it once the checkout is healthy.
  • A failed Doctor keeps "keep the Gateway stopped": the updater cannot tell a partial migration from a harmless failure without the child's verdict.

…rt data at risk

A Gateway lock that is held, timed out or unreadable refused Doctor admission before any write, so it is now deferred contention instead of gateway-state-unverified. A live legacy owner or an owner in another process namespace, which the state lock cannot exclude, stays at risk. Git legacy updates no longer record state-migrated-no-rollback before Doctor runs; Doctor's own refusal and the measured schema decide.
@clawsweeper

clawsweeper Bot commented Nov 18, 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 Nov 18, 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: needs maintainer review before merge.

What this changes

This PR distinguishes retryable Gateway lock failures from concrete writer risks and stops Git updates marking data at risk before Doctor runs.

Example: Doctor cannot read the Gateway owner lock before opening repair writers.

  • Before: The refusal is data-at-risk / gateway-state-unverified.
  • After: The refusal is deferred / admission-unavailable, preserving the update's existing recovery verdict.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch is source-supported and has meaningful regression coverage, but the required shipped-entry-point behavior remains unproven.
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 failed update can tell users their data is at risk and withhold Gateway recovery even when maintenance never began.
Reason: The maintainer-authored direction restores the existing distinction between retryable admission failure and evidence-backed data risk without adding configuration or a competing recovery owner.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses two false data-risk classifications still present on main, and source review found no introduced correctness bug.

Priority: P1
Reviewed head: b215bea124e7a3213b919091196c9ea8d18fba4b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted CLI output or a terminal recording for lock refusal during update and an in-place Git update failure after Doctor starts, including a latest-stable upgrade with settings and data preserved.
Agent review details

How this fits together

Doctor classifies maintenance failures, the Git updater records recovery facts, and update finalization consumes those facts alongside persisted-state inspection to decide recovery and Gateway restart.

flowchart TD
  A[Update request] --> B[Git updater]
  B --> C[Doctor maintenance admission]
  C --> D[Lock failure classifier]
  D --> E[Recovery verdict]
  B --> F[Persisted state inspection]
  F --> E
  E --> G[Gateway recovery and guidance]
Loading

Technical review

Best possible solution:

Keep Doctor as the refusal classifier and derive Git migration risks from observed state or concrete owner refusals.

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

Current-main source directly shows both incorrect marks; the PR reports failing-base and passing-head tests, but this read-only review ran no target code.

Is this the best way to solve the issue?

The patch is the smallest coherent source fix: it refines the existing classifier with a legacy error subtype and removes the premature Git risk mark while retaining rollback prohibition and downstream state checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Doctor maintenance refusal classification changes intended behavior with a stated reason (51fcb7f: Preserve unsafe restoration and partial-publication failures while classifying maintenance admission refusals.)
  • Legacy Gateway lock failures keeps the original intent (aac5c4d: Prevent offline maintenance while a legacy Gateway that predates state-local coordination may still write.)
  • Git pre-Doctor recovery mark changes intended behavior with a stated reason (73bb905: Carry producer-owned data-risk facts into stopped-service recovery while preventing code rollback after possible migration.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +11, Tests +60. Total +71 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 19 8 +11
Tests 2 66 6 +60
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 85 14 +71

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.

Review metrics

Metric Value Why it matters
Production versus test changes Production +19/-8; tests +66/-6 The small production increase preserves a typed legacy-owner distinction; tests cover lock classification, partial-publication safety, and the existing Git failure matrix.

Labels

Label changes:

  • add P1: False data-risk verdicts can prevent update repair from restoring a stopped Gateway after otherwise retryable failures.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: False data-risk verdicts can prevent update repair from restoring a stopped Gateway after otherwise retryable failures.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 18, 2026, 7:06 PM ET / November 19, 2026, 00:06 UTC.

Only a lock held by a coordinated state owner, or a lock record that could not be read or checked in time (a typed GatewayLockInspectionError), is deferred. Every other Gateway lock failure keeps its gateway-state-unverified mark. The lock error classes move beside the namespace error so gateway-lock.ts stays under its line cap.
@fuller-stack-dev
fuller-stack-dev marked this pull request as draft November 19, 2026 00:52
…ctor

Revert the Gateway lock classifier change: GatewayLockError is thrown both for contention and for owners the state lock cannot exclude (historical and legacy locks, other namespaces, an interrupted database port, a live owner lease), so deferring by type dropped real risk marks. The Git runner keeps its pre-Doctor mark while Doctor may still have stopped part way, and clears it once Doctor finishes, so a later UI asset or HEAD check no longer names a data risk.
@openclaw-barnacle openclaw-barnacle Bot added size: XS and removed commands Command implementations size: S labels Nov 19, 2026
@fuller-stack-dev fuller-stack-dev changed the title fix: stop calling a busy Gateway lock or a Git update's Doctor start data at risk fix: stop calling a Git update's later checkout failure data at risk once Doctor finished Nov 19, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Closing without merging.

This set out to stop two paths from recording "data at risk" without evidence: lock contention during an update, and the mark a Git update sets before Doctor starts.

Neither change could be defended:

  • Lock classifier. The error type it keyed on is raised for ordinary contention and also for owners the state lock cannot exclude: historical and legacy locks, other namespaces, an interrupted database port, and a live owner lease. Treating that type as contention would have dropped real risk marks. The change was fully reverted.
  • Git pre-Doctor mark. Review found the mark is the only thing that stops final recovery from restarting a checkout whose HEAD failed verification. Clearing it after a successful Doctor has no negative control for that case.

A correct version needs typed lock errors at each producer, and a restart-unsafe signal that final recovery honors without the data-at-risk label. That is a larger design and will come as its own change.

The rollback half of this work (a failed schema read during rollback no longer reads as data at risk) continues in #201498.

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

Labels

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: XS 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