Repository navigation
fix(relay): wait for a fresh Claude Code session's mod before typing at it - #1198
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 againinlich.logsince 13 Nov).The cause is a race between two signals:
Readyas soon as its screen goes quiet, and one in an untrusted folder once session-start arrives.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
takesDeliverysaw a ready session with no mod, and the relay typed.Change
modFirstPoll), pushed to at least 10 s after session-start (modPollAfterStart) for a session held on a trust question.ModAttachinganswers whether that session's mod is due and has not polled yet.takesDeliveryrefuses delivery while it is true, so a send, a scheduled prompt and a PR watch all wait in the existingawaitReadyloop and then go to the mod.docs/ceilings.mdanddocs/hooks/mod-control.md.holdForStartcalls instartgate_test.gochanged only because the function's signature did.Test plan
TestATaskWaitsForTheFirstPollOfAModOnItsWayandTestATaskIsTypedOnceAModThatNeverPolledIsNoLongerExpectedfailed before the fix, reproducing the typed-then-typed-again pattern from the log, and pass after it (30 runs with-race).TestModAttachingUntilTheModPollsOrIsDuecovers not polled yet, polled, due, started after it was due, no mod and no transport.TestStartExpectsAModOnlyFromClaudeCodeWithThePlugindrives a realStart, and fails when the wiring inStartis disabled.gofmt,go vet ./...,go fix -diff ./...andgo test ./...clean;go vetfor darwin and windows on the touched packages.