Skip to content

fix(gateway): skip restart sentinel for hot-applied config writes - #144764

Open
wangyan2026 wants to merge 2 commits into
openclaw:mainfrom
wangyan2026:fix/gateway-hot-apply-sentinel-144063
Open

wangyan2026 wants to merge 2 commits into
openclaw:mainfrom
wangyan2026:fix/gateway-hot-apply-sentinel-144063

Conversation

@wangyan2026

@wangyan2026 wangyan2026 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Related to #144063

What Problem This Solves

A hot-applied config.patch (e.g. agents.defaults.model) requires no Gateway restart, but resolveGatewayConfigRestartWriteResult persisted a restart sentinel unconditionally. The next unrelated Gateway start — a container upgrade hours later — then replayed the stale notice with the old config-patch reason and a doctor --non-interactive recommendation that doctor --help describes as "Run without prompts (safe migrations only)", not a read-only check.

Why This Change Was Made

The restart sentinel is now persisted only when the config write actually requires a Gateway restart.

  • resolveGatewayConfigRestartWriteResult gates tryWriteRestartSentinelPayload on restartRequirement.requiresRestart. A hot-applied write returns sentinelPersisted: false and never calls writeRestartSentinel, so no stale row survives for the next start to consume.
  • buildConfigRestartSentinelPayload withholds the doctor hint for hot-applied writes (doctorHint: null). There is no restart to follow up on, and doctor --non-interactive can apply safe migrations — not a read-only check.
  • Restart-requiring writes (gateway.port, reload.mode: off, plan.restartGateway) still persist the sentinel and carry the doctor --non-interactive hint as before.
  • The consumer (loadRestartSentinelStartupTask) is unchanged. It still serves update-kind sentinels and legitimate restart-requiring config sentinels. The fix is at the producer owner, which Codex confirmed is "narrower than suppressing all restart notifications or adding a new setting."
  • formatDoctorNonInteractiveHint is unchanged. It is shared by four callers (/restart, update, update-restart-sentinel-payload, config); a global --lint change would affect restart-requiring and update paths where safe-migration semantics are intentional.

User Impact

Owners no longer receive a stale "Gateway restart config-patch ok" notice on an unrelated later Gateway start after a hot-applied config change. The misleading doctor --non-interactive recommendation no longer follows a write that required no restart. Restart-requiring config writes are unaffected.

Evidence

Current main persists the restart sentinel for every config.patch/config.apply write, even when resolveConfigRestartRequirement returns requiresRestart: false. PR #83041 (commit 96e27c6ea8c) introduced the requiresRestart field into payload.stats but did not connect it to the persistence gate. Codex review (2026-09-10) confirmed: "a successful hot-applicable config.patch persists a nonempty notice that startup later consumes without checking restart necessity or age."

Exact head gates persistence on requiresRestart. Live proof calling the exported production function shouldAwaitGatewayConfigApplication (returns !requiresRestart):

$ node --import tsx --input-type=module <<'NODE'
import { shouldAwaitGatewayConfigApplication } from "./src/gateway/server-methods/config-write-flow.ts";
const hot = shouldAwaitGatewayConfigApplication({
  changedPaths: ["agents.defaults.model"],
  previousConfig: { agents: { defaults: { model: "old-model" } } },
  nextConfig: { agents: { defaults: { model: "new-model" } } },
});
const restart = shouldAwaitGatewayConfigApplication({
  changedPaths: ["gateway.port"],
  previousConfig: { gateway: { port: 4000 } },
  nextConfig: { gateway: { port: 4001 } },
});
console.log("hot-apply agents.defaults.model:", hot, "(true = no restart required)");
console.log("restart-requiring gateway.port:", restart, "(false = restart required)");
NODE
hot-apply agents.defaults.model: true (true = no restart required)
restart-requiring gateway.port: false (false = restart required)

Regression tests verify the gate and the conditional doctor hint (mocked sentinel persistence):

$ node scripts/run-vitest.mjs src/gateway/server-methods/config-write-flow.test.ts -- --reporter=verbose
 ✓ |gateway-methods| src/gateway/server-methods/config-write-flow.test.ts > resolveGatewayConfigRestartWriteResult > does not persist a restart sentinel for a hot-applied write 6ms
 ✓ |gateway-methods| src/gateway/server-methods/config-write-flow.test.ts > resolveGatewayConfigRestartWriteResult > persists a restart sentinel with a doctor hint for a restart-requiring write 5ms
 Test Files  1 passed (1)
      Tests  10 passed (10)

The hot-applied test asserts sentinelPersisted === false, writeRestartSentinel not called, and doctorHint === null. The restart-requiring test asserts sentinelPersisted === true, writeRestartSentinel called once, and doctorHint contains openclaw doctor --non-interactive.

Real persistence proof (no mocks on writeRestartSentinel; real temp SQLite state DB via OPENCLAW_STATE_DIR):

$ node scripts/run-vitest.mjs src/gateway/server-methods/config-write-flow.integration.test.ts -- --reporter=verbose
 ✓ |gateway-methods| src/gateway/server-methods/config-write-flow.integration.test.ts > resolveGatewayConfigRestartWriteResult real persistence > does not persist a restart sentinel row for a hot-applied write 322ms
 ✓ |gateway-methods| src/gateway/server-methods/config-write-flow.integration.test.ts > resolveGatewayConfigRestartWriteResult real persistence > persists a restart sentinel row for a restart-requiring write 220ms
 Test Files  1 passed (1)
      Tests  2 passed (2)

The hot-applied integration test reads the real gateway_restart_sentinel table after resolveGatewayConfigRestartWriteResult and asserts the current row is undefined — no stale row survives for a later startup to consume. The restart-requiring integration test asserts the current row exists with kind: "config-patch", status: "ok", stats.requiresRestart: true, and doctorHint containing openclaw doctor --non-interactive. This proves the changed persistence behavior end-to-end at the storage owner, not just the mocked call path.

Config-write/startup flow proof (real Gateway + config.patch RPC + DB + startup consumer input):

$ node --import tsx /tmp/proof-144063.mts
=== Scenario 1: hot-applied config.patch (agents.defaults.model) ===
RPC ack sentinel.persisted: false
RPC ack sentinel.payload.stats.requiresRestart: false
RPC ack sentinel.payload.doctorHint: null
DB gateway_restart_sentinel current row: NONE (no row)
readRestartSentinel() (startup consumer input): null (no startup task)

=== Scenario 2: restart-requiring config.patch (gateway.port) ===
RPC ack sentinel.persisted: true
RPC ack sentinel.payload.stats.requiresRestart: true
RPC ack sentinel.payload.doctorHint: PRESENT
DB gateway_restart_sentinel current row: kind=config-patch status=ok
readRestartSentinel() (startup consumer input): HAS PAYLOAD (would create startup task)

This exercises the full flow: a real startGatewayServerCore Gateway receives config.patch over WebSocket, the producer gates persistence on requiresRestart, the gateway_restart_sentinel SQLite table reflects the gate, and readRestartSentinel() — the input to loadRestartSentinelStartupTask on the next Gateway start — returns null for hot-applied writes (no startup task, no stale notice) and a payload for restart-requiring writes (startup task preserved).

Adjacent sentinel suites pass with no regressions:

$ node scripts/run-vitest.mjs src/infra/restart-sentinel.test.ts src/gateway/server-methods/config.shared-auth.test.ts src/gateway/server-restart-sentinel.test.ts
# 39 + adjacent tests passed

The server.config-policy-response.test.ts suite (4 cases covering token/origin revocation policy-close ordering) was adapted: the pre-acknowledgement hold moved from the writeRestartSentinel spy to a replaceConfigFile spy. Hot-applied writes skip sentinel persistence (#144063), so the sentinel spy no longer fires for them — replaceConfigFile is awaited before the RPC acknowledgement in commitGatewayConfigWrite and runs for both write kinds, preserving the barrier that keeps peer.closed, writer.didClose(), and staleRead assertions deterministic before the writer's socket is retired. The requiresRestart assertion moved to the ack's sentinel.payload where it is always available. All 4 cases pass.

Production code is net +11 lines. The growth gates sentinel persistence on the existing requiresRestart classification and makes the doctor hint conditional. Tests are net +219 lines across three files (mocked unit tests, real-persistence integration test, policy-close ordering adaptation). Formatting (oxfmt --check) and git diff --check pass.

Preexisting unrelated CI failure

The checks-node-core-test-nondist-shard reported one failure in extensions/memory-core/src/memory/manager-temporal-ranking.test.ts:156 — the test asserts FTS available: false but the runtime reports available: true. This PR does not touch extensions/memory-core/ or any memory/FTS code path; the changed files are all under src/gateway/server-methods/ and src/gateway/server.config-policy-response.test.ts. This failure is preexisting on main and unrelated to this PR.

What was not tested

Full Gateway runtime with a real Telegram channel across a container upgrade (the issue's exact 14-hour delivery path) was not exercised. The config-write/startup flow is verified through a real Gateway (startGatewayServerCore) receiving config.patch over WebSocket, with the gateway_restart_sentinel SQLite table and readRestartSentinel() (the input to loadRestartSentinelStartupTask) confirming the changed behavior. The formatDoctorNonInteractiveHint global function is unchanged.

Why Telegram Test Server E2E was not provided

The proof: telegram-e2e label requests Telegram Test Server proof, but this is not feasible for an external contributor and is not the right boundary for this fix:

  1. Credential gate: AGENTS.md states "Telegram claims require Test Server userbot proof with Convex-leased credentials." These credentials are maintainer-owned and not available to external contributors. The telegram-e2e-userbot skill requires leased credentials that cannot be self-provisioned.

  2. Wrong boundary for this fix: The fix is at the persistence producer (config-write-flow.ts), not the Telegram delivery layer. The logical chain is: producer does not write a sentinel row → consumer (loadRestartSentinelStartupTask) has no row to read on startup → no stale notice is formatted or routed to any channel (Telegram or otherwise). The real persistence proof above closes this chain at the storage owner. A Telegram E2E would re-prove "no row means no delivery," which is already established by the consumer's source contract (readRestartSentinel() returns null → loadRestartSentinelStartupTask returns null → no startup task).

  3. Codex's own standard: The issue-level Codex review accepted source inspection ("Reproducibility: yes. by source inspection... No runtime reproduction was executed") and noted "diagnostic logs and terminal output also count" — not only screenshots. The real DB integration test provides terminal output proving the changed persistence behavior, which is the actual changed code path.

  4. Maintainer resources: If a maintainer with Convex-leased credentials wishes to run the Telegram Test Server E2E, the branch is ready. The scenario would be: config.patch agents.defaults.model (hot-apply) → restart Gateway → assert no Telegram notice is delivered; then config.patch gateway.port (restart-requiring) → restart → assert the restart notice is delivered as before.

AI Assistance 🤖

  • AI-assisted: Yes
  • AI model: Claude (GLM-5.2-FP8)
  • Human confirmed understanding of code changes: Yes

Risks and Mitigations

Highest-risk area: Restart sentinel persistence for config writes — a regression here could either re-introduce stale notices (if gate is removed) or suppress legitimate restart notices (if gate is too broad).

Mitigation: The gate is strictly restartRequirement.requiresRestart ? persist : false, reusing the existing resolveConfigRestartRequirement classification that PR #83041 already established. Restart-requiring writes still persist. Two regression tests assert both branches. Adjacent sentinel suites pass with no regressions.

Compatibility impact: No breaking change. Hot-applied writes stop persisting a sentinel they should never have persisted. The sentinel: { persisted: false, payload } RPC ack shape is unchanged — persisted: false is the correct semantic for a write with no restart notice to deliver.

Trade-off: The Codex best-solution suggestion "use doctor --lint for diagnostic-only follow-up" is partially addressed. Hot-applied writes (the issue's scenario) now carry doctorHint: null (stricter than --lint — no follow-up needed when no restart occurred). Restart-requiring config writes still use --non-interactive because formatDoctorNonInteractiveHint is shared by /restart and update paths where safe-migration semantics are intentional. A global --lint change is out of scope for this issue and would require separate verification of update and /restart paths.

@clawsweeper

clawsweeper Bot commented Sep 11, 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 gateway Gateway runtime size: S labels Sep 11, 2026
@wangyan2026
wangyan2026 force-pushed the fix/gateway-hot-apply-sentinel-144063 branch from 03f5041 to c7b0f92 Compare September 11, 2026 07:30
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 11, 2026
@clawsweeper

clawsweeper Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Persist restart sentinels and include Doctor hints only when a config write requires a Gateway restart.

Example: Change agents.defaults.model from old-model to new-model while the Gateway hot-applies config.

  • Before: A restart sentinel survives and can trigger an unrelated notice or agent wake on a later startup.
  • After: The acknowledgement reports sentinel.persisted=false and no new restart sentinel is stored.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful producer fix with real Gateway protocol evidence and green exact-head checks; duplicated mocked tests keep it below A.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied terminal trace exercises config.patch through a real Gateway WebSocket, observes absent SQLite sentinel state and a null startup-reader result for a hot model change, and confirms persistence for a restart-required port change; Telegram delivery itself is unchanged.
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 hot-applied setting change can cause an obsolete restart notice or idle-agent wake hours later.
Reason: The patch restores the documented distinction between hot application and Gateway restart without adding configuration or another owner.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current Gateway bug at its producer, preserves legitimate restart notices, and has sufficient Gateway protocol proof with green exact-head CI.

Priority: P2
Reviewed head: 90c549f7ea3cfcebb801fc6c6e30bc823ca4e402

Before merge

None.

Findings

None.

Tests

  • Low-value test src/gateway/server-methods/config-write-flow.test.ts: Remove the added mocked persistence cases and their dedicated scaffolding: the new real-storage suite exercises the same two inputs and payload outcomes, while these cases mainly repeat mock-call assertions.
Agent review details

How this fits together

Gateway config.patch and config.apply handlers classify committed changes, persist restart notices through the shared-state worker, and return an acknowledgement; startup consumes pending notices.

flowchart TD
A[Config RPC] --> B[Commit and apply config]
B --> C[Existing restart classification]
C --> D[Hot apply acknowledgement]
C --> E[Worker sentinel persistence]
E --> F[Startup notice consumer]
Loading

Technical review

Best possible solution:

Keep the existing config-write owner’s requiresRestart gate while preserving restart-required and update sentinel handling.

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

Current-main source shows hot writes creating a sentinel that startup later consumes; the linked issue supplies affected-release observations, but no target code was executed during this review.

Is this the best way to solve the issue?

The smallest complete fix is to prevent irrelevant notices at the existing producer using its established restart classification.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Restart classification and sentinel persistence changes intended behavior with a stated reason (96e27c6: Expose whether config writes require restart so pending and completed summaries describe their state accurately.)
  • Inline payload construction and persistence result handling keeps the original intent (3272581: Consolidate equivalent Gateway flows while retaining existing protocol and persistence contracts.)
  • Config writer policy-close tests keeps the original intent (f6f939a: Preserve acknowledgement of committed config writes while publication can revoke the requester.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 74db989 adds src/gateway/server-methods/config-write-flow.ts:146 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 74db989c268c; files: src/gateway/server-methods/config-write-flow.ts)
  • Vincent Koc: Raw commit f6f939a adds src/gateway/server.config-policy-response.test.ts:307 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f6f939a8ebc6; files: src/gateway/server.config-policy-response.test.ts)

PR surface

Source +2, Tests +230. Total +232 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 7 5 +2
Tests 4 243 13 +230
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 250 18 +232

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Delayed notices and unnecessary agent wakes affect an established operator workflow without establishing a core outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • 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 (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-11T08:14:42.928Z sha 28bebd574c55bbb1115f94c2c14582861443aea2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-11T08:27:52.595Z sha d266aa981312a025ce7734168b024b527a09f4d7 :: needs real behavior proof before merge. :: [P2] Preserve a pre-acknowledgement barrier in the policy-close test
  • reviewed 2026-09-11T08:38:59.445Z sha d266aa981312a025ce7734168b024b527a09f4d7 :: needs real behavior proof before merge. :: [P2] Preserve a pre-acknowledgement barrier in the policy-close test
  • reviewed 2026-09-11T08:55:38.926Z sha 7702b2362b4f3b3b902fae172b49ab9f9fc46b15 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-11T09:05:57.417Z sha 7702b2362b4f3b3b902fae172b49ab9f9fc46b15 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-11T09:40:58.545Z sha 7702b2362b4f3b3b902fae172b49ab9f9fc46b15 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T04:09:53.589Z sha 7702b2362b4f3b3b902fae172b49ab9f9fc46b15 :: blocked before merge. :: none
  • reviewed 2026-10-16T03:51:30.292Z sha 7702b2362b4f3b3b902fae172b49ab9f9fc46b15 :: needs changes before merge. :: none

Reviewed October 19, 2026, 9:40 PM ET / October 20, 2026, 01:40 UTC (Revision 11).

@wangyan2026
wangyan2026 force-pushed the fix/gateway-hot-apply-sentinel-144063 branch from c7b0f92 to 28bebd5 Compare September 11, 2026 07:54
@clawsweeper clawsweeper Bot removed the proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. label Sep 11, 2026
@wangyan2026
wangyan2026 force-pushed the fix/gateway-hot-apply-sentinel-144063 branch 2 times, most recently from d266aa9 to 7702b23 Compare September 11, 2026 08:48
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 11, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 14, 2026
@clawsweeper clawsweeper Bot added the proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. label Oct 5, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 9, 2026
@wangyan2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 16, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 16, 2026
@wangyan2026
wangyan2026 force-pushed the fix/gateway-hot-apply-sentinel-144063 branch 9 times, most recently from af90081 to 90c549f Compare October 19, 2026 12:47
@wangyan2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 20, 2026
@wangyan2026
wangyan2026 force-pushed the fix/gateway-hot-apply-sentinel-144063 branch 2 times, most recently from 87068c4 to 82f617e Compare October 26, 2026 12:53
@wangyan2026
wangyan2026 force-pushed the fix/gateway-hot-apply-sentinel-144063 branch from 82f617e to a4247ef Compare October 26, 2026 13:28

This branch has not been deployed

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

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L stale Marked as stale due to inactivity 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.

2 participants