Skip to content

fix(pending): tell a first message whose launched agent ended apart, and say both held reasons in the reader's language - #1969

Merged
devswha merged 5 commits into
mainfrom
fix/pending-launch-ended
Oct 26, 2026
Merged

devswha merged 5 commits into
mainfrom
fix/pending-launch-ended

Conversation

@devswha

@devswha devswha commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Fixes #1547.

Change

A pane's first message is held for one of two reasons that shared the code pending_target_changed: the pane's terminal or agent session changed, or the agent started for that message came up and ended before the message went (#1532). The client could not tell them apart. pending_target_changed was also missing from submitNote, so PendingMessages showed the bridge's English reason (Not sent: {message}) in Korean, Japanese and Chinese.

  • server/core/pending.ts: the launch-ended hold (LAUNCH_GONE) gets its own code, first_message_launch_ended. bindLaunched now returns "ended" when the launched agent came up and left. The drain then holds the message with that reason and drains the pane once more. Send now answers that reason and re-holds with it. launchBoundIn stops re-reading a message held for either reason. pendingContext throws the shared TARGET_CHANGED constant instead of repeating its text.
  • Version skew: an older client takes a Send now answer with a code it does not know as "maybe typed", which would leave the row "Not confirmed" with Send now hidden. The pending-action frame therefore gains an optional launch_ended: true, which this client always sends (src/lib/ws.ts). A frame without it gets pending_target_changed for this case, which an older client takes as nothing typed. The held row every connection sees keeps the new reason. A new client against an older bridge just sees pending_target_changed, as before.
  • src/lib/compose.ts: both codes are in submitNotTyped and get their own note in submitNote. src/components/PendingMessages.tsx routes both codes to submitNote.
  • src/lib/i18n/composer.{ko,ja,zh}.ts: the two notes, next to first_message_unattended's.
  • docs/agent-commands.md: the first-message paragraph names both codes and the frame flag. DESIGN.md: the first-message paragraph names the new hold reason.
  • changelog.d/pending-launch-ended-note.md.

This changes the WebSocket contract (a new held reason and an optional pending-action field) and touches queued input. Per AGENTS.md it needs a real review.

A launch also counts as ended while herdr still names its agent for a moment after the process exits, when the pane's shell itself is back in front (8efa7f6). An agent exec'd at the shell's pid keeps the shell's pid, so the process there counts as the shell only under a name other than the launched agent's, which the message keeps from the process read while that agent runs in front, from its queueing on (063fd3d, 726b73d). Without a known name, the reason stays pending_target_changed.

Known limits: a launched process named like the shell (an sh wrapper under an sh shell) falls back to pending_target_changed. A drain that lands in the instant between a killed agent's exit and an exec of another holds the message as launch-ended, which is what it is at that moment. In every case the message is held and never typed; only the note differs.

Design precedent

None applies. This gives an existing held-message note its own wording, the way first_message_unattended already has one. No new UI.

Validation

  • server/pending-input.contract.test.ts, the launched-agent cases: a launched agent that came up and quit is held with first_message_launch_ended, and Send now answers with it. A frame without launch_ended gets pending_target_changed while the row keeps the new reason. Another agent coming up in the terminal still holds the message with pending_target_changed. These cases were not re-run locally after the rebase: this PC is at its inotify instance limit, so watcher-backed contract tests fail with EMFILE here, and the herdr-backed check run was refused admission (a check slot port was held). CI's Integration job runs them.
  • src/lib/compose.test.ts, src/components/PendingMessages.test.tsx (ko, ja and zh rows for both codes, no English server text), src/lib/ws.test.ts (the frame carries launch_ended), and src/lib/i18n.test.ts. A mutation check: dropping the two codes from PendingMessages.tsx fails the new row test.
  • Browser QA on the demo build (fixture transport, no herdr session), in Korean at 1440×900 and 390×844 and in Japanese at 390×844, rerun after the rebase: two held first messages, one per code, each show their own Korean note and no English server text.
  • Reviews before the rebase: omo-native-code-reviewer approved with no HIGH finding. Codex (gpt-6.1-sol, xhigh) found no HIGH finding. Both raised the old-client skew, which the launch_ended flag fixes, and one test assertion that could not fail, which was replaced. Codex's LOW about identity-read races is the known limit above.
  • Reviews after the rebase onto main: omo-native-code-reviewer approved again with no CRITICAL, HIGH or MEDIUM finding. Its LOWs: DESIGN.md did not name the new reason (fixed here); the drain's "ended" branch is reached only when two quick pane reads disagree and has no test (correct as written); launch_ended is sent on every pending action, discards included (harmless); a comment above targetChanged on main belongs to launchGone (not in this diff). Codex (gpt-6.1-sol, xhigh) approved the rebased commit with no HIGH, MEDIUM or LOW finding; it also checked that a held message stays held in both version-skew directions and that the extra drain runs once.
  • server/core/pending.test.ts (each process read scripted in turn): a launched agent learned at an event, or bound at queueing and gone at the next read, then ended with the shell back under herdr's name for it, is first held with first_message_launch_ended and keeps it once herdr lets go. An agent of its kind exec'd at the shell's pid is held with pending_target_changed. Send now answers that reason, and pending_target_changed to a frame without launch_ended. Nothing reaches herdr's text, key or screen calls, the pty, or submitText. Each earlier commit of this PR fails its own case. On 726b73d, -t 'first message' in server/pending-input.contract.test.ts passes 19/0 on this PC.
  • Locally after the rebase onto 0.4.18: bun run typecheck passes, and src/lib/compose.test.ts, src/components/PendingMessages.test.tsx, src/lib/ws.test.ts, src/lib/i18n.test.ts, src/conventions.test.ts and scripts/changelog-fold.test.ts pass (189 tests, 0 failures). bun run check fast could not run its herdr-backed steps here for the same host reasons (inotify limit, check-slot admission), none of them in files this diff touches; per the lead it counts as passed locally, and GitHub CI runs the full suite.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 7ab4bde and 8b70415.

Files selected for processing: 15
  • DESIGN.md
  • changelog.d/pending-launch-ended-note.md
  • docs/agent-commands.md
  • server/core/pending.ts
  • server/pending-input.contract.test.ts
  • shared/protocol.ts
  • src/components/PendingMessages.test.tsx
  • src/components/PendingMessages.tsx
  • src/lib/compose.test.ts
  • src/lib/compose.ts
  • src/lib/i18n/composer.ja.ts
  • src/lib/i18n/composer.ko.ts
  • src/lib/i18n/composer.zh.ts
  • src/lib/ws.test.ts
  • src/lib/ws.ts

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

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Pending first messages now show a specific notice when the agent started for the message has ended, distinct from the notice shown when the pane’s terminal or agent session has changed.
    • These notices ask you to review the message before sending it again and are available in Korean, Japanese, and Simplified Chinese.
  • Documentation
    • Clarified when a queued first message is held because its launch ended or its target changed.

First-message holds now distinguish an agent launch that ended before delivery from a changed pane target. Pending-action requests signal support for the distinct launch-ended code. The client displays translated refusal notes for both reasons.

Changes: First-message refusal handling

Layer / File(s) Summary
Launch-ended state and compatibility
shared/protocol.ts, server/core/pending.ts, src/lib/ws.ts, server/pending-input.contract.test.ts, src/lib/ws.test.ts, DESIGN.md, docs/agent-commands.md, changelog.d/pending-launch-ended-note.md
The server holds ended launches with first_message_launch_ended and distinguishes them from changed targets. Clients send launch_ended: true to receive the specific code; older requests receive pending_target_changed. Contract tests and documentation cover the distinction.
Translated refusal notes
src/lib/compose.ts, src/components/PendingMessages.tsx, src/lib/i18n/composer.*.ts, src/lib/compose.test.ts, src/components/PendingMessages.test.tsx
The client classifies launch-ended refusals as not typed and displays distinct notes for both refusal codes. Korean, Japanese, and Simplified Chinese translations and rendering tests cover the notes.

Priority: Normal

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

Change: Bug fix

Possibly related issues

  • Issue 1533 — The change updates launch-ended holds and Send now compatibility, but does not address native Windows process detection or repeated-read behavior.
  • Issue 1518 — The change updates the hold reason and Send now behavior for an exited launch, but does not establish that all wait-state causes are fixed.
Merge Risk: Minimal · up to 8b704

Older clients can still use Send now and receive a refusal they understand. No merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 12 files. (3 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the main change: a first message whose launched agent ended now gets its own held reason, and both held reasons get translated notes. It is specific and matches the changeset, though i…
Linked Issues check Passed Issue #1547 requires separate codes, translated notes, shared TARGET_CHANGED, i18n coverage, and pending-input contract coverage. The supplied change summary reports first_message_launch_ended and…
Out of Scope Changes check Passed The changes stay within issue #1547. Server and client protocol updates support the new hold reason and old-client behavior. Tests, translations, documentation, and the changelog support the same pend…
Description check Passed The pull request description follows the required template. It explains the problem and resulting behavior, identifies the related issue, documents the WebSocket and queued-input changes, and lists va…
Full details: Title check

Explanation

The title names the main change: a first message whose launched agent ended now gets its own held reason, and both held reasons get translated notes. It is specific and matches the changeset, though it is long (119 characters).

Full details: Linked Issues check

Explanation

Issue #1547 requires separate codes, translated notes, shared TARGET_CHANGED, i18n coverage, and pending-input contract coverage. The supplied change summary reports first_message_launch_ended and pending_target_changed in server and client handling, submitNote translations in Korean, Japanese, and Chinese, and pendingContext use of TARGET_CHANGED. It also reports i18n tests and launched-agent contract cases that assert the new code and compatibility behavior. The repository diff was unavailable, so this conclusion relies on the supplied PR evidence and file evidence.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #1547. Server and client protocol updates support the new hold reason and old-client behavior. Tests, translations, documentation, and the changelog support the same pending-message behavior. No unrelated change is demonstrated.

Full details: Description check

Explanation

The pull request description follows the required template. It explains the problem and resulting behavior, identifies the related issue, documents the WebSocket and queued-input changes, and lists validation results, contract-test coverage, known test limitations, and CI coverage.

Full details: Docstring Coverage

Explanation

Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 12 files. (3 skipped: 3 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 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

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review of 8b70415. Astra gate (omo-native-gate-reviewer, gpt-6-astra) rejected it on one blocker.

What holds:

  • 169 client tests pass. In my local run, the PendingMessages, compose and ws tests passed 147/147, and typecheck is clean.
  • The draft stays held in every case Astra checked, so nothing is auto-sent or dropped.
  • Astra found no wire-compatibility problem with older clients or bundles, and nothing that looks like slop or overfitting.

BLOCKER: the wrong reason is shown when the agent label is stale (server/core/pending.ts:109-112, :618-621, :648-656)

  • When it happens: the launched process exits while herdr still reports the pane's agent label.
  • What goes wrong: the message is classified pending_target_changed, not first_message_launch_ended. When the label clears later, the reason stays wrong, because the held record is excluded from further learning. The draft is still held, but the user sees the wrong reason, which is the case this PR is meant to fix.
  • Evidence: the existing contract case at server/pending-input.contract.test.ts:1781 failed in an isolated run, receiving pending_target_changed instead of first_message_launch_ended. A controlled production-code probe reproduced the same sequence on its own.
  • Fix needed: correct the stale-label ordering while keeping real replacement detection, and add a deterministic regression case for it.

This PR touches server/ and shared/ (the WS contract), so it merges only after the 0.4.18 Release run. The re-review will cover only the new commits.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Fixed the merge pass blocker in 8efa7f6 (one new commit on 8b70415, no rebase).

Blocker: wrong reason when herdr's agent label outlasts the launched process. launchGone (server/core/pending.ts) now also counts the launch as ended when herdr still names the launched kind but the pane's own shell (shell_pid from the same pane.process_info read) is the process in front, and the process learned for the launch is no longer there. Any other process under that name, another agent kind, another terminal, or another session still goes to targetChanged and pending_target_changed. The old code already held the message in exactly this case, so only the reason changes, and nothing can be typed. A missing shell_pid leaves the old behaviour.

Regression case: server/pending-input.contract.test.ts, "says first_message_launch_ended while herdr still names its launched agent with the shell back in front, and keeps it once herdr lets go". It subscribes before the kill to the first held reason (either code). It checks that the shell is in front and herdr still names claude (the manual report). It then forces a drain with an attach, expects first_message_launch_ended, and after release_agent expects Send now to answer the same, with nothing typed.

Verification: typecheck is clean. The contract cases could not run on this PC: every case failed with EMFILE (the host's inotify instances are at 128/128), so CI's Integration job is the evidence for this commit, including the run that failed on 8b70415. omo-native-code-reviewer approved the delta with no blockers. Its LOW notes: (1) on Windows herdr lists only the launcher, but Windows launches record no pid today, so the branch cannot fire there; (2) the case relies on herdr keeping a manual report after the process exits, which it asserts, so a herdr change fails loudly; (3) the misplaced launchGone comment above targetChanged was moved and rewritten.

Codex Sol reviewed 8b70415 (APPROVE, no findings). It was not run on this delta because Codex sessions are stalling host-wide; the merge pass reviews.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Merge pass re-review of 8efa7f6 (Astra gate). The original SC3 case is fixed, but the fix broke replacement detection.

Fixed:

  • The stale-label case now reports first_message_launch_ended and keeps that reason after the label clears.
  • The contract case at server/pending-input.contract.test.ts:1781 now passes.
  • The new regression at :1793 exercises the stale-label ordering deterministically.

BLOCKER: an agent exec'd at the shell's PID is read as launch-ended (server/core/pending.ts:653-656)

  • What goes wrong: the new shellBack check takes identity.processPid === shellPid as proof that the shell came back. But exec keeps the PID, so that PID can belong to the replacement agent.
  • Evidence: the existing real-process replacement contract at server/pending-input.contract.test.ts:1484 (fixture :159-163) fails. It expects pending_target_changed and receives first_message_launch_ended. A separate production-code probe reproduced the same result with a foreground agent at shell_pid and no shell snapshot in between.
  • Effect: the draft stays held, but the reason shown is wrong.
  • Fix: tell a shell that really returned apart from an exec'd replacement, for example by checking the foreground process's name or start time against the shell's. Keep the replacement assertion at :1484.

This PR touches server/ and shared/, so it merges only after the 0.4.18 Release run. The re-review will cover only the new commits.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Fixed the second blocker in 063fd3d (one new commit on 8efa7f6).

Blocker: an agent exec'd at the shell's pid read as launch-ended. A launch-bound first message now keeps the process name of its launched agent (launchedNames in server/core/pending.ts). The name is read from the same pane.process_info read while that process runs in front under the launched kind, whether its pid was bound at queueing (the launch's own pid) or learned at an event. The process at shell_pid counts as the shell only under a name other than the launched agent's. An agent of the kind exec'd there keeps that name and goes to targetChanged, so it is held with pending_target_changed. Without a known name, the reason stays pending_target_changed, as before 8efa7f6. The :1484 replacement assertion is unchanged.

Covered without herdr timing: server/core/pending.test.ts gains three cases with a scripted process read and session snapshot:

  • learned at an event and ended, with the shell back under herdr's name for it: first_message_launch_ended
  • bound at queueing and ended the same way: first_message_launch_ended
  • bound at queueing and replaced by an agent of its kind exec'd at the shell's pid: pending_target_changed

Each earlier commit fails its own case:

  • 8b70415 fails the two ended cases (the first blocker).
  • 8efa7f6 fails the exec case (this blocker).
  • An intermediate version that kept the name only when the pid was learned at an event fails the queueing case. omo-native-code-reviewer found that gap (MEDIUM), and it is fixed here.
  • 063fd3d passes all three.

Removed: the contract case added in 8efa7f6 ("says first_message_launch_ended while herdr still names its launched agent..."). It relied on herdr keeping its manual name after the process exited. In an isolated run, herdr had already dropped the name by the control assertion, so the case passed or failed by timing. The scripted unit cases cover what it was meant to cover.

Verification on this PC:

  • bun test --timeout 30000 -t 'first message' ./server/pending-input.contract.test.ts through bun run check run, on this pending.ts: 21 pass, 0 fail, no EMFILE. That run included :1484, the launch-ended cases, and the case now removed.
  • server/core/pending.test.ts passes 5/5. server/conventions.test.ts and src/conventions.test.ts pass, and typecheck is clean.

Reviews: omo-native-code-reviewer approved the exec fix, with the MEDIUM above (now fixed) and these LOWs:

  • A drain that lands in the instant between the killed agent's exit and the exec holds the message as launch-ended. That is true at that moment: the agent has ended and the shell is in front.
  • A launched process with the same name as the shell (an sh wrapper under an sh shell) falls back to pending_target_changed.

Codex was not run on this delta because Codex sessions are stalling host-wide. The merge pass reviews.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Merge pass re-review of 063fd3d (Astra gate). The exec-at-shell-PID blocker is fixed. Two findings remain.

Fixed: the replacement assertion at server/pending-input.contract.test.ts:1484 is unchanged and passes. Once the agent's name has been learned, the production probe tells an exec'd agent apart from a returned shell, and the reason survives the stale label clearing. 5 core tests and 4 selected contracts pass.

BLOCKER 1: if the agent exits before the first drain, the stale-label bug comes back (server/core/pending.ts:574, :604-615, :664-667)

  • Cause: the read made when the message is queued sees the live agent's name but doesn't save it. Only later learn() calls fill launchedNames.
  • Result: if the agent exits before the next read, the returned shell is classified pending_target_changed permanently, even after the label clears.
  • Reproduced: deterministically, against the production implementation.
  • Fix: keep the name observed when the message is queued, and add a test where the agent exits before the first drain.

BLOCKER 2: the moved regression lost coverage (server/core/pending.test.ts:104-149, server/pending-input.contract.test.ts:1744-1790)

  • What the new core cases don't do:
    • They never clear the stale label, and never press Send now once the hold is in place.
    • They check the last reason, not the first.
    • Their empty-typed assertion watches the immediate submitText path. Pending delivery writes through paneSendText/paneSendKeys (server/core/pending.ts:452, :470, :802).
  • Contract test: the remaining contract test releases the label before it awaits the hold, so it no longer reliably keeps the ordering the deleted regression covered.
  • Fix: bring back the transition and action assertions, and watch the real pending write path.

This PR touches server/ and shared/, so it merges only after the 0.4.18 Release run. The re-review will cover only the new commits.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Both findings are fixed in 726b73d (one new commit on 063fd3d).

BLOCKER 1: the agent exits before the first drain. queueFirstMessage now runs learn on its own currentIdentity read (server/core/pending.ts), as an event's read would. An agent that read sees in front under the launched kind has its process name kept before it can leave. learn's own guards are unchanged: herdr must name the launched kind, and nothing known may disagree. A launch pid that is not in front at that read therefore records nothing.

BLOCKER 2: the moved regression's coverage. The unit case in server/core/pending.test.ts now scripts each pane.process_info answer in turn, so a read at queueing can see the agent and the very next read find it gone, with no timing involved. It covers three scenarios:

  • learned at an event, then ended with the shell back under herdr's name
  • bound at queueing and gone at the next read, the same way (this blocker)
  • bound at queueing and replaced by an agent of the kind exec'd at the shell's pid

Each scenario checks:

  • the first reason the message is held with
  • for the ended ones, that herdr letting go of the name keeps the reason (the transition)
  • Send now with launch_ended answers that reason, and Send now without it answers pending_target_changed, while the card keeps the reason
  • nothing reaches herdr's paneSendText, paneSendKeys or paneRead, the pty (sight().write), or submitText. The harness gives the page a ready, attached sighting, so only the message's own checks stand in the way.

Mutation checks (the same unit file, against each pending.ts):

  • 8b70415 fails the two ended cases.
  • 8efa7f6 fails the exec case.
  • 063fd3d fails the gone-before-any-event case (this blocker).
  • A mutant whose Send now skips bindLaunched and pendingContext's identity check reaches the mocked paneRead, so its answer becomes submit_failed, and all three cases fail.
  • 726b73d passes 5/5.

Verification on this PC:

  • -t 'first message' in server/pending-input.contract.test.ts through bun run check run: 19 pass, 0 fail, no EMFILE. That is 21 minus the herdr-timing case removed in 063fd3d and the one never pushed.
  • server/core/ unit tests and both conventions tests: 122/0.
  • Typecheck is clean.

The remaining contract case (:1744) is unchanged. It passes in either order, and the ordering is now pinned by the scripted unit case.

@devswha
devswha force-pushed the fix/pending-launch-ended branch from 726b73d to eece2f0 Compare October 26, 2026 09:59
@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto main 4d2e360 after the 0.4.18 freeze and pushed once (eece2f0, same changes as 726b73d; omo-native-code-reviewer approved round 3 with LOWs only); the earlier run 40301897013 was cancelled during the freeze, not failed, and I re-run nothing.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

#1986 merged as 1f8bb08. As agreed, please rebase onto main together with the test fix for the semantic conflict with #1986, and push once. Only the rebase and the test change will be re-checked.

mp added 5 commits October 26, 2026 20:57
…and say both held reasons in the reader's language

A first message held because the agent started for it has ended now carries
its own code, first_message_launch_ended, instead of sharing
pending_target_changed with a pane whose terminal or agent session changed.
Both codes get a note of their own in Korean, Japanese and Chinese, so a held
row no longer shows the bridge's English reason. pendingContext throws the
shared TARGET_CHANGED constant.

Send now answers the new code only to a client whose pending-action frame says
launch_ended; an older client, which would take an unknown code as maybe typed,
is answered pending_target_changed, while the card keeps the new reason.

Fixes #1547
…th the shell back in front

The launched process can exit while herdr still names its agent in the pane.
The first message was then held as pending_target_changed, and since a
message held for that reason is not read again, the wrong reason stayed.
launchGone now also counts the launch as ended when herdr names the launched
kind but the pane's own shell is the process in front; any other process
under that name is still another agent.

A contract case kills the launched agent while herdr's manual report still
names it, checks the shell is back in front, and expects the first held
reason to be first_message_launch_ended, kept after herdr lets go.
…shell coming back

An exec keeps the pid, so an agent exec'd in place of the pane's shell was
read as the shell back in front and its first message held as the launch
having ended, not as a replacement. A launch-bound first message now keeps
the process name of its launched agent, read while that process runs in
front under the launched kind, whether its pid was bound at queueing or
learned at an event. The process at the shell's pid counts as the shell only
under another name; without a known name the reason stays
pending_target_changed.

The stale-name reads are covered in server/core/pending.test.ts, where the
process read is scripted: learned at an event or bound at queueing and ended
with the shell back under herdr's name (first_message_launch_ended), and an
agent of the kind exec'd at the shell's pid (pending_target_changed). The
contract case that relied on herdr keeping its name after the process exited
is removed: herdr drops it at its own pace, so that case could pass or fail
by timing.
… a held first message's reason end to end

A first message bound at its queueing kept its launched agent's name only
from a later event's read, so an agent that left before the first drain was
read with no name, and the shell back in front under herdr's stale name
held the message as pending_target_changed for good. queueFirstMessage now
learns from its own read as an event would.

The unit cases in server/core/pending.test.ts script each process read in
turn: learned at an event, or bound at queueing and gone at the next read,
with the shell back under herdr's name, and an agent of the kind exec'd at
the shell's pid. Each checks the first reason it is held with, that the
reason stays once herdr lets go of an ended agent's name, that Send now
answers that reason (and pending_target_changed to a frame without
launch_ended), and that nothing reaches herdr's text, key or screen calls,
the pty, or submitText.
… however many reads it makes

The case where a launch's agent leaves before any event scripted exactly one
process read for the queueing. An identity read that reads the foreground
again before it answers (#1986) then saw the agent gone at its queueing and
the case failed, though nothing it checks changed. The agent now leaves from
the second session snapshot on, which every identity read starts with, so the
queueing's reads see it and every later read, whichever drain makes it, finds
it gone.
@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Head moved: rebased onto main after #1986 merged (1f8bb08), with one test-only commit (95588f8).

Why: #1986 and this PR both change server/core/pending.ts and merge without a git conflict. But #1986's currentIdentity reads the pane's foreground again before it answers. This PR's unit case "bound at its queueing, then left before any event" in server/core/pending.test.ts scripted exactly one process read for the queueing. With #1986 in, the queueing's second read already saw the agent gone, and the case failed. Production behaviour is unchanged; the case counted reads.

Fix (test only): the agent now leaves from the second session snapshot on. Every identity read starts with that snapshot, so the queueing's reads see the agent and every later read, whichever drain makes it, finds it gone. That holds however many process reads an identity read makes.

Checked locally:

One push, so one CI run.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review report. Overall: PASSED. This PR changes queued input (pending first messages) and the WS contract (shared/protocol.ts). Each round was reviewed by an Astra gate (omo-native-gate-reviewer, gpt-6-astra). It approved 726b73d after four rounds. CodeRabbit was rate-limited, so this agent review stands in for it, as AGENTS.md allows.

What holds:

  • The two held reasons are now separate codes: the session changed (pending_target_changed), and the launched agent ended (first_message_launch_ended). Both are localized in ko, ja and zh.
  • A held message is never sent automatically, and its draft is kept.
  • An older client or bundle still keeps the message held.

Findings, and how each was resolved:

  • SC3, stale label (8b70415): the launched process exited while herdr still named its agent. The message was held as pending_target_changed and never corrected. Fixed in 8efa7f6.
  • SC3, exec at shell_pid (8efa7f6): an agent exec'd at the shell's PID was read as the shell coming back. Fixed in 063fd3d: an exec'd agent is told apart from a returned shell, and the replacement contract at server/pending-input.contract.test.ts:1484 still passes.
  • Exit before the first drain (063fd3d): the name seen at queueing was not saved, so an agent that exited before the first drain brought the stale-label bug back. Fixed in 726b73d: the name is learned at queueing. The reason survives the label clearing, the draft stays held and unchanged, and exec at shell_pid still gives pending_target_changed.
  • Coverage lost when the regression moved (063fd3d): restored in 726b73d. The tests now:
    • assert the first hold reason;
    • clear the stale label;
    • press Send now afterwards;
    • check the replies to both client versions;
    • watch the real pending write path: paneSendText/paneSendKeys and the terminal writes.

Checks: 5 core tests, 4 selected contracts and all 3 production probes pass. Locally, PendingMessages, compose and ws pass 147/147, pending.test passes, and typecheck is clean.

git merge-tree against main is clean. This PR shares files with #1970, #1975, #1977, #1979, #1980, #1981, #1986, #1991, #1995 and #1997, and merges cleanly with each. It merges only after the 0.4.18 Release run, because it touches server/ and shared/.

Rebase onto #1986 (95588f8):

  • Rebase: commits 1-4 are unchanged in the range-diff.
  • Why the test changed: fix(pending): bind a queued message to the agent process as command outcomes do, and read its birth without blocking #1986 made an identity read check the foreground again before it answers. That broke one case, which had scripted exactly one process read for the queueing. Nothing the case checks had changed.
  • The test-only commit 95588f8: the agent now leaves from the second session snapshot on, so the result no longer depends on how many reads happen. No production code changed.
  • Results: on the rebased head, the four changed test files (pending, PendingMessages, compose, ws) pass 153/153 three times in a row, and typecheck is clean.

@devswha
devswha merged commit f53db83 into main Oct 26, 2026
19 checks passed
@devswha
devswha deleted the fix/pending-launch-ended branch October 26, 2026 16:57
devswha added a commit that referenced this pull request Oct 28, 2026
…he first agent ends (#2222)

Found by the main-integration lane: Integration failed on main run
40644839354 (30cd84f) and on #2176's run 40643516119.

## Cause (test flake, not a product regression)

`a create request's first message > is bound to the agent process it was
queued under: a replacement of the same kind ...` started SESSION2 from
the shell (`recorder SESSION1; exec recorder SESSION2`). Between SIGKILL
of SESSION1 and the `exec`, bash alone is in front. A pane event in that
gap makes `launchGone` (shell back in front, `server/core/pending.ts`)
hold the message as `first_message_launch_ended`. That is the documented
behaviour from #1969: the launched agent did end, and no agent was in
front. The test expected `pending_target_changed`, so it failed whenever
a read landed in the gap.

**Reproduced:** keeping the shell busy for a moment before the `exec` (a
builtin loop, so the shell itself stays in front) fails the old test 3
of 3, with exactly CI's `Received: "first_message_launch_ended"`. A
`sleep 1` there does not reproduce it, because `sleep` is another
process and reads as a changed target.

## Change

- The npm-style launcher fixture now also handles SIGUSR1: it starts
SESSION2, and ends SESSION1 once SESSION2 has spawned, so an agent is in
front throughout. Its exit-driven path (used by the #1545 test) is
unchanged.
- The test uses that launcher and waits until herdr no longer lists
SESSION1 before it reports idle.

## Proof

- **Mutation:** with `samePendingIdentity` ignoring process pid and
birth, the new test fails 2 of 2 (the message is typed into SESSION2).
- **Stress:** the first-message block plus the two replacement tests (21
tests) passed 10 of 10 on CI's Node 22 and herdr 0.9.3, through `dori
heavy` on a loaded host.
- **Local checks:** `bun run check fast` ok.

Test-only: no app code changes. Splits from the same lane: #2223 and
#2224.

## Reviews

- **omo-native-code-reviewer**, round 1 on the combined change: BLOCK
with two HIGHs, both fixed. One was a loop shape that
`scripts/conventions.test.ts` counts as a fixed sleep; the other was the
OpenCode helper not waiting for its own Ctrl-L. Round 2 on these heads:
APPROVE, no findings above LOW.
- Test-only, so no Codex review (notes/pr-policy.md: the test-only gate
is omo alone).
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.

Pending messages: translate the target-changed notes and tell a launch that ended apart

1 participant