Repository navigation
refactor(channels): own the lifecycle status contract in SDK patch factories - #118795
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed August 3, 2026, 3:17 PM ET / 19:17 UTC. ClawSweeper reviewWhat this changesThis PR adds shared plugin-SDK factories for ready, blocked, and stopped channel status patches, migrates bundled channels to them, and lifecycle-owns selected plugin registries and pending-upload timers. Merge readiness⛔ Blocked until real behavior proof is added - 7 items remain This PR’s stated terminal-recovery repair is still blocked by the Gateway’s current lifecycle lock: a ready patch clears Priority: P2 Review scores
Verification
How this fits togetherBundled channel plugins send status patches to the Gateway runtime store, which merges them into account state and derives health and restart decisions. The PR also moves selected process-local registries and timers under lifecycle cleanup so restart and shutdown do not retain stale plugin state. flowchart LR
Channels[Bundled channel plugins] --> Factories[SDK lifecycle patch factories]
Factories --> Runtime[Gateway runtime status store]
Runtime --> Lock[Terminal lifecycle guard]
Lock --> Health[Health and restart decisions]
Registries[Plugin registries and timers] --> Cleanup[Lifecycle cleanup]
Cleanup --> Restart[Gateway restart or shutdown]
Decision needed
Why: Current main intentionally reserves lifecycle reset authority for the Gateway start transition, while this PR’s central claim requires a channel-level ready patch to reverse that state. The code can implement either rule, but choosing the durable authority boundary is maintainer intent. Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +2, Tests +279, Generated 0, Other +2. Total +283 across 64 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Mantis proof suggestionAfter the Gateway recovery rule is fixed, a Telegram live transcript can prove that a terminal state followed by successful polling becomes genuinely ready in the observable status surface. A maintainer can ask Mantis to capture proof by posting this exact PR comment: Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Define one canonical recovery rule at the Gateway status-store boundary: either an authenticated ready patch may explicitly clear a terminal block, with a gateway-level regression test, or terminal recovery must always run through the Gateway-owned Do we have a high-confidence way to reproduce the issue? Yes, from source: begin with a runtime row whose lifecycle is Is this the best way to solve the issue? No: the shared factory is a good consolidation point, but it cannot deliver the claimed terminal recovery while the Gateway merge owner deliberately rejects non- Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cd42cb770332. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
75557a9 to
892db51
Compare
892db51 to
be1e200
Compare
|
Merged via squash.
|
…outing-20260803 * origin/main: (34 commits) fix(config): reject unsupported diagnostics otel grpc (#93087) fix(providers): recognize configured media credentials across provider boundaries (#118761) refactor: delete dead post-landing plugin/hooks scaffolding (#118920) fix(cron): deliver child results after heartbeat-only parent responses (#118743) fix(ci): keep Matrix chunk tests aligned with inventory (#118917) fix(tts): preserve hidden speech answers when synthesis fails (#118690) test(gateway): add HTTP API QA coverage (#118809) test(qa): cover Control UI sessions and cron (#118838) fix(macos): preserve native command ownership and consent (#118914) test(qa): cover OpenClaw exec process lifecycle (#118819) test(ui): cover diagnostic operator flows (#118837) fix(search): propagate cancellation through provider-owned requests (#118895) test(gateway): cover loopback and LAN access (#118824) refactor(channels): own the lifecycle status contract in SDK patch factories (#118795) test(ui): add guarded config QA coverage (#118814) fix(feishu): fence external collaboration tool results (#118877) test(qa): cover Plugin SDK import topology (#118878) test(qa): register external app SDK proof (#118829) fix(gateway): expire temporal rows in cached session lists (#118875) test(matrix): isolate runtime state (#118892) ...
…te-dry-run-no-state-mutation * commit '682f60ce56b37c5cd3205fdcbbf25b21d48708f2': (28 commits) fix(config): reject unsupported diagnostics otel grpc (#93087) fix(providers): recognize configured media credentials across provider boundaries (#118761) refactor: delete dead post-landing plugin/hooks scaffolding (#118920) fix(cron): deliver child results after heartbeat-only parent responses (#118743) fix(ci): keep Matrix chunk tests aligned with inventory (#118917) fix(tts): preserve hidden speech answers when synthesis fails (#118690) test(gateway): add HTTP API QA coverage (#118809) test(qa): cover Control UI sessions and cron (#118838) fix(macos): preserve native command ownership and consent (#118914) test(qa): cover OpenClaw exec process lifecycle (#118819) test(ui): cover diagnostic operator flows (#118837) fix(search): propagate cancellation through provider-owned requests (#118895) test(gateway): cover loopback and LAN access (#118824) refactor(channels): own the lifecycle status contract in SDK patch factories (#118795) test(ui): add guarded config QA coverage (#118814) fix(feishu): fence external collaboration tool results (#118877) test(qa): cover Plugin SDK import topology (#118878) test(qa): register external app SDK proof (#118829) fix(gateway): expire temporal rows in cached session lists (#118875) test(matrix): isolate runtime state (#118892) ...
…ctories (openclaw#118795) * refactor(sdk): add channel lifecycle patch factories * refactor(channels): adopt lifecycle patches in a-m * refactor(channels): adopt lifecycle patches in n-z * refactor(runtime): lifecycle-own ambient registries * test(slack): assert lifecycle factory fields * fix(sdk): preserve lifecycle patch extras types * test(zalouser): widen lifecycle status sink * test(irc): avoid shadowed status patch * fix(zalo): reuse account-agnostic media route * fix(gateway): accept explicit channel ready recovery * test(qa): assert terminal Slack block fact * test(qa): restore Slack blocked lifecycle scenario * test(gateway): lock explicit lifecycle recovery contract
What Problem This Solves
The two lifecycle adoption waves (#118110, #118298) left 26 extensions publishing near-identical
setStatusblocks — 71 blocks, ~390 lines, all restating the same contract by hand. Hand-rolled repetition already produced six latent bugs:readypublishes that fail to clearterminalDisconnect, so a channel recovering from a terminal failure (repaired token, restored session) keeps reportingterminal-disconnecton its next stop becausesetRuntimepatch-merges and an omitted key clears nothing.Why This Change Was Made
Three factories in
src/gateway/channel-status-patches.ts(exported via the existingplugin-sdk/gateway-runtimebarrel) now own the contract:channelReadyPatch(extras?)— running/connected,ready, timestamp, cleared error, and the load-bearing explicitterminalDisconnect: undefinedchannelBlockedPatch(lastError, extras?)—blocked, terminal, error required by signaturechannelStoppedPatch(extras?)— not running/connected,stoppedExtras are type-constrained from overriding factory-owned lifecycle fields, so a channel cannot silently reintroduce the bug class. 26 extensions migrated (~40 sites);
starting/recoveringsites intentionally stay local (legitimate per-channel variance). Latent fixes: Buzz, IRC, Nextcloud Talk, Raft, Reef, Zalo User previously publishedreadywithout the terminal clear (plus two consistency fixes in QQBot).Also included, on the ambient-state factory from #118271: stateful target drivers move to the plugin-registry-owned global map (with ACP registration made repeatable after drains), Discord's components-registry scalars join its lifecycle-owned singleton, and MS Teams' pending-upload reset now cancels every TTL timer before clearing — timers no longer leak across gateway lifecycles.
User Impact
Channels that recover from terminal auth failures now report health correctly on subsequent stops instead of a stuck
terminal-disconnect. MS Teams no longer leaks upload-expiry timers across restarts. No configuration or visible behavior changes otherwise.Evidence
Maintainer decisions recorded: the sticky terminal guard may be cleared by a channel-authored patch only when it explicitly owns both
lifecycle: "ready"andterminalDisconnect: undefined; weaker/derived signals and task finalization never clear it, while the Gateway-ownedstartingpath remains unchanged. The three lifecycle factories are accepted as an additive public SDK status contract for external plugins.Exact-head Gateway behavior proof
Head
4ca033b9288183b8e529e62b2f1fc2f3eb961447was built withOPENCLAW_BUILD_PRIVATE_QA=1 pnpm build;dist/build-info.jsonmatched the Git head. The reused harness is QA Lab's dist child gateway plus its established generated external-plugin load-path pattern. The child owned an ephemeralOPENCLAW_STATE_DIR, bound an isolated loopback port, used mock credentials only, and never touched the operator Gateway or state. A separate source-blind validation rerun passed all five behavior-contract clauses and anti-cheat probes.{ "verdict": "PASS", "headSha": "4ca033b9288183b8e529e62b2f1fc2f3eb961447", "harness": "QA Lab dist child gateway + generated external channel fixture", "statusSurface": "channels.status", "isolation": { "stateDir": "ephemeral", "gatewayHost": "127.0.0.1", "gatewayPort": "49321", "operatorGatewayTouched": false, "credentials": "mock-only", "distBuilt": true }, "scenario": { "transition": ["blocked", "ready"], "channelAuthoredRecovery": "channelReadyPatch", "gatewayPidUnchanged": true, "startCount": 1, "readyCount": 1, "terminalDisconnectCleared": true, "restartPending": false } }Redacted
channels.statusexcerpts:{ "terminalBlocked": { "accountId": "default", "running": true, "connected": false, "lifecycle": "blocked", "healthState": "blocked", "terminalDisconnect": true, "restartPending": false, "lastError": null }, "explicitReady": { "accountId": "default", "running": true, "connected": true, "lifecycle": "ready", "restartPending": false, "lastConnectedAt": 1785785039812, "lastError": null } }The generic external-plugin status projection does not expose
lastStartAt; no-restart is therefore proven by unchanged Gateway PID, exactly one recorded channel task start, andrestartPending: falserather than by claiming an absent timestamp comparison.Ambient restart-drain transcript
The same exact-head build exercised the built MS Teams FileConsentCard path, retained its real five-minute pending-upload timer, then called the built global singleton restart drain in a fresh process with ephemeral state.
{ "scenario": "msteams-pending-upload-restart-drain", "headSha": "4ca033b9288183b8e529e62b2f1fc2f3eb961447", "isolation": { "stateDir": "ephemeral", "operatorStateTouched": false }, "before": { "cardContentType": "application/vnd.microsoft.teams.card.file.consent", "uploadPresent": true, "pendingUploadCount": 1, "pendingTimerCount": 1, "activeTimeoutDelta": 1, "timerDestroyed": false }, "after": { "uploadPresent": false, "pendingUploadCount": 0, "pendingTimerCount": 0, "activeTimeoutDelta": 0, "timerDestroyed": true }, "verdict": "PASS" }🤖 Generated with Claude Code