Repository navigation
fix(gateway): shutdown reports unresolved SecretRef warnings when channel credentials use exec/file refs - #112717
Conversation
Shutdown cleared the secrets runtime snapshot in the close prelude, which also drops the pinned runtime config. The channels close step then lazily re-pins the raw config, so stopChannel's resolveAccount hit unresolved SecretRefs and every shutdown of a gateway with an exec/file SecretRef credential logged an unresolved-SecretRef WARN and completed with warnings. The failed resolveAccount also skipped the per-account stop bookkeeping (graceful wait, task/abort cleanup, stopped-runtime state) and the plugin stopAccount hook. Move the scrub into the close handler's finally block so it still always runs, but only after every step that can read credentials. Fixes openclaw#112681
|
Codex review: needs maintainer review before merge. Reviewed July 28, 2026, 3:27 AM ET / 07:27 UTC. ClawSweeper reviewWhat this changesThe PR moves gateway SecretRef snapshot cleanup until after channel and plugin teardown and adds regression tests for teardown ordering and failure cleanup. Merge readinessKeep this PR open for normal maintainer review. The patch preserves resolved SecretRefs through channel and plugin teardown, then scrubs them in a Priority: P2 Review scores
Verification
How this fits togetherGateway shutdown runs a prelude followed by channel, plugin, and service teardown. Channel stop handlers can still resolve account credentials, so a resolved runtime configuration snapshot must survive until those steps have completed and then be scrubbed. flowchart LR
A[Gateway shutdown request] --> B[Close prelude]
B --> C[Channel teardown]
C --> D[Plugin and service teardown]
D --> E[Resolve account credentials]
E --> F[Clear secret snapshot]
F --> G[Shutdown result]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +6, Tests +39. Total +45 across 3 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep credential-resolution state alive through every gateway teardown owner, scrub it exactly once in final cleanup, and merge only after the branch is refreshed against current Do we have a high-confidence way to reproduce the issue? Yes in source and contributor evidence: an exec or file SecretRef remains resolvable during startup but is needed again by channel teardown after the old prelude cleared its runtime snapshot. The supplied isolated-state SIGTERM run reports the failure before the patch and a clean shutdown after it. Is this the best way to solve the issue? Yes. Moving the existing scrub to final cleanup is narrower than making each channel cache credentials or suppressing shutdown warnings, and it preserves cleanup even when teardown reports a failure. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d2d6108d2c17. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
Adapt SecretRef shutdown cleanup to the current gateway lifecycle split.
|
@clawsweeper re-review Current head |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Maintainer merge note: the branch was refreshed through |
|
Merged via squash.
|
…nnel credentials use exec/file refs (openclaw#112717) * fix(gateway): clear secrets runtime snapshot only after channel teardown Shutdown cleared the secrets runtime snapshot in the close prelude, which also drops the pinned runtime config. The channels close step then lazily re-pins the raw config, so stopChannel's resolveAccount hit unresolved SecretRefs and every shutdown of a gateway with an exec/file SecretRef credential logged an unresolved-SecretRef WARN and completed with warnings. The failed resolveAccount also skipped the per-account stop bookkeeping (graceful wait, task/abort cleanup, stopped-runtime state) and the plugin stopAccount hook. Move the scrub into the close handler's finally block so it still always runs, but only after every step that can read credentials. Fixes openclaw#112681 * chore: drop release-owned changelog entry --------- Co-authored-by: FullerStackDev <[email protected]>
Closes #112681
What Problem This Solves
Fixes an issue where every gateway shutdown logs an unresolved SecretRef warning and finishes with
completed in Nms with warnings: channel/<id>when a channel credential (for examplechannels.telegram.botToken) is configured as an exec or file SecretRef. The same ref resolves fine at startup and at runtime, so nothing actually failed, but any alerting that greps gateway logs for WARN around restarts fires on every single restart.Why This Change Was Made
The close prelude cleared the secrets runtime snapshot before the channel stop steps ran, and that clear also drops the pinned runtime config. When the channels step later called
getRuntimeConfig(), it lazily re-pinned the raw config file, sostopChannel->plugin.config.resolveAccount(cfg, id)saw the raw SecretRef and the strict read threwUnresolvedSecretInputError. That throw is what shows up as the shutdown warning, and it also skips the rest of the per-account stop path: the graceful stop wait, the task/abort bookkeeping, the stopped-runtime state write, and the plugin'sstopAccounthook (Telegram uses it to release its polling lease, keyed by the token it can no longer read).The scrub is moved into the close handler's
finallyblock: it still always runs, including when a close step fails, but only after every step that can read credentials.runGatewayClosePreludeloses the parameter since it has exactly one caller and nothing else needs the early clear.User Impact
Operators who moved channel credentials out of plaintext into SecretRefs (the hardening path from https://docs.openclaw.ai/gateway/secrets) get a clean
shutdown completed cleanly in Nmsagain, restart alerting stops false-positiving, and channel stop hooks run with the resolved credential during shutdown instead of being skipped.Evidence
Reproduced from source on Linux with an isolated
OPENCLAW_STATE_DIR,channels.telegram.botTokenset to an exec SecretRef, and the channel connected and polling (getMe/getUpdates answered by a local stub so the run needs no real bot token). Then SIGTERM.Before (main,
32d4323049):After (this branch, same setup):
The early clear was pinned down by instrumenting
clearRuntimeConfigSnapshotwith a stack trace during a reproduction run:Validation:
node scripts/run-vitest.mjs src/gateway/server-close.test.ts- 47 passed on final merge head75a3dbf9d5861f6d7f2c8a3bdcb186c3168dfd7e, including the ordering and failure-cleanup regressions.node --import tsx scripts/native-app-i18n.ts verifypassed after current-main integration.