Skip to content

fix(relay): wait for a fresh Claude Code session's mod before typing at it - #1198

Merged
omartelo merged 2 commits into
mainfrom
fix/relay-wait-for-mod-first-poll
Nov 17, 2026
Merged

omartelo merged 2 commits into
mainfrom
fix/relay-wait-for-mod-first-poll

Conversation

@omartelo

Copy link
Copy Markdown
Collaborator

Summary

A task relayed to a Claude Code session that just opened was typed at its PTY, left on the prompt with its Enter lost, and then handed to the mod by the receipt check 30 seconds later, so the session ran it while the typed copy stayed in the composer. Seen on fan-out subagent cards (relay: task was typed and nothing read it, typing it again in lich.log since 13 Nov).

The cause is a race between two signals:

  • A Claude Code session in a trusted folder is Ready as soon as its screen goes quiet, and one in an untrusted folder once session-start arrives.
  • The lich-plugin mod polls only from Claude Code's own session.start. Measured on Claude Code 2.1.326 against a logging server: the first poll comes 0.6 s after session-start on a fresh session (2.3 s from spawn) and 1.6 s after it on a resumed 16 MB transcript (5.2 s from spawn).

Inside that gap takesDelivery saw a ready session with no mod, and the relay typed.

Change

  • The terminal records on a spawned Claude Code session whose lich-plugin is installed in its profile (the same check the start gate makes) when its mod is due: 20 s from spawn (modFirstPoll), pushed to at least 10 s after session-start (modPollAfterStart) for a session held on a trust question.
  • ModAttaching answers whether that session's mod is due and has not polled yet. takesDelivery refuses delivery while it is true, so a send, a scheduled prompt and a PR watch all wait in the existing awaitReady loop and then go to the mod.
  • Past the bound, a session whose mod never polled (mods off, Claude Code older than 2.1.280) is typed at as before, only later. Written into docs/ceilings.md and docs/hooks/mod-control.md.
  • The holdForStart calls in startgate_test.go changed only because the function's signature did.

Test plan

  • TestATaskWaitsForTheFirstPollOfAModOnItsWay and TestATaskIsTypedOnceAModThatNeverPolledIsNoLongerExpected failed before the fix, reproducing the typed-then-typed-again pattern from the log, and pass after it (30 runs with -race).
  • TestModAttachingUntilTheModPollsOrIsDue covers not polled yet, polled, due, started after it was due, no mod and no transport.
  • TestStartExpectsAModOnlyFromClaudeCodeWithThePlugin drives a real Start, and fails when the wiring in Start is disabled.
  • Local gate: gofmt, go vet ./..., go fix -diff ./... and go test ./... clean; go vet for darwin and windows on the touched packages.

@omartelo
omartelo merged commit 23e4c68 into main Nov 17, 2026
8 checks passed
@omartelo
omartelo deleted the fix/relay-wait-for-mod-first-poll branch November 17, 2026 23:39
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