Repository navigation
fix(agents): grok lookups by session, Agy locks read last, and 503 for a Letta scan cut short - #3598
Conversation
…for it A grok pane herdr reported with no agent_session for one snapshot lost its background count and its turn's hold for about ten seconds. sameSession() read the missing id as another session, so the pane was looked up at once as herdr reported it; a grok session is found by its id, so that lookup could only fail, and a failed lookup of "another session" lets the state go at once. The miss then held the next snapshots off for RETRY_MS, when herdr named the session again. herdr naming no session is not another session. A grok pane reported without one is now asked for by the session known for it: nothing is looked up while that lookup is recent, and once it is old the lookup is a real one of the known id against the pane's process. One that fails is a first miss as any (the count stands, the poll asks again ten seconds on, by that id), and two in a row let the pane go as before. A pane nothing is known of is asked for as herdr reports it. Follow-up to #3572 (merge-pass review, LOW). Co-Authored-By: Claude Fable 5.2 <[email protected]>
The memory of a failed lookup was kept per pane and agent. A grok session is found by the id herdr reports, so a miss of one id said nothing about another, yet it held the snapshot lookup of a newly reported session off for RETRY_MS: a pane herdr named no session for yet (grok just started), or whose earlier session was not found, waited up to ten seconds for the session herdr named next. The miss now carries the session id it was of (grok only: an agy session is found by the pane's process, whatever the pane says of a session, so its miss still holds for any id). Both gates read it through one helper: the retry spacing, and the "second miss in a row" that lets a pane go. For the second no case is reachable today, on main or here: a pane kept through a miss is always kept under the session that miss was of, and a failed lookup of another session lets it go at once. It is compared there too so that the two gates cannot come apart. Follow-up to #3572 (merge-pass review, LOW). Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ocks resolveAgyStore and agyFreshSession read the process's locks first and asked herdr the second time afterwards. Both were inside the start-identity bracket, but the locks, which are the answer, were not the last evidence gathered: an Agy that moved to another conversation (or took its first lock) while herdr answered was still answered with the conversation it had left, or greeted as one that had begun none. The order is now identity, second ask, locks, identity. A second answer that names another process ends the lookup before any lock is read. What that costs: the second ask is made before it is known what the locks show, so a lookup that finds no single conversation lock, and a greeting refused because a lock is held, ask herdr twice where they asked once. A lookup that answers still asks twice; a pane herdr names no single Agy for, an Agy whose start identity cannot be read and a greeting refused by its start arguments are still settled by the first ask. Tests: the ask counts are updated to that (agy-store.test.ts: the two cases above move from one ask to two, and the cases the first ask settles are pinned anew), a stand-in Agy moves its lock while herdr answers the second time, and on Linux the order of the reads is pinned as such. docs/agy-chat.md and the unreleased changelog fragment of #3573 describe the new order. Follow-up to #3573 (merge-pass review, LOW). Co-Authored-By: Claude Fable 5.2 <[email protected]>
…resolution After the awaited transcript scan, toolOutput refuses a pane already seen bound to another conversation and resolves any other pane once more. That last resolution was only compared by its own answer. One begun before a `/new` in the pane still names the conversation the output was read from; when another read saw the pane on the new conversation while it was under way, the old conversation's output was answered all the same. The final check now also refuses when the pane's binding moved since the lookup resolved it (rebound), which covers what other reads saw during that last resolution. The OmO branch of toolOutput has the same shape and is left as it is: the finding named the Letta branch. Follow-up to #3575 (merge-pass review, LOW). Co-Authored-By: Claude Fable 5.2 <[email protected]>
A Letta transcript scan for one call's whole output stops at its own time
limit (10 s, checked between two reads) and answered null there, as for a
call the transcript does not hold: GET /api/pane/conversation/tool-output
said 404 output_not_found for a call that may lie past where the scan
stopped.
lettaToolOutput now tells the two apart. Out of time with some of what the
transcript held as the scan began still unread, it throws LettaScanCut; out
of time only once all of that was read, or at the end of the file, it
answers null as before (so does a scan stopped at its 256 MiB cap, past
which a call is not offered). The file thread answers a cut scan as
{ cut: true }, since an error crosses a thread as its message alone, and
lettaToolOutputOffThread rejects with FileBusyError for it, which the
route already answers 503 file_busy with Retry-After, as for a busy pool.
The letta-output file task takes an optional budgetMs, as the documents
task does, so a test can run a scan with no time on a real file thread.
Tests: letta.test.ts pinned the old answer in one line (a scan past its
limit answers null); it now expects LettaScanCut there. The changelog
fragment also names the previous commit's fix.
Follow-up to #3575 (merge-pass review, LOW).
Co-Authored-By: Claude Fable 5.2 <[email protected]>
The memory of a failed lookup held one miss per pane, of the session it was of. A miss of another session replaced it, so the spacing of lookups that fail was lost when herdr reported the pane differently from one snapshot to the next: a grok pane whose session cannot be found, named in one snapshot, with no session in the next and named again in the third (or two ids in turn) was looked up on every snapshot, where main asks once in ten seconds. Each lookup of a named id is a pane.process_info call and process reads. The pane's misses are now kept by session, for the agent they were of: each session is asked for again only RETRY_MS after its own miss, whichever was missed last. All of them are dropped as before when a lookup finds a session there, when the pane runs another agent or when it leaves, so the map holds one entry per session herdr named for the pane meanwhile. The "second miss in a row" reads the same entry, and is unchanged: a pane kept through a miss is kept under the session that miss was of. Test: ten snapshots in ten seconds that name a session and none in turn, with a lookup that always fails, ask once for each (ten times before), then again ten seconds after each one's own miss; the same for two ids in turn. Review follow-up on this branch (skeptic, LOW). Co-Authored-By: Claude Fable 5.2 <[email protected]>
… for Two parts of the branch that asks for a session-less grok pane by the session known for it could change with no test failing: - `known?.agent === agent` read as `known !== undefined`: a pane known as agy's and reported as a grok with no session would be asked for with the id herdr had named for agy, a herdr call and process reads for an id that is no grok session, where the pane as reported costs nothing to refuse. - the pane a status asked for during a lookup kept as substituted, not as herdr reported it: when that lookup ends with the pane let go, the status's own lookup would ask by the session just let go. One test covers both: an agy pane that turns into a grok with no session is asked for as "grok, no session" and agy's count is let go; and a status naming no session that asks while the second failing lookup of the known session is under way is given a lookup as herdr reported the pane, once the pane is let go. Either change above now fails it. No code change. Review follow-up on this branch (skeptic, LOW). Co-Authored-By: Claude Fable 5.2 <[email protected]>
Asking herdr the second time before the locks are read left the closing comparison of the two start identities with no test, in resolveAgyStore and in agyFreshSession: answering whatever the second read said passed every case. Before the reorder the stand-in Agy was killed during herdr's second answer, after its locks had been read, so only that comparison could refuse. Now the kill comes before the lock read and the lookup ends there, with the locks unreadable. In the new order that comparison is the one thing that refuses a pid another process took between herdr's second answer and the lock read, which is the bracket the reorder was made for. The Linux order test now has the read of /proc/<pid>/stat that follows the locks tell another start time (field 22) and expects no store and no greeting, with every step of the lookup taken (ask, identity, ask, locks, identity), so the refusal is the comparison's. It fails with either comparison removed. Linux only, as the order test is: elsewhere the identity is read through ps or a Windows handle. The two "process is gone" cases say what they now show: its locks cannot be read. No code change. Review follow-up on this branch (skeptic, MEDIUM). Co-Authored-By: Claude Fable 5.2 <[email protected]>
… herdr once docs/agy-chat.md says an Agy whose birth identity cannot be read is settled by the first ask. For resolveAgyStore a test held that; for agyFreshSession none did: its `if (!before) return null` could move to after the second ask and the lock read with every case passing. The greeting test now asks about the stand-in after it was killed, with one answer from herdr: no greeting, and herdr asked once. It fails with the return moved. No code change. Review follow-up on this branch (skeptic, LOW). Co-Authored-By: Claude Fable 5.2 <[email protected]>
…solution The OmO branch of toolOutput had the window 02e64d6 closed for Letta. After its transcript settles it refuses a pane already seen bound to another session and resolves any other pane once more, and that last resolution was only compared by its own answer. One begun before OmO started another session in the pane still names the session the output was read from; when another read saw the pane on the new session while it was under way, the old session's output was answered all the same. The final check now also refuses when the pane's binding moved since the lookup resolved it (rebound), as the Letta branch does. 02e64d6 left this branch as it was because the merge pass's finding named Letta's; the review of this branch reproduced it here. The line is older code (#3359), not #3575's. Test: the second omoSessionForPane call of one toolOutput is held, another paneTranscript sees the pane on the other session, and the held call then answers the old path: "old session" before, no output now; with nothing seen in between the same resolution answers. Review follow-up on this branch (skeptic, LOW). Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ing of misses over The comment on `failed` said each session herdr names for a pane is asked for only every RETRY_MS. That holds while none of them is found. A lookup that finds a session drops every miss of the pane, the other sessions' too, and the miss of a session other than the one known lets go what the pane holds. So where herdr names in turn a grok session that is found and one that is not, every snapshot looks one up and the count is told and let go in turn: ten lookups in ten seconds, where main makes two (and leaves the count at 0). This came with 60d632d. It is left as a known limit, which the comment now states and a test pins: nothing shows herdr naming two ids in turn for one pane, and the observed case (an id, then none) is asked for by the session known. Spacing it would take keeping the other sessions' misses through a lookup that finds one and reading them for a pane whose session is known, which would also hold a snapshot's lookup of a session the pane really went back to; more than a shape nobody has seen deserves. No behaviour change. A correction to 8c44a29's message: it said a session-less grok pane asked for with the id herdr named for agy costs a herdr call and process reads. It costs neither: resolveGrokStore refuses a session whose agent is not grok before it asks herdr anything. What `known?.agent === agent` decides is that another agent's id is never what a grok pane is asked for by, nor the key its miss is remembered under. Review follow-up on this branch (skeptic, LOW). Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Merge passMerged head
Both reviewers CLEAR (Claude Opus 5.5, Codex Terra); follow-ups from the reviews of #3572, #3573 and #3575, each checked against its original scenario. Known: a process that leaves the foreground after herdr's second answer is not caught (main has the same window one step later); a grok pane whose process was replaced while herdr names no session keeps the old count up to about 40 s. The tool-output route answers 503 (retry) where a scan was cut; the client shows the same retry for 404 and 503. |
Follow-ups to the low-severity findings the merge pass left on #3572, #3573 and #3575, as one PR, plus what the review of this branch found on the way. Cut from
925872654; it merges cleanly intoorigin/mainatc94f52572.The five findings
1. A grok pane herdr names no session for keeps what it holds (#3572)
server/agent-tasks.ts. A grok pane reported with noagent_sessionfor one snapshot lost its background count, and the hold of a turn that ended on a task, for about ten seconds. The missing id was read as another session, so the pane was looked up as reported. A grok session is found by its id, so that lookup could only fail, and a failed lookup of "another session" lets the state go at once.herdr naming no session is not another session. A grok pane reported without one is now asked for by the session known for it:
2. A failed lookup is remembered with the session it was of (#3572)
server/agent-tasks.ts. The memory of a failed lookup was kept per pane and agent. For grok, a miss of one session id held off the snapshot lookup of a newly named other session for the retry interval, and could count as the first of its two misses.The pane's misses are now kept by session, for the agent they were of (grok only: an agy session is found by the pane's process, so its miss still holds whichever id herdr names). Both gates read the same entry: the retry spacing, and the "second miss in a row" that lets a pane go. Each session's miss stays beside the others', so herdr naming a session, then none or another, then the first again asks for each only every ten seconds while none of them is found.
Known limit, left as it is. A lookup that finds a session drops every miss of the pane. Where herdr names in turn a session that is found and one that is not, every snapshot looks one up and the count is told and let go in turn: ten lookups in ten seconds, where main makes two (and leaves the count at 0). Nothing shows herdr naming two ids in turn for one pane; the observed case (an id, then none) is covered by item 1. The comment on
failedstates the limit and a test pins it. Spacing it would mean keeping the other sessions' misses through a lookup that finds one and reading them for a pane whose session is known, which would also hold a snapshot's lookup of a session the pane really went back to.3. Agy: herdr is asked the second time before the locks are read (#3573)
server/agy-store.ts,resolveAgyStoreandagyFreshSession. The order was identity, locks, second ask, identity. It is now identity, second ask, locks, identity, so the lock read is the last evidence gathered and still lies inside the start-identity bracket. A second answer that names another process ends the lookup before any lock is read.What the new order costs. The second ask is made before it is known what the locks show:
docs/agy-chat.mddescribes the new order and these costs, and the unreleased fragment of #3573 (changelog.d/agy-pane-process-recheck.md) is reworded to it.4. Letta: no output when the pane moved during the last resolution (#3575)
server/conversation.ts, the Letta branch oftoolOutput. After the awaited scan the pane is resolved once more, and that resolution was only compared by its own answer. One begun before a/newin the pane still names the conversation the output was read from, so when another read saw the pane on the new conversation meanwhile, the old conversation's output was answered. The final check now also refuses when the binding moved since the lookup resolved it (|| rebound(paneId, transcript)).5. Letta: a scan cut by its time limit answers "try again" (#3575)
server/letta.ts,server/file-tasks.ts. A transcript scan stopped by its own 10 s limit answered as "no such call" (404output_not_found), though the call may lie past where it stopped.lettaToolOutputthrowsLettaScanCutwhen it runs out of time with some of what the transcript held as the scan began still unread. It answers null as before at the end of the file, when all of that was read, and at its 256 MiB cap.{ cut: true }(an error crosses a thread as its message alone), andlettaToolOutputOffThreadrejects withFileBusyErrorfor it.file_busywithRetry-Afterit already gives when no file thread is free. Only which cases get it changes.letta-outputfile task takes an optionalbudgetMs, as the documents task does, so a test can run a scan with no time on a real file thread.Beyond the five findings
OmO has the window item 4 closes for Letta. The OmO branch of
toolOutputresolved the pane a last time and compared only that answer (older code, #3359). The review of this branch reproduced it: the held last resolution answered the old session's output after another read had seen the pane on a new session. The same|| rebound(paneId, transcript)is added there, with a test and a changelog fragment of its own. Please treat it as an addition to the five; it is one commit (7fcbbe6a2) and can be dropped on its own.Tests
server/agent-tasks.test.ts: a session-less grok pane keeps its count and is asked for by the session known; a pane known as another agent's, or let go meanwhile, is asked for as reported; a miss holds no lookup of another session off; each session's miss is kept beside the others'; the known limit above.server/agy-store.test.ts: the ask counts of the table above; a stand-in Agy that moves its lock while herdr answers the second time; on Linux the order of the reads (ask, identity, ask, locks, identity), and that the start identity read after the locks is what refuses a pid taken between the second answer and the lock read; a greeting with an unreadable start identity asks once. The order test is Linux only: elsewhere the identity is read throughpsor a Windows handle.server/letta.test.ts: the pane moved during the last resolution; a scan with no time answers{ cut: true }on the file thread andFileBusyErroron the pane's route, for a call the transcript holds and for one it does not; read to the end, the answers are the output and "not found".server/conversation.test.ts: the OmO pane moved during the last resolution ("old session" before the fix, no output now).Changelog
changelog.d/grok-unnamed-session-keeps-count.md,letta-tool-output-try-again.mdandomo-tool-output-pane-moved.mdare new;agy-pane-process-recheck.md(#3573, unreleased) is reworded to the new order.Validation
Run at head
aa59268f9, withHERDR_TEST_MODE=unitand aTMPDIRof its own:bun test server/agent-tasks.test.ts: 23 passbun test server/agy-store.test.ts: 24 passbun test server/conversation.test.ts: 253 passbun test server/letta.test.ts: 81 passbun test server/file-pool.test.ts: 21 passbun test server/core/status.test.ts: 82 passbun test server/conventions.test.ts: 14 passbun test scripts/changelog-fold.test.ts: 12 passbun run typecheck: cleanbun run check fastataa59268f9: green (unit 14797 pass, 0 fail; typecheck, build, generated files).Reviewed before opening by an independent agent reviewer in three rounds (one medium and several low findings, all fixed or listed above; the last round: ship).
Not run:
bun run check fulland the browser regressions (nosrc/change). Nothing was run on macOS or Windows; the Agy path on macOS is untested natively, asdocs/agy-chat.mdalready says.server/agy-store.tsis imported byserver/windows-native.test.ts, so this waits for GitHub's Native Windows job.Notes for the merge pass
GET /api/pane/conversation/tool-outputanswer 503 instead of 404, so this PR touches an HTTP answer and waits for a real review.8c44a2908gives a wrong reason for theknown?.agent === agentclause (a saved herdr call).resolveGrokStorerefuses a session that is not grok's before it asks herdr anything; the clause only keeps another agent's id out of what a grok pane is asked for by and remembered under.aa59268f9's message corrects it; a squash message should not carry the old line.🤖 Generated with Claude Code