Repository navigation
feat(threads): thread_read is bounded and reads on; agent messages are capped per sender - #1222
Merged
Merged
Conversation
…e capped per sender - thread_read cuts a message at 4,096 characters with textOffset to read on, and holds a response to 64 KB in both views, saying where to continue. - thread_wait's resultText and run.result events are cut to 4,000 characters with a pointer to thread_read; the delegation notice is unchanged. - thread_send returns delivery: started | queued. - A thread holds 3 waiting agent messages per sending thread and 10 in all. - The same text from the same thread within 2 minutes is refused (duplicate_message); a retry with the same clientRequestId still replays. - Each limit refusal has its own conflict code and wording. Refs #1160 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bvsr365
force-pushed
the
thread-read-bounds-and-send-limits
branch
from
November 15, 2026 15:38
f2d4fe6 to
840af70
Compare
12 tasks done
bvsr365
added a commit
that referenced
this pull request
Nov 15, 2026
…nd repeat check every agent has #1222's caps (three waiting per sender, ten in all) and its repeat check (duplicate_message) count a sender on another computer by its computer and thread (origin.from), so one computer and two follow one rule and one set of codes. The owner path's own repeat check is gone; its rate limit and daily budget stay. Refs #1160 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 15, 2026
This was referenced Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An agent reading another thread could get a response of about 800 KB, and a message longer than 4,096 characters was cut with no way to read the rest. A thread held 3 waiting agent messages in all, so one chatty sender could shut every other sender out. Nothing stopped a sender from sending the same text twice, and every limit refusal looked about the same to the agent.
Change
thread_read, messages view: each message still holds at most 4,096 characters. A message that is cut is markedtruncatedwithtotalCharsandnextTextOffset. The newtextOffsetparameter continues the message atafterIndexfrom that point. A cut never splits a character.[Message from an agent in thread …]header, the agent's words, and the closing[End of message from an agent]line.origin.bodymarks where the words sit.thread_readreturns that stored text, sotext,totalChars,nextTextOffsetandtextOffsetall count characters of the whole stored message. The first part of a long agent message starts with the header, and the last part ends with the closing line. The stored text never changes after it is written, so reading on gives consistent pieces.thread_read, both views: a response holds at most 64 KB of UTF-8 JSON. A page that reaches the cap holds fewer whole items, sayscapped: true, and itsnextAfterIndexornextAfterSeqcontinues after the last item it holds. An event too big for a response of its own comes with a preview of its payload. The existing limits stay: events 200 by default and 500 at most, messages 50 by default and 200 at most.thread_wait'sresultTextandrun.resultevents inthread_readare cut to 4,000 characters, with a marker, the full length and a pointer tothread_read. The cut happens in the tool only, so a subagent's result still reaches its parent whole through the delegation notice.thread_sendresult: a newdelivery: "started" | "queued"field sits besidequeued.thread_sendadmission and to what an agent queues or takes over withqueue_enqueueandqueue_edit. The refusals areagent_queue_full_per_senderandagent_queue_full. A person's messages never count.AGENT_REPEAT_WINDOW_MS) is refused withduplicate_messageandretryAfterMs. It is decided last in the engine's admission, under the thread's lock, so two identical sends at once cannot both pass. A retry with the sameclientRequestIdnever reaches admission: the engine replays its receipt and returns the first result. The record lives in memory, like the per-run send count, so a restart forgets it.sends_per_run_exceededcount still skips a bot's calls. The queue caps count waiting messages in one target thread. A bot's messages were already held to the old cap of 3 agent messages in all. Now they count like any sender's: at most 3 from the bot's thread waiting in one thread, and 10 from all agents. For a bot that is looser than before. A bot that starts or messages many threads is not limited by this. The 25-start, 21-message chat turn inbotThreadsDaemon.test.tsstill passes. The repeat check applies to a bot too: the same text to the same thread within 2 minutes is refused with the reason, and the bot can tell its owner.data.conflictand wording that says what to do:agent_hops_exceeded,agent_queue_full_per_sender,agent_queue_full,duplicate_message,sends_per_run_exceeded. The sends-per-run limit used to be a plain error and is now a conflict like the others.instructions.tsanddocs/run-engine/SPEC.md§15.1 describe the new parameters, results and caps.How to review
src/mms/run/mcp/appTools/thread.ts: the constants at the top, thenfitPage,boundedEventandcutResultText, then thethread_read,thread_sendandthread_waithandlers, andSEND_CONFLICTS.src/mms/orchestrator/OrchestratorService.ts:agentQueueRefusal, its two call sites (send admission andqueueCommand), and the repeat check (claimAgentMessage, the newonAdmitsend option). This is the riskiest part.Verification
Tier 5 (run engine). Tested commit: 840af70, rebased on master at ea1b126 (which includes #1197, #1170, #1219, #1223, #1224 and #1220).
npx tsc --noEmit -p tsconfig.node.json: clean.npx vitest runwith these 16 files: 403 tests passed. The files:tests/run/threadActionsTools.test.ts,threadActionsDaemon.test.ts,queueTools.test.ts,queueEditDaemon.test.ts,mcpToolRegistry.test.ts,agentThreadReach.test.ts,threadCreateTools.test.ts,threadCreateDaemon.test.ts,botThreadTools.test.ts,botThreadsDaemon.test.ts,delegationGuidance.test.ts,mousseMcpServer.test.ts,appToolListing.test.ts,subagentHold.test.ts,subagentHoldIntegration.test.ts, andtests/bots/botThreads.test.ts.textOffset, including a character outside the BMP on the cut:mcpToolRegistry"a message marked truncated is read on with textOffset".mcpToolRegistry, one test per view. They use two-byte characters, check every response's byte length, and read every item exactly once by following the continuation. The events test includes an event larger than the cap.textOffset:mcpToolRegistry"an agent's long message reads on over its stored text". The pieces put back together equal the stored text, and the agent's own words sit betweenorigin.body.headandtail.threadActionsTools"cuts a long result" (it also checks that the parent'schild_resultrow keeps the whole text) andmcpToolRegistry"cuts a run's final text in the events".threadActionsDaemon. The second sender still gets in after the first is refused.queueEditDaemon. A person's message still gets in.clientRequestIdreturns the first result, and another thread may send the same words:threadActionsDaemon. With the admission hook removed, this test fails.threadActionsTools.queueEditDaemonandthreadActionsDaemonnow expect the cap per sender. The sends-per-run tests now expect a conflict. The hop-limit chain test now sends different words on each hop, because the same words would now be refused as a repeat before the hop limit is reached.check-on-real-data, the messages view, copies of 151 threads with 13,961 messages): old and new code were run on the same threads. Every message was rebuilt exactly by followingtextOffset: 0 mismatches. Before, 100 messages were cut with no way to read on; reading them in full took 147 extra calls. At the largest page size (limit 200), one page was 97 KB before; now the largest is 63.6 KB, 2 pages stopped at the cap and continued, and none went over. At the default limit (50), no page reached the cap; the largest was 42.9 KB.Notes
thread-settle-notice), which also edits thethread_senddescription and result. The edits here are one addeddeliveryfield and one changed sentence in the description, so the two PRs should rebase cleanly.instructions.tschanged in thethread_sendandthread_readlines.queue_enqueueinto another thread is held to the queue caps but not to the repeat check.Refs #1160
🤖 Generated with Claude Code