Repository navigation
🤖 feat: per-hook Stop continuation limits with a ceiling of 50 per user turn - #7835
Conversation
…er turn Each turn.stop continuation reason now names its plugin and hook (hookKey = <plugin instance id>:<hook key>), so every Stop hook counts its own continuations in a user turn: the shared default of 3 (moved to src/constants/pluginHooks.ts), a number from loopLimit, or no per-hook limit for loopLimit: null. MAX_PLUGIN_CONTINUATIONS_PER_USER_TURN (50) caps all continuations of one user turn. Codex Stop hooks set no loopLimit, so they keep 3 per user turn. - TurnStopContext carries turnContinuations and hookContinuations before the chain runs, so a consumer can pass its own count to its hook (Cursor loop_count). stopHookActive is derived from turnContinuations. - runTurnStopHooks drops the reasons of hooks at their limit and returns the kept hookKeys and plugin names. AgentSession adds 1 per kept key and resets both counts wherever the single counter reset before. - Each plugin continuation emits the notice "plugin continued turn n of 50". A continuation of Xum's own nudges alone emits none. RFC: rfc/20261030_cursor-plugin-support.md, PR 7 (D2, D3, D4). --- _Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh` • Cost: `$4.51`_ <!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh costs=4.51 -->
Signed-off-by: Thomas Kosiewski <tk@coder.com>
Comment Sicko flagged recordStopHookContinuation: it also emits the "plugin continued turn n of 50" notice, which its name hid. Rename it to countAndAnnounceStopHookContinuation. --- _Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh` • Cost: `$4.51`_ <!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh costs=4.51 -->
The "plugin continued turn n of 50" notice went through the chat error queue: a red toast that stays until dismissed, one queued per continuation. A loop with loop_limit: null (PR 8) could queue 50. - plugin.hook.notice and the plugin-hook-notice chat event take an optional severity "info". AgentSession sends it for the continuation notice. A hook's systemMessage keeps no severity and still shows as a warning. - chatErrorToasts gains publishChatInfo: the notice shows through the chat input's existing "info" toast intent (non-error style, role=status), and a newer info notice replaces one still waiting, so a loop leaves one notice. Tests for verifier gaps F3 (the hook service keys Stop counts by the plugin folder's instance id, not its name) and F4 (the notice names only plugins whose reasons were kept). --- _Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh` • Cost: `$10.30`_ <!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh costs=10.30 -->
Codex RFC finding 4: when the joined reasons pass TURN_STOP_PROMPT_MAX_CHARS, the cut can drop a later hook's whole reason, yet that hook was still counted toward its limit and named in the notice. - runTurnStopHooks returns the kept reasons. joinTurnStopReasons joins them, cuts the prompt, and returns the keys and plugin names only of reasons with some text left after the cut, each once. - mergeTurnStopContinuation makes the one cut, with the room that Xum's nudges leave, so a reason that a nudge pushes out does not count either. Tests: a second reason cut wholly does not count and is not named, one cut mid-way does; the same for a nudge cut; joinTurnStopReasons at the cut boundaries. --- _Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh` • Cost: `$18.74`_ <!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh costs=18.74 -->
The delta verifier found that removing the Math.max(0, ...) guard broke no test. A cut to -1 characters (nudges longer than the cap) must still leave no reason text; without the guard, slice(0, -1) keeps all but the last character. --- _Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh` • Cost: `$20.26`_ <!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=xhigh costs=20.26 -->
…nto cursor-plugins/stop-limits
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🟢 e2e stories (Haiku): 14 passed22 agent steps · 7 replayed from cache · 15 model calls · 46.3k tokens (24% cached) All 14 tests in 9 files
e2e 0.20.0 · 1m 12s · web · run artifacts 🟢 e2e Electron stories (Haiku): 3 passed3 agent steps · 3 model calls · 8.0k tokens (22% cached) All 3 tests in 3 files
e2e 0.20.0 · 19.8s · electron · run artifacts 🟢 e2e agent repros (Haiku): no tests selectedSpend: $0.00 of the $1.00 cap (proxy ledger) e2e 0.20.0 · 5.3s · 2 targets (web, phone) · run artifacts |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Summary
Each plugin Stop hook now has its own continuation limit per user turn: the shared default of 3, a number from
loopLimit, or no per-hook limit forloopLimit: null. A ceiling of 50 continuations per user turn caps all hooks together. Codex Stop hooks set noloopLimit, so each keeps 3 continuations per user turn. Every plugin continuation shows an informational notice, "plugin continued turn n of 50".Background
ThomasK33 asked for the Cursor plugin RFC as a reviewed, mergeable PR stack. This is PR 7 of that RFC:
rfc/20261030_cursor-plugin-support.md, "PR 7: Per-hook stop limits", section 6 (Stop-loop limits), decisions D2, D3 and D4.Before this PR, one counter (
MAX_STOP_HOOK_CONTINUATIONS = 3) covered every Stop-hook continuation of a user turn. Cursor plugins such as ralph-loop need a per-hookloop_limit(or none) and their ownloop_count. PR 8 adds Cursor hooks on top of this code path; no Cursor hook runs yet.Implementation
TurnStopContext.continueReasonsholds{text, pluginName, hookKey, loopLimit?}.hookKeyis<plugin instance id>:<AgentPluginHookSchema.key>: a hook key names a location inside one plugin, so two plugins with the same key keep separate counts.codexHookServicepasses the plugin folder's instance id.TurnStopContextcarriesturnContinuationsandhookContinuations, so a consumer can pass its own count to its hook (Cursorloop_count, PR 8).stopHookActiveis derived fromturnContinuations.runTurnStopHooksdrops the reasons of hooks at their limit.joinTurnStopReasonsbuilds the prompt with the existingTURN_STOP_PROMPT_MAX_CHARScut and returns a hook's key only when some of its reason text is in the final prompt;mergeTurnStopContinuationmakes that one cut with the room Xum's nudges leave.resetStopHookCounts), checks the ceiling of 50, and emits the notice.plugin.hook.noticeand theplugin-hook-noticechat event take an optionalseverity: "info". The chat input shows it through its existing non-error toast, and a newer info notice replaces one still waiting (publishChatInfo), so a loop does not stack one toast per continuation. A hook'ssystemMessagekeeps no severity and shows as before.docs/hooks/plugins.mdxstates the per-hook limit, the ceiling and the notice.Validation
AgentSessiontests with the real event spine and the real Codex hook runner (agentSession.turnStopHooks.test.ts): default 3,loopLimit2,nullstops at 50, two hooks count separately and see their own counts before they run, a new user message resets both, a user Stop adds no continuation, two Codex plugins with the same hook key count separately, a reason cut wholly by the prompt cap or by the nudge does not count, the notice text and its plugin names.null, numeric limit, default, rollback copies, notice severity, info replacement, the cut rules) makes the targeted tests fail for every mutant.role=statusnon-error toast ("turn 1"), then "turn 3" (turn 2 never showed); a hooksystemMessagestill shows the redrole=alerttoast; the toast fits a 390 px phone width.Risks
Release note
Stop-hook continuations are counted per hook, with a ceiling of 50 per user turn (D2, D3, D4). Hooks without
loop_limit, all Codex hooks included, keep 3 continuations per user turn each.Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:xhigh• Cost:$20.92