Skip to content

feat(rpc): a thread call carries its chain count and meets the user's threads.chainCountLimit (S32, #5899) - #5923

Merged
code-yeongyu merged 6 commits into
mainfrom
feat/s32b-chain-count-admission
Nov 6, 2026
Merged

code-yeongyu merged 6 commits into
mainfrom
feat/s32b-chain-count-admission

Conversation

@code-yeongyu

@code-yeongyu code-yeongyu commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Fixes #5641
Fixes #5899

Stacked on #5882 (base feat/s32-session-plane). Merge #5882 first, then this one. It wires the user-set thread chain count limit (decision K8) where chains are created, which is the part of S32's acceptance that #5882 left unread.

What changes

  • RPC input. prompt, steer and follow_up accept chainCount, a positive integer: the hop count of a thread call from another session. It is 1 for the first call of a chain and one more per hop, and a chain may come back to a session it already visited (A→B→A).
  • Admission. handleClientInput admits such an input with admitChainCall() against the user's threads.chainCountLimit, read from the settings on every call, before admission records anything.
    • Unset (the default) admits any length. There is no default cap, no warning and no cost limit.
    • Past the limit, the input is refused with the typed reason errorCode: "chain_count_limit" and errorData: { count, limit }, and nothing of it runs.
  • Propagation. An admitted count reaches the session's input extension event as chainCount, so a thread call that session sends next can carry one more. Input that is not a thread call has no count.
  • Docs. docs/rpc.md (thread chains), docs/extensions.md (event.chainCount), and the docs/settings.md row now says where the limit is read.
  • Method-class review. chainCount is added to the reviewed field lists of the three commands. Their class (drive) is unchanged, because the field can only get an input refused.

Tests

  • packages/coding-agent/test/suite/regressions/5899-thread-chain-count-limit.test.ts uses the real settings file through the RPC connection handler:
    • With no limit set, a 12-hop call is admitted.
    • Call N is admitted under limit N.
    • Call N+1 is refused with chain_count_limit and { count: 3, limit: 2 } for prompt, steer and follow_up, and no input event fires.
    • An input that is not a thread call carries no count.
  • Mutations, each killed:
    • Skipping the admission fails the 3 refusal cases.
    • Not forwarding the count to the input event fails the 2 admission cases.
  • Gated push at 4fa6c6f: bun run check, knip, changelog gate against the stack base, 79 tests passed across the new test and the RPC input suites (5776-*, client-message ledger, external admission, method-class table, session-plane).

Summary by cubic

Makes thread calls from other sessions carry their hop count and enforces the user's threads.chainCountLimit where chains are created (the RPC input admission), the part of S32 acceptance #5882 left unread. prompt, steer, and follow_up now accept chainCount (1 for the first call, one more per hop, a chain may revisit a session). admitInputChain() checks the count against the setting read on every call before anything of the input is recorded or held: unset admits any length with no default cap, and past the limit the input is refused with the typed reason chain_count_limit and errorData: { count, limit } without any of it running. A chainCount that is not a positive safe integer is refused first with errorCode: "invalid_chain_count" and errorData: { chainCount }, since the RPC boundary only shape-checks a command and a malformed count would never compare above the limit. The check runs before a run hold can keep an over-limit call as a notice, and a terminal's session-control endpoint refuses chainCount with unsupported_field because its text-only admission cannot carry a hop count. An admitted count reaches the session's input event as chainCount, so a thread call that session sends next carries one more; input that is not a thread call has no count. Includes a regression suite that exercises the real settings file through every entry — a plain RPC connection, a held run, and the terminal endpoint — plus updates to docs/rpc.md, docs/extensions.md, docs/settings.md, the method-class reviewed-field lists, and the changelog fragment.

Written for commit 6ca0e99. Summary will update on new commits.

View guided diff Turn on auto-fix

… threads.chainCountLimit (S32, #5899)

RPC prompt, steer and follow_up accept chainCount, the hop count of a thread call from
another session. It is admitted with admitChainCall() against the user's
threads.chainCountLimit before admission records anything: unset means unlimited (no
default cap, no cost limit); past the limit the input is refused with errorCode
chain_count_limit and errorData { count, limit }. An admitted count reaches the input
extension event as chainCount so the next thread call can carry one more.

Fixes #5641
Fixes #5899
…ng or admitting it (#5923 review)

The chain count check moves into admitInputChain() (modes/rpc/chain-admission.ts) and runs
first in connection-handler for prompt, steer and follow_up, so a run hold can no longer keep
an over-limit thread call as a notice. A terminal's session-control endpoint cannot carry the
hop count through its text-only admission and now refuses chainCount with unsupported_field
instead of admitting it with no limit. The regression test runs every refusal through each
entry; a mutant per entry fails only that entry's rows.
…e chain limit (#5935)

The RPC boundary only shape-checks a command, so a chainCount of null, 0, -3, 1.5, "abc" or
past the safe-integer range reached admitInputChain unvalidated, never compared above the
user's limit, and was admitted onto the input event. admitInputChain now refuses anything
but a positive safe integer with errorCode invalid_chain_count and errorData { chainCount }
before the limit is read, at every entry (plain RPC, RPC under a hold; the terminal endpoint
already refuses chainCount). RED rows per bad value through each entry; a mutant that drops
the check fails all 13.

Fixes #5935
main extracted admitPrompt/admitInput/UNSERVED_INPUT_FIELDS into
session-control-input-commands.ts. Keep main's file untouched (#5906's
session_moved_away work, no admission widening for senpi#6074) and carry
#5923's one change - chainCount in UNSERVED_INPUT_FIELDS - into the new home.
… the re-head

The re-head moved UNSERVED_INPUT_FIELDS into session-control-input-commands.ts,
so the fragment's tracker block now names that file instead of the old one.
@code-yeongyu
code-yeongyu merged commit f4dc3ac into main Nov 6, 2026
11 checks passed
@code-yeongyu
code-yeongyu deleted the feat/s32b-chain-count-admission branch November 6, 2026 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant