Repository navigation
fix(agent): wait for session file in agent send --wait - #401
Open
codeaholicguy wants to merge 1 commit into
Open
codeaholicguy wants to merge 1 commit into
codeaholicguy wants to merge 1 commit into
Conversation
agent send --wait executed right after agent start failed with "No session file found" because the registry entry exists at start while the session file only materializes when the harness writes its first entry (on the first message). The wait path resolved the session file at dispatch time and failed immediately. Send the prompt first, then poll listAgents() for the session file to appear, bounded by the caller's --timeout or a 30s default grace period. Session-file appearance doubles as the harness readiness signal, so sends into a still-booting TUI are no longer silently dropped either. A distinct error is raised when the agent process exits without ever creating a session file. Closes #400 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This branch has not been deployed
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.
Closes #400
Repro
Root cause
The agent registry entry is created at
agent start, but the session file only materializes when the harness writes its first entry — which happens on the first message.sendToAgentresolvedagent.sessionFilePathat dispatch time and threwNo session file foundimmediately when it was absent, sosend --waitright afterstartcould never succeed.Fix design
In
sendToAgent(packages/cli/src/services/agent/agent.service.ts):sendAgentPrompt). This matters: the send is often what triggers the harness to write its first session entry.agent.sessionFilePathis absent, the newwaitForSessionFilepollsmanager.listAgents()every 500ms until the file appears, bounded bymin(--timeout, 30s)default grace.listAgents()while polling, a distinct error is raised:Agent "<name>" exited before creating a session file— separate from the generic response timeout.Agent "<name>" did not create a session file within <N>ms.sessionFilePathalready exists, behavior is unchanged: the transcript baseline is still seeded before the send so no messages are skipped.Validation
agent.test.ts— file appears after send → success; agent exits → distinct error; grace expiry → bounded error.packages/clisuite: 1341 tests pass.e2e/agent-send-wait.e2e.tsdrives the compiledsendToAgentthrough a scriptedlistAgents()sequence reproducing start-then-send-wait. Trade-off: a realagent startboot needs tmux + a live harness binary, too heavy for CI — so process detection and tmux delivery are stubbed via the injectedruntime/focusManagerseams while the send → poll → wait path runs against the real built dist. Verified it catches the bug: all 3 tests fail against the pre-fix code.npm run lint,npm test,npm run test:e2eall green (pre-commit hook + manual runs).Generated with Devin