Skip to content

fix: reliable post-launch prompt delivery#229

Open
AgentWrapper wants to merge 1 commit intomainfrom
fix/reliable-prompt-delivery
Open

fix: reliable post-launch prompt delivery#229
AgentWrapper wants to merge 1 commit intomainfrom
fix/reliable-prompt-delivery

Conversation

@AgentWrapper
Copy link
Collaborator

Summary

  • Replace blind 5-second setTimeout + unverified sendMessage() in session-manager.ts with a polling-based ready-detection loop
  • Poll for agent process existence (up to 30s), then poll for idle state via detectActivity() (up to 60s) before sending the prompt
  • Verify delivery by checking for active state after send (3 attempts with retry)
  • Log console.warn on failure instead of silently swallowing errors — user sees actionable retry instructions (ao send <session>)

Problem

ao spawn delivered the initial prompt via a fixed 5-second delay + blind runtime.sendMessage(), which failed ~50% of the time because Claude Code takes longer than 5s to start (trust prompt, loading CLAUDE.md, etc.). Errors were silently caught, leaving users with idle sessions that never received instructions.

Test plan

  • All 82 existing session-manager tests pass (including 6 updated post-launch tests)
  • New test: polls for agent readiness before sending (verifies detectActivity called multiple times)
  • New test: verifies delivery by checking for active state (confirms no unnecessary retries)
  • TypeScript typecheck passes
  • Full test suite passes (core + cli)

🤖 Generated with Claude Code

Replace the blind 5-second wait + unverified sendMessage with a proper
polling loop that:

1. Polls for agent process existence (up to 30s)
2. Polls for agent idle state via detectActivity (up to 60s)
3. Sends the message once the agent is ready
4. Verifies delivery by checking for active state (3 attempts)
5. Logs warnings on failure instead of silently swallowing errors

This reuses patterns from `ao send` (busy detection + retry) and the
integration test (waitForTuiReady polling for ❯ prompt).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

console.warn(
`[ao] Session ${sessionId}: agent not idle after ${READY_POLL_TIMEOUT_MS / 1000}s. Sending prompt anyway.`,
);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misleading warning when waiting_input exits loop early

Low Severity

When detectActivity returns "waiting_input", the Step 2 loop breaks early without setting agentReady = true. The subsequent warning then claims "agent not idle after 60s" even though the timeout was never reached — the loop exited because the agent was in waiting_input state. This logs incorrect elapsed time and hides the actual reason (a permission/trust prompt), which could mislead operators debugging delivery issues.

Additional Locations (1)

Fix in Cursor Fix in Web

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