Skip to content

fix(gateway): keep listener live when restart state is invalid - #120966

Merged
steipete merged 2 commits into
mainfrom
codex/reload-preflight-safety
Aug 9, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/reload-preflight-safety

Conversation

@steipete

@steipete steipete commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Related: #35862

What Problem This Solves

Fixes an issue where a config write that required a Gateway restart could close a healthy listener even when the persisted SQLite state could not be reopened by the successor lifecycle. The restart then failed before returning a server handle, leaving the process alive without a listener and preventing an external supervisor from restoring service cleanly.

Why This Change Was Made

Config-reload restart admission now performs a fresh, read-only database readiness check before resolving config secrets or emitting the restart signal. It verifies the canonical shared-state schema and every registered agent database with the same maintenance-owned contracts startup relies on. If readiness fails, the existing bounded retry owner keeps the current lifecycle serving, logs Doctor guidance, and retries without signaling, resetting task registries, writing a supervisor handoff, or starting a duplicate listener.

The readiness loader stays behind a lazy runtime boundary so this safety check does not expand the cold Gateway startup import graph. This is AI-assisted work; the implementation and owner boundaries were inspected directly.

User Impact

Operators keep a reachable Gateway when a restart-required config change coincides with noncanonical persisted database state. After openclaw doctor --fix repairs the state, the already-owned retry can proceed normally.

Evidence

  • Blacksmith Testbox: https://github.com/openclaw/openclaw/actions/runs/31299235406
  • Focused Vitest: 223 assertions passed across database readiness, restart ordering/retry, existing managed reload behavior, and startup import boundaries.
  • Remote check:changed: formatting, max-lines, dependency/architecture guards, dead-code scans, production/test typechecks, lint, database-first guards, and import cycles passed.
  • Ordered regression proves an unhealthy database check runs before secrets preparation and restart signal delivery, then emits exactly once after readiness recovers.
  • State and registered-agent SQLite regressions use fresh read-only handles and prove noncanonical current schemas are rejected without mutation.
  • Source-blind isolated process proof first failed and exposed a missing managed-reloader handoff; after that wiring repair, the same contract passed with the original PID and old port healthy, the configured replacement port unbound, persisted config confirmed, and explicit restart-preflight/Doctor guidance in logs.
  • Autoreview: clean before the initial commit (confidence 0.93) and after the behavior-driven wiring repair (confidence 0.99), with no accepted/actionable findings.
  • Production LOC: +86/-8 (net +78), justified by the new restart safety/ownership boundary and shared state + agent schema contract coverage. Tests: +182/-12.

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 9, 2026
@steipete
steipete marked this pull request as ready for review August 9, 2026 06:55
@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready at eab6caa1118aa2e885b85a46823f7c369b511b7f.

Root cause: config-reload restart admission preflighted candidate secrets but not fresh successor-owned database state. A healthy process could therefore close its listener, reset task runtime ownership, and only then discover that a fresh shared-state/agent database open was invalid.

The fix checks current persisted database readiness through fresh read-only maintenance contracts before secrets preparation or signal emission. Failed readiness remains on the existing retry owner; no SIGUSR1, supervisor handoff, task-registry reload, or replacement listener occurs until repair succeeds.

Proof:

Production LOC: +86/-8 (net +78), justified by the new restart safety/ownership boundary and shared-state plus registered-agent sibling coverage. Tests: +182/-12.

Known proof gaps: none.

@steipete
steipete merged commit 266ad72 into main Aug 9, 2026
124 of 126 checks passed
@steipete
steipete deleted the codex/reload-preflight-safety branch August 9, 2026 07:28
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

gateway Gateway runtime maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant