Skip to content

fix(agents): grok lookups by session, Agy locks read last, and 503 for a Letta scan cut short - #3598

Merged
devswha merged 11 commits into
mainfrom
fix/agent-store-review-followups
Nov 10, 2026
Merged

devswha merged 11 commits into
mainfrom
fix/agent-store-review-followups

Conversation

@devswha

@devswha devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner

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 into origin/main at c94f52572.

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 no agent_session for 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:

  • Nothing is looked up while that lookup is recent.
  • Once it is old, the lookup is a real one of the known id. 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.
  • A pane nothing is known of is asked for as herdr reports it.
  • The session known is used only when it is grok's own: another agent's id is never what a grok pane is asked for by, nor the key its miss is remembered under.

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 failed states 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, resolveAgyStore and agyFreshSession. 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:

Case Asks before Asks now
A lookup that answers 2 2
A lookup that finds no single conversation lock 1 2
A greeting refused because a lock is held 1 2
A pane herdr names no single Agy for 1 1
An Agy whose start identity cannot be read 1 1
A greeting refused by its start arguments 1 1

docs/agy-chat.md describes 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 of toolOutput. After the awaited scan the pane is resolved once more, and that 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, 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" (404 output_not_found), though the call may lie past where it stopped.

  • lettaToolOutput throws LettaScanCut when 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.
  • The file thread answers a cut scan as { cut: true } (an error crosses a thread as its message alone), and lettaToolOutputOffThread rejects with FileBusyError for it.
  • The route gains no new answer: it is the 503 file_busy with Retry-After it already gives when no file thread is free. Only which cases get it changes.
  • 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.

Beyond the five findings

OmO has the window item 4 closes for Letta. The OmO branch of toolOutput resolved 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 through ps or 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 and FileBusyError on 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.md and omo-tool-output-pane-moved.md are new; agy-pane-process-recheck.md (#3573, unreleased) is reworded to the new order.

Validation

Run at head aa59268f9, with HERDR_TEST_MODE=unit and a TMPDIR of its own:

  • bun test server/agent-tasks.test.ts: 23 pass
  • bun test server/agy-store.test.ts: 24 pass
  • bun test server/conversation.test.ts: 253 pass
  • bun test server/letta.test.ts: 81 pass
  • bun test server/file-pool.test.ts: 21 pass
  • bun test server/core/status.test.ts: 82 pass
  • bun test server/conventions.test.ts: 14 pass
  • bun test scripts/changelog-fold.test.ts: 12 pass
  • bun run typecheck: clean

bun run check fast at aa59268f9: 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 full and the browser regressions (no src/ change). Nothing was run on macOS or Windows; the Agy path on macOS is untested natively, as docs/agy-chat.md already says. server/agy-store.ts is imported by server/windows-native.test.ts, so this waits for GitHub's Native Windows job.

Notes for the merge pass

  • Item 5 changes which cases of GET /api/pane/conversation/tool-output answer 503 instead of 404, so this PR touches an HTTP answer and waits for a real review.
  • The message of 8c44a2908 gives a wrong reason for the known?.agent === agent clause (a saved herdr call). resolveGrokStore refuses 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

devswha and others added 11 commits November 10, 2026 22:02
…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]>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved Grok background-task tracking when session information is temporarily unavailable, and retry behavior when looking up sessions.
    • Tool-output requests now distinguish scans interrupted by a time limit from completed searches with no match, allowing interrupted requests to be retried.
    • Prevented stale tool output from being returned when a pane’s conversation changes during a lookup.
    • Improved pane and process validation when resolving conversation stores, reducing the chance of using outdated process or lock information.

The changes update Agy process checks around lock reads, Grok session lookup and retry tracking, and Letta and OmO tool-output handling. Tests and documentation cover the updated behaviors.

Changes: Agy process validation

Layer / File(s) Summary
Validate process identity around lock inspection
server/agy-store.ts, server/agy-store.test.ts, docs/agy-chat.md, changelog.d/agy-pane-process-recheck.md
Store resolution and fresh-session checks validate the pane’s process before reading held locks and verify process identity around the lookup. Tests cover process changes, lock changes, and query ordering. Documentation and the changelog describe the updated checks.

Grok session lookup tracking

Layer / File(s) Summary
Track Grok session lookups and misses
server/agent-tasks.ts, server/agent-tasks.test.ts, changelog.d/grok-unnamed-session-keeps-count.md
Lookup selection and retry spacing now track misses by agent and session. Tests cover temporary missing sessions, session changes, and repeated lookup misses.

Tool-output handling

Layer / File(s) Summary
Distinguish incomplete Letta scans
server/letta.ts, server/file-tasks.ts, server/letta.test.ts, changelog.d/letta-tool-output-try-again.md
A scan that stops with unread transcript content returns a cut-scan result rather than a completed no-match result. File tasks accept an optional time budget and map cut scans to a retry response.
Reject output after pane rebinding
server/conversation.ts, server/conversation.test.ts, server/letta.test.ts, changelog.d/omo-tool-output-pane-moved.md, changelog.d/letta-tool-output-try-again.md
Letta and OmO output validation rejects results when the pane is rebound during the final lookup. Regression tests cover the changed binding and unchanged binding cases.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: jimbb

Merge Risk: Minimal · up to aa592

This change tightens process-identity checks for Agy, keeps Grok background counts through brief session gaps, and returns a retryable 503 for cut Letta scans. It also rejects OmO and Letta tool output when the pane was rebound. No concrete merge-blocking risk was found. macOS and native Windows were not tested.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly names the main Grok, Agy, and Letta changes. It is long, but remains specific and readable.
Description check Passed The description explains the changes, links the related issues, and lists validation results and skipped checks. It also describes tests for the HTTP response behavior, though it does not explicitly i…
Docstring Coverage Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the changes, links the related issues, and lists validation results and skipped checks. It also describes tests for the HTTP response behavior, though it does not explicitly identify contract-test coverage.

Full details: Docstring Coverage

Explanation

Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 8 functions across 9 files. (5 skipped: 5 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c94f525 and aa59268.

Files selected for processing: 14

  • changelog.d/agy-pane-process-recheck.md
  • changelog.d/grok-unnamed-session-keeps-count.md
  • changelog.d/letta-tool-output-try-again.md
  • changelog.d/omo-tool-output-pane-moved.md
  • docs/agy-chat.md
  • server/agent-tasks.test.ts
  • server/agent-tasks.ts
  • server/agy-store.test.ts
  • server/agy-store.ts
  • server/conversation.test.ts
  • server/conversation.ts
  • server/file-tasks.ts
  • server/letta.test.ts
  • server/letta.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@devswha
devswha merged commit 03155da into main Nov 10, 2026
21 checks passed
@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head aa59268f998d as 03155dac6696 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

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.

@devswha
devswha deleted the fix/agent-store-review-followups branch November 10, 2026 18:39
hallelshohat added a commit to hallelshohat/ovis that referenced this pull request Nov 15, 2026