Skip to content

fix(cli): agent wait returns when agent already matches --until - #504

Open
codeaholicguy wants to merge 2 commits into
mainfrom
cursor/agent-wait-until-initial-state-5af4
Open

codeaholicguy wants to merge 2 commits into
mainfrom
cursor/agent-wait-until-initial-state-5af4

Conversation

@codeaholicguy

@codeaholicguy codeaholicguy commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Problem

ai-devkit agent wait --until only noticed status changes after a baseline snapshot. If a worker was already waiting, a filtered wait (with --id) could sit until timeout unless you ran agent list --json first. Unfiltered waits in recipes like the channel ping loop should stay transition-only so you do not get duplicate pings on startup.

Root cause

waitForAgentChanges in packages/cli/src/services/agent/agent-wait.service.ts took one baseline list() and then used diffAgentChanges, which ignores agents that are already in a target status. That is correct for ongoing polls, but lead/worker loops that pass --id need a one-shot check on the current state.

Wait behavior lives in the CLI service. I did not change packages/agent-manager or devkitd.

Fix (option C, Hoang)

  1. When watch is set (--id or --group), after subscribe and the baseline list, if every watched agent already matches --until, return immediately with reason: "triggered" and the same JSON shape as a transition (from and to are the current status).
  2. If any watched agent is not in --until yet, block for transitions as on main.
  3. When watch is omitted (unfiltered wait), no initial-state shortcut. Behavior matches main (transition-only).

Test plan

npm run build
cd packages/cli && npx vitest run tests/services/agent/agent-wait.service.test.ts tests/commands/agent.test.ts -t wait
cd packages/cli && npx vitest run
npm run lint

Regression tests:

  • Filtered wait: watched agent already waiting returns triggered on the first list.
  • Filtered wait: two --id targets, only one already waiting, still times out until transition.
  • Unfiltered wait: agent already waiting still times out until a new transition.
  • CLI integration for --id immediate match and unfiltered timeout.

Behavior changes

  • Filtered wait (--id / --group): returns immediately when every watched agent already satisfies --until. No need to call agent list --json first for the lead/worker case.
  • Unfiltered wait: still transition-only. Channel ping recipes at lines 133 and 218 in 22-agent-wait-channel-ping-recipe.md are unchanged in intent.
  • appeared: still transition-only (no instant match for agents already listed).

Review note: Hoang can still switch to option B during review (opt-in --now flag on any wait) if he wants unfiltered immediate match without changing default semantics.

Docs

  • web/content/docs/8-agent-management.md
  • web/content/docs/20-cross-vendor-agent-recipe.md
  • web/content/docs/22-agent-wait-channel-ping-recipe.md
  • skills/agent-orchestration/SKILL.md

init --demo (PR #487) does not call agent wait; no change there.

Risks

Skills / process

dev-lifecycle, tdd, verify, dev-commit, dev-review.

Tooling friction

None on this push.

Open in Web Open in Cursor 

cursoragent and others added 2 commits November 27, 2026 16:07
…until

Check the current agent list right after the baseline read. If any watched
agent already satisfies --until, return triggered with the same JSON shape
instead of waiting only for transitions.
Check current state only for filtered waits. Every watched agent must
already match --until for an immediate return; unfiltered waits stay
transition-only. Update web docs and agent-orchestration skill.

Co-authored-by: Hoang Nguyen <codeaholicguy@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

2 participants