Skip to content

feat(plugins): run_stopped hook for confirmed user stops - #190906

Merged
obviyus merged 2 commits into
mainfrom
seam/run-stopped-hook
Nov 2, 2026
Merged

obviyus merged 2 commits into
mainfrom
seam/run-stopped-hook

Conversation

@obviyus

@obviyus obviyus commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

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.

@clawsweeper

clawsweeper Bot commented Nov 2, 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 docs Improvements or additions to documentation gateway Gateway runtime size: L labels Nov 2, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Core cancels Workshop review directly, but plugins receive no explicit Stop notification.
  • After: Plugins receive source client, session agent:main:a, and run ID run-1 before cancellation commits.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused implementation with the previous finding fixed and green gates; behavioral evidence remains an in-process Gateway harness.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored PR is outside the ordinary contributor proof gate; supplied validation exercises a loaded plugin through in-process Gateway Stop RPCs and timeout rejection, without a separate shipped-runtime capture.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Plugins managing detached post-turn work cannot distinguish an explicit user Stop soon enough to suppress work triggered by the stopped run's completion.
Reason: The maintainer-authored direction supplies a concrete missing contract for Workshop extraction and other detached consumers without adding configuration or another cancellation owner.

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
Reviewed head: fd18991866f9bbb0654b0ad886c87865c434c8b4

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No separate shipped Gateway capture demonstrates the new hook outside the in-process test setup.
Agent review details

How this fits together

Channel 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]
Loading

Technical review

Best 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

  • Explicit Stop and Workshop cancellation keeps the original intent (2919a0d: Cancel queued and active review work and suppress the stopped foreground run's completion only after accepted Stop authorization.)
  • Hook context eligibility keeps the original intent (7f004de: Share eligibility between presence and dispatch while retaining contextual filtering and dispatch ordering.)
  • Canonical hook contracts and registration keeps the original intent (4d1bb7c: Derive hook names and facade signatures from canonical contracts instead of maintaining parallel inventories.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +81, Tests +315, Docs +31, Other 0. Total +427 across 17 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 12 192 111 +81
Tests 3 315 0 +315
Docs 1 31 0 +31
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 17 539 112 +427

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a focused plugin capability enabling detached-work cancellation integrations, with existing user Stop behavior preserved.
  • merge-risk: 🚨 compatibility: The additive run_stopped hook creates a public plugin lifecycle contract; its direction and ordering are explicitly recorded by the collaborator author, with existing hook contracts retained.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 (1 earlier review cycle)
  • reviewed 2026-11-02T06:20:54.723Z sha 8a7fa57 :: needs changes before merge. :: [P2] Remove the assertions copied into the new eligibility helper

Reviewed November 2, 2026, 3:02 AM ET / 08:02 UTC (Revision 2).

@obviyus

obviyus commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 2, 2026
@obviyus
obviyus merged commit 71e516a into main Nov 2, 2026
138 checks passed
@obviyus
obviyus deleted the seam/run-stopped-hook branch November 2, 2026 08:40
@obviyus

obviyus commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 71e516a. Plugins can now use api.on("run_stopped") for confirmed user stops; the three core stop sites call one owner. Proof: real-Gateway e2e (chat.abort by run and by session, /stop each fire once; timeouts don't), Workshop contract suites unchanged.

vincentkoc added a commit that referenced this pull request Nov 2, 2026
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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.

1 participant