Skip to content

fix(move): read the agent again, last of all, right before typing its exit - #4111

Merged
devswha merged 1 commit into
mainfrom
fix/move-exit-last-read
Nov 18, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/move-exit-last-read

Conversation

@devswha

@devswha devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner

What

Before the move to herdr-core ends an agent, it types the agent's exit command into its pane. It
read the agent's status and conversation, then its input box, then typed. An agent that took work
or switched conversation during the input-box read, or while the exit waited for the pane's input
lane, was still typed into. The comment the restore pass put back in server/runtime-move-run.ts
named this gap (#4094).

  • herdrSource.sendExit now reads, inside the pane's input lane, the input box and then the agent
    (kind, status, conversation), and refuses unless the pane still shows the same idle agent on the
    conversation the plan showed. The pending queue is asked once more in herdr's pre-write guard: a
    held message can be re-keyed to the pane outside the lane.
  • A refusal is a returned value, not a thrown error. runMove stops with a reason the page already
    translates (agent_busy, input_left, plan_changed) where it used to show a raw
    failed: a message waits for the pane.
  • An agent that was certainly not typed into is no longer kept in the journal as ended, so a
    rollback neither lists it as left behind nor restarts it. Certain means: a check refused, the
    guard refused before a byte went out, herdr answered agent_blocked, agent_not_found or
    agent_not_ready, or herdr was never reached (connect_failed, still shown as what failed).
    Any other error may follow the keys: it still throws and the entry stays.

Not changed, on purpose

  • Work or a draft that starts between those reads and herdr's Enter (300 ms after its paste) from
    outside the lane is still typed into: the terminal, herdr's own clients, POST /api/pane/input.
    herdr has no call that types only into an idle agent with an empty input box. The order is box,
    then agent: the agent's status is what the wait for the lane leaves stale.
  • A fresh plan carries no conversation id (shared/runtime-move.ts is a wire type), so its
    conversation is not compared.
  • The journal entry is saved before the lane is taken, so a server that stops during that wait
    names an agent it never typed into.
  • rollBack calls destination.endMove even when nothing was built on herdr-core.
  • A failed read, agent_blocked and a queued message are all reported as agent_busy, as
    runMove's own first read already reports them.

The last four predate this PR.

Reviews

  • Codex gpt-6.2-sol and gpt-6.2-astra, read-only, on the first head: the same seven findings
    from both. Four were about this change and are fixed here (conversation not compared, read order,
    a failed read left in the journal, a message re-keyed during the read). Three predate it and are
    listed above.
  • gpt-6.2-sol on the second head: the read order again (decided as above), an unreachable herdr
    left in the journal (fixed), the default prompt adapter not covered by a test (the adapter is
    gone: agentPrompt is called directly), and the fresh plan (listed above).
  • gpt-6.2-sol on the third head: CLEAR, with one medium (an error code carried in herdr's reply
    counted as nothing typed) and one low (an empty pane.get answer), both fixed in this head.

Validation

  • bun run check fast on this head: passed.
  • server/runtime-move-service.test.ts and server/runtime-move-run.test.ts: the new and changed
    tests fail on main's runtime-move-run.ts and runtime-move-service.ts and pass here.
  • Not run: bun run check full, the browser regressions (no UI change), a real move on a live
    herdr.

🤖 Generated with Claude Code

… exit

The move to herdr-core read an agent's status and conversation, then its
input box, then typed the exit command. An agent that took work or switched
conversation during the input-box read, or while the exit waited for the
pane's input lane, was still typed into.

sendExit now reads the input box and then the agent inside the pane's input
lane, and refuses when the pane no longer shows the same idle agent on the
conversation the plan showed. The queue is asked again in herdr's pre-write
guard, since a held message can be re-keyed to the pane outside the lane.

A refusal comes back as a value: runMove stops with a reason the page already
translates (agent_busy, input_left, plan_changed) instead of a raw
"failed: ..." line, and an agent that was not typed into is no longer listed
as ended. That covers a failed read, the guard refusing before a byte went
out, herdr answering that it refused (agent_blocked, agent_not_found,
agent_not_ready) and a herdr that was never reached (connect_failed, still
shown as what failed). Any other error may follow the keys: it still throws
and keeps the journal entry.

Still typed into: work or a draft that starts between those reads and herdr's
Enter, 300 ms after its paste, from outside the lane (the terminal, herdr's
own clients, POST /api/pane/input). herdr has no call that types only into an
idle agent with an empty input box.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Moves now recheck an agent’s status and conversation before sending an exit request. If the agent has started working again or changed conversations, the move stops and reports the reason.
    • Agents that did not receive an exit request are no longer incorrectly reported as left behind; other agents that have exited are still restored.

The move exit flow now rechecks the pane, agent, session, and input before sending exit keys. It returns named refusal or failure results. When an exit is refused, the move removes its provisional journal entry and aborts.

Changes: Move exit validation

Layer / File(s) Summary
Exit checks and result contract
server/runtime-move-run.ts, server/runtime-move-service.ts, server/runtime-move-service.test.ts
sendExit accepts the planned session and checks the current pane, agent state, and input before sending keys. It returns named results for refusals and selected failures. Tests cover state changes, queue timing, session mismatches, and error mappings.
Move refusal and journal handling
server/runtime-move-run.ts, server/runtime-move-run.test.ts, changelog.d/move-exit-last-read.md
runMove removes the provisional journal entry and aborts when sendExit does not return sent. Tests cover exit refusal and shell timing. The changelog describes the resulting move behavior.

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

Change: Bug fix

Possibly related issues

  • Issue 3947: The changes address the move exit read-then-type race by rechecking pane and agent state before sending keys. They do not implement the issue’s HTTP API, guards, or heartbeat.
Merge Risk: Minimal · up to d4b97

The move exit flow now rereads the agent right before typing the exit command, and it stops with a named reason if the agent has become busy or changed conversation. No concrete merge-blocking defect was found. The remaining uncertainty is how herdr orders its refusal replies relative to typing, which could only matter in a narrow race.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the move now reads the agent again, last, right before typing its exit. It matches the changeset summary and the PR objectives. It is specific enough for a teammate sc…
Description check Passed The description follows the template. It has a Change section that states the problem (an agent typed into after its status and input-box reads went stale), the new behavior, and the rollback change. …
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: Title check

Explanation

The title names the main change: the move now reads the agent again, last, right before typing its exit. It matches the changeset summary and the PR objectives. It is specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description follows the template. It has a Change section that states the problem (an agent typed into after its status and input-box reads went stale), the new behavior, and the rollback change. It also has a Validation section listing the commands run (bun run check fast), the tests checked against main, and the checks not run (bun run check full, browser regressions, live herdr move). It also lists known limitations. The template asks for a linked issue only for features, and this is a fix. It references #4094 for the gap.

Finishing Touches

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 10c2f06 and d4b975e.

Files selected for processing: 5

  • changelog.d/move-exit-last-read.md
  • server/runtime-move-run.test.ts
  • server/runtime-move-run.ts
  • server/runtime-move-service.test.ts
  • server/runtime-move-service.ts

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

@devswha
devswha merged commit 9df15d6 into main Nov 18, 2026
24 checks passed
@devswha

devswha commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head d4b975e89. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit reviewed this head.

Merged by the session that opened it. Reviews: CodeRabbit at this head, no actionable comments. Codex gpt-6.2-sol and gpt-6.2-astra, read-only, on the first head: the same seven findings, four about this change and fixed, three older and listed in the PR body. gpt-6.2-sol on the second head: an unreachable herdr left in the journal (fixed), the prompt adapter (removed). gpt-6.2-sol on the third head: CLEAR; its one medium (an error code carried in herdr's reply counted as nothing typed) and one low (an empty pane.get answer) are fixed in this head with tests. bun run check fast passed on this head.

@devswha
devswha deleted the fix/move-exit-last-read branch November 18, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant