Repository navigation
feat(plugins): run_stopped hook for confirmed user stops - #190906
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR adds a typed run_stopped plugin hook at existing explicit Stop boundaries while preserving Workshop cancellation. Example: A client stops run run-1 in session agent:main:a using chat.abort.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this maintainer-authored PR open: it supplies a useful missing plugin hook, resolves the earlier assertion finding, and has green exact-head gates with no new actionable defect found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherChannel commands and Gateway Stop requests pass through existing authorization and cancellation owners; a shared notification owner forwards their selected sessions and runs to Workshop and registered plugin observers. flowchart TD
A[Channel Stop] --> C[Authorized Stop boundaries]
B[Gateway client Stop] --> C
C --> D[Run stopped notification]
D --> E[Workshop cancellation]
D --> F[Plugin hook handlers]
C --> G[Run cancellation]
Technical reviewBest possible solution: Retain the narrow hook and shared notification owner so plugins can observe explicit Stop without duplicating cancellation policy. Do we have a high-confidence way to reproduce the issue? This is a capability addition rather than a reported malfunction; source inspection confirms current main has only the Workshop-specific bridge. Is this the best way to solve the issue? The change uses the existing hook registry and authorized Stop boundaries, centralizes notification, and justifies the small type and predicate extractions through existing file limits. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5ae5ea8d8e16. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +81, Tests +315, Docs +31, Other 0. Total +427 across 17 files. Added test files: 2. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 2, 2026, 3:02 AM ET / 08:02 UTC (Revision 2). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 71e516a. Plugins can now use |
Keep the three module-local hook aliases and the session involvement transaction helper private. They were exposed without production consumers by #190906 and #184511, causing the owning dead-code checks to fail. Derive the Gateway observer fixture's event and context from the existing run_stopped handler signature. Public hook shapes, the local transaction caller, authority checks and credential-writer recognition remain unchanged. The original export gate reproduces all four findings. The repaired dependency and export gates, core and consumer types, typed lint, formatting and the staged test-line ratchet pass.
…0906) ## What Problem This Solves Plugins that run detached work after a turn (Skill Workshop's background review, advisor) cannot learn that a user explicitly stopped a session's run. Core called Workshop's stop directly from three stop sites, which blocks moving Skill Workshop into its bundled plugin. ## User Impact No user-visible change: `/stop`, Control UI Stop and `chat.abort` still cancel a pending Workshop review exactly as before. Plugins gain `api.on("run_stopped", ...)`. ## Why This Change Was Made - New typed hook `run_stopped` (event: `source` channel|client, stopped `sessions`, `runIds`; context agentId/sessionKey when exactly one session). - One owner, `notifySessionRunStopped()` (`src/sessions/session-run-stopped.ts`), dedupes and fires the hook fire-and-forget with error isolation; the three confirmed-stop sites (`abort-operation.ts`, `chat-abort-exact-run.ts`, `chat-abort-session-plan.ts`) call only this owner. Workshop-named flags at those sites are renamed generically. - Fires only for explicit channel/client stops; timeouts, failures, watchdog, restart, supersede and Talk barge-in do not fire it. - Core Workshop's stop is still called from the owner until Workshop moves into the plugin; then it becomes `api.on("run_stopped")`. - Handlers run synchronously after the stop is authorized and before cancellation commits (documented), so a consumer can suppress work before the stopped run's own `agent_end`. - No new SDK exports (export budget unchanged), no schema or protocol change. Two existing pieces moved to sibling files to keep `hook-types.ts`/`hooks.ts` under the line cap. ## Evidence - New e2e `src/gateway/server-methods/chat.abort-run-stopped-hook.e2e.test.ts`: real in-process Gateway, test plugin loaded through `plugins.load.paths` + `register(api)`; `chat.abort` by run id, `chat.abort` by session and `chat.send "/stop"` each fire exactly once with the right payload; a timed-out run fires nothing. - Channel `/stop` path covered in `abort.test.ts`. - Workshop behavior pin, assertions unchanged: 6 unit contract suites 65/65; 3 e2e contract suites 17/17. - Abort/stop/talk suites 424/424; plugin hook suites, boundary invariants, advisor and agent-end side effects 212/212. - `tsgo:core`, `tsgo:core:test`, type-aware oxlint, `plugin-sdk:check-exports`, `plugin-sdk:surface:check`, `check:line-cap-ratchet` pass; `plugin-sdk:api:diff` is additive only. Co-authored-by: Ayaan Zaidi <[email protected]>
Keep the three module-local hook aliases and the session involvement transaction helper private. They were exposed without production consumers by openclaw#190906 and openclaw#184511, causing the owning dead-code checks to fail. Derive the Gateway observer fixture's event and context from the existing run_stopped handler signature. Public hook shapes, the local transaction caller, authority checks and credential-writer recognition remain unchanged. The original export gate reproduces all four findings. The repaired dependency and export gates, core and consumer types, typed lint, formatting and the staged test-line ratchet pass.
What Problem This Solves
Plugins that run detached work after a turn (Skill Workshop's background review, advisor) cannot learn that a user explicitly stopped a session's run. Core called Workshop's stop directly from three stop sites, which blocks moving Skill Workshop into its bundled plugin.
User Impact
No user-visible change:
/stop, Control UI Stop andchat.abortstill cancel a pending Workshop review exactly as before. Plugins gainapi.on("run_stopped", ...).Why This Change Was Made
run_stopped(event:sourcechannel|client, stoppedsessions,runIds; context agentId/sessionKey when exactly one session).notifySessionRunStopped()(src/sessions/session-run-stopped.ts), dedupes and fires the hook fire-and-forget with error isolation; the three confirmed-stop sites (abort-operation.ts,chat-abort-exact-run.ts,chat-abort-session-plan.ts) call only this owner. Workshop-named flags at those sites are renamed generically.api.on("run_stopped").agent_end.hook-types.ts/hooks.tsunder the line cap.Evidence
src/gateway/server-methods/chat.abort-run-stopped-hook.e2e.test.ts: real in-process Gateway, test plugin loaded throughplugins.load.paths+register(api);chat.abortby run id,chat.abortby session andchat.send "/stop"each fire exactly once with the right payload; a timed-out run fires nothing./stoppath covered inabort.test.ts.tsgo:core,tsgo:core:test, type-aware oxlint,plugin-sdk:check-exports,plugin-sdk:surface:check,check:line-cap-ratchetpass;plugin-sdk:api:diffis additive only.