Skip to content

🤖 feat: per-hook Stop continuation limits with a ceiling of 50 per user turn - #7835

Merged
ThomasK33 merged 8 commits into
cursor-plugins/turn-stop-textfrom
cursor-plugins/stop-limits
Oct 31, 2026
Merged

ThomasK33 merged 8 commits into
cursor-plugins/turn-stop-textfrom
cursor-plugins/stop-limits

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

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 for loopLimit: null. A ceiling of 50 continuations per user turn caps all hooks together. Codex Stop hooks set no loopLimit, 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-hook loop_limit (or none) and their own loop_count. PR 8 adds Cursor hooks on top of this code path; no Cursor hook runs yet.

Implementation

  • Reasons name their hook. TurnStopContext.continueReasons holds {text, pluginName, hookKey, loopLimit?}. hookKey is <plugin instance id>:<AgentPluginHookSchema.key>: a hook key names a location inside one plugin, so two plugins with the same key keep separate counts. codexHookService passes the plugin folder's instance id.
  • Counts are visible before the chain runs. TurnStopContext carries turnContinuations and hookContinuations, so a consumer can pass its own count to its hook (Cursor loop_count, PR 8). stopHookActive is derived from turnContinuations.
  • Limits apply after the chain. runTurnStopHooks drops the reasons of hooks at their limit. joinTurnStopReasons builds the prompt with the existing TURN_STOP_PROMPT_MAX_CHARS cut and returns a hook's key only when some of its reason text is in the final prompt; mergeTurnStopContinuation makes that one cut with the room Xum's nudges leave.
  • AgentSession keeps the turn counter and a per-hook map, resets both wherever the single counter reset before (resetStopHookCounts), checks the ceiling of 50, and emits the notice.
  • The notice is informational. plugin.hook.notice and the plugin-hook-notice chat event take an optional severity: "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's systemMessage keeps no severity and shows as before.
  • Docs: docs/hooks/plugins.mdx states the per-hook limit, the ceiling and the notice.

Validation

  • Real AgentSession tests with the real event spine and the real Codex hook runner (agentSession.turnStopHooks.test.ts): default 3, loopLimit 2, null stops 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.
  • A mutation script (22 mutants, one behavior each: key namespacing, count exposure, resets, ceiling, null, numeric limit, default, rollback copies, notice severity, info replacement, the cut rules) makes the targeted tests fail for every mutant.
  • UI check in Storybook with agent-browser: three continuation notices sent at once showed one role=status non-error toast ("turn 1"), then "turn 3" (turn 2 never showed); a hook systemMessage still shows the red role=alert toast; the toast fits a 390 px phone width.
  • An independent verifier read the diff against the RFC and returned clean at each Phase A head.

Risks

  • Low to medium, limited to plugin Stop hooks and the chat toast for plugin notices. Users without plugin Stop hooks see no change: Xum's own TODO and status nudges keep their rule and show no notice.
  • The counts live in memory and reset on each new user turn and on restart, as before.

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.

  • Codex Stop-hook users now see an informational notice for each continuation: "Plugin : plugin continued turn n of 50". It is a non-error toast, and a newer notice replaces one that has not shown yet, so a loop does not stack one toast per continuation.
  • Each Stop hook now counts separately. After a TODO nudge continues the turn, a Stop hook still gets its own 3 continuations (4 continuations in total, where Xum stopped at 3 before).
  • Two Codex Stop hooks that continue on different stops can continue one user turn up to 6 times, where Xum stopped at 3 before.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh • Cost: $20.92

…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 -->
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T12:07:59.199882Z 6f1cfc8 Manual request
🔒 Security Review ✅ Completed 2026-10-31T12:08:17.714638Z 6f1cfc8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ThomasK33
ThomasK33 added this pull request to stack #7836 October 31, 2026 11:58
@github-actions

Copy link
Copy Markdown
Contributor

🟢 e2e stories (Haiku): 14 passed

22 agent steps · 7 replayed from cache · 15 model calls · 46.3k tokens (24% cached)
Spend: $0.09 of the $1.00 cap (proxy ledger)

All 14 tests in 9 files
Test Agent Time
🟢 chatRestart.e2e.ts · 1 passed 1 step · 1 call 5.3s
🟢 a chat survives a restart of the server 1 step · 1 call 5.3s
🟢 compaction.e2e.ts · 1 passed 1 step · 1 call 4.5s
🟢 /compact replaces the old chat with a summary 1 step · 1 call 4.5s
🟢 pluginTrustRestart.e2e.ts · 1 passed 4 steps · 2 calls 10.1s
🟢 a trusted plugin hook stays trusted after the server restarts 4 steps · 2 calls 10.1s
🟢 settingsRoundTrip.e2e.ts · 1 passed 2 steps · 1 call 8.6s
🟢 a chat survives trips through Settings 2 steps · 1 call 8.6s
🟢 sidebarPerWorkspace.e2e.ts · 1 passed 4 steps · 1 call 4.4s
🟢 a new workspace starts with its right sidebar collapsed while another keeps it open 4 steps · 1 call 4.4s
🟢 smoke.e2e.ts · 1 passed 2 steps · 1 call 2.4s
🟢 the agent opens the playground workspace 2 steps · 1 call 2.4s
🟢 streamErrors.e2e.ts · 1 passed 1 step · 1 call 7.2s
🟢 stream errors show in the chat, and the chat recovers 1 step · 1 call 7.2s
🟢 todoNudge.e2e.ts · 1 passed 1 step · 1 call 4.0s
🟢 the agent finishes open TODO items after the turn-end nudge 1 step · 1 call 4.0s
🟢 touchAlignment.e2e.ts · 6 passed 6 steps · 6 calls 22.2s
🟢 the Settings close button is level with the title on a touch screen 390px wide 1 step · 1 call 3.7s
🟢 the Settings close button is level with the title on a touch screen 768px wide 1 step · 1 call 4.2s
🟢 Backup settings checkboxes are small and level with their labels on a touch phone 1 step · 1 call 4.4s
🟢 the heartbeat checkbox is small and level with its label on a touch phone 1 step · 1 call 3.7s
🟢 a reply's model and time stay on one line on a touch phone 1 step · 1 call 3.4s
🟢 the workspace actions menu stays on the title row on a touch phone 1 step · 1 call 2.7s

e2e 0.20.0 · 1m 12s · web · run artifacts

🟢 e2e Electron stories (Haiku): 3 passed

3 agent steps · 3 model calls · 8.0k tokens (22% cached)
Spend: $0.02 of the $1.00 cap (proxy ledger)

All 3 tests in 3 files
Test Agent Time
🟢 electron/deepLink.e2e.ts · 1 passed 1 step · 1 call 5.0s
🟢 a deep link of a second launch starts a chat in the running app 1 step · 1 call 5.0s
🟢 electron/menuBar.e2e.ts · 1 passed 1 step · 1 call 5.6s
🟢 the workspace menu bar is the desktop title bar 1 step · 1 call 5.6s
🟢 electron/smoke.e2e.ts · 1 passed 1 step · 1 call 7.2s
🟢 Xum Electron opens the playground workspace 1 step · 1 call 7.2s

e2e 0.20.0 · 19.8s · electron · run artifacts

🟢 e2e agent repros (Haiku): no tests selected

Spend: $0.00 of the $1.00 cap (proxy ledger)

e2e 0.20.0 · 5.3s · 2 targets (web, phone) · run artifacts

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

Head: 6f1cfc8

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 6f1cfc839e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 6f1cfc839e

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 31, 2026
Merged via the queue into main with commit 456d5c0 Oct 31, 2026
34 of 35 checks passed
@ThomasK33
ThomasK33 deleted the cursor-plugins/stop-limits branch October 31, 2026 23:09
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.

1 participant