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

Merged
CO
19d ago
+359-1

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 4fa6c6fe9d: 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.