Skip to content

feat(plugin): add session.stopping hook for loop continuation - #44712

Open
orenbaldinger wants to merge 1 commit into
anomalyco:devfrom
orenbaldinger:feat/session-stopping-hook
Open

orenbaldinger wants to merge 1 commit into
anomalyco:devfrom
orenbaldinger:feat/session-stopping-hook

Conversation

@orenbaldinger

@orenbaldinger orenbaldinger commented Aug 24, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #16626

Type of change

  • New feature

What does this PR do?

Adds an awaited session.stopping plugin hook in the Hooks interface to allow external plugins to evaluate session state and optionally inject a continuation message before the prompt loop breaks.

Key semantics:

  • Awaited Lifecycle: Dispatched in SessionPrompt.run immediately prior to natural loop exit.
  • Fail-Closed Default: Output defaults to stop: true. If a plugin listener throws or rejects, execution stops cleanly (stop: true, message: undefined).
  • Sticky Veto: Multiple listeners run in registration order. If any listener sets stop: true, subsequent listeners cannot force continuation.
  • Defense-in-Depth Cap: Core enforces SESSION_STOPPING_REENTRY_CAP = 3 to prevent runaway infinite loops from misconfigured plugins.
  • Cleanup: In-memory continuation state is pruned on session.deleted.

How did you verify your code works?

  • bun test packages/opencode/test/plugin/session-stopping.test.ts (listener ordering, error isolation, fail-closed behavior)
  • bun test --timeout 30000 packages/opencode/test/plugin/session-stopping-exit-matrix.test.ts (compaction stops, provider/tool error non-natural exits, nested sessions, concurrent loop callers)
  • bun turbo typecheck across all workspace packages

Screenshots / recordings

N/A — backend lifecycle hook change without UI modifications.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 24, 2026
@orenbaldinger orenbaldinger changed the title feat(opencode): add awaited session.stopping plugin hook for loop continuation feat(plugin): add session.stopping hook for loop continuation Aug 24, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: add session.stopping plugin hook to allow re-entering the agent loop

2 participants