Skip to content

swarm: await_members has no blocking mode and swarm dependency IDs are not accepted by bg wait #2152

Open

Description

@osmanaksu

Type: enhancement (the non-blocking wake behavior is by design and works; this is adding an opt-in blocking/unified wait)
Labels: enhancement, swarm

Problem
swarm await_members is non-blocking: it registers a dependency and returns immediately with "Watching ... in the background. You'll be woken." The wake mechanism works, but there is no synchronous join, and the dependency ID returned is not accepted by bg wait (which only knows background tasks). A coordinator with nothing else to do ends up in a poll loop (swarm list / repeated await_members), and the two "waitable" subsystems (swarm deps vs. bg tasks) do not share a common handle.

Code

  • crates/jcode-app-core/src/server/background_tasks.rs:259-343 — dispatch_swarm_await_completion delivers a soft-interrupt + wake when the condition is met; it is inherently non-blocking.
  • Test: crates/jcode-app-core/src/tool/communicate_tests/end_to_end.rs:135-242 — communicate_await_members_background_returns_immediately_and_notifies.
  • bg wait (the background-task subsystem) does not resolve swarm dependency IDs; it returns "Task not found" for them.

Repro

  1. swarm await_members with mode=all.
  2. It returns immediately with a dependency ID.
  3. bg wait with that dependency ID → "Task not found".
  4. The coordinator must either poll swarm list or wait for the wake; there is no blocking alternative.

Suggested fix (low priority — the wake mechanism works)

  1. Add a wait=true (or blocking) option to swarm await_members that blocks until the condition is met or the timeout elapses.
  2. Or introduce a unified "waitable handle" type that both bg wait and swarm await_members accept, so a coordinator can wait on either with one call.

Acceptance

  • swarm await_members with wait=true blocks and returns the result when the condition is met (or on timeout).
  • A single wait call accepts both background-task IDs and swarm dependency IDs (unified handle).
  • Default (non-blocking) behavior is unchanged.

Activity

  1. osmanaksu commented on Nov 12, 2026

    @osmanaksu
    Author

    This is a deliberate design decision, not a bug. The code comment in communicate.rs:1784-1786 states:

    Public member waits are always asynchronous. The blocking CommAwaitMembers protocol remains available internally, but agents must not park an entire turn waiting on a worker or a long-lived socket.

    The background flag is hardcoded to true (line 1786) regardless of what the agent requests. If an agent requests background: false, the response includes a compatibility note: "Blocking member waits are no longer supported; this wait was started asynchronously."

    The rationale: a blocking wait would park the agent's entire turn (and the coordinator's turn) on a long-lived socket, blocking all other work. The recommended pattern is:

    1. Start the wait with background: true (default).
    2. Record the returned wait ID in todo.waiting_on.
    3. Continue working on independent tasks.
    4. The wait completes in the background and notifies/wakes the session.

    The internal CommAwaitMembers protocol does support blocking (the background: false path exists in the server), but it is intentionally not exposed to the public swarm tool to prevent agent turns from stalling.

    This is not something to fix — it is the intended behavior. Closing as not-a-bug.

  2. added
    enhancement
    area: swarm
    triage: needs-decision
    on Nov 13, 2026
  3. 1jehuang commented on Nov 13, 2026

    @1jehuang
    Owner

    Thanks for following up with the code comment. Triage: as you noted, non-blocking member waits are intentional. I am leaving this open for the maintainer to confirm whether to close it or keep the unified wait handle idea as a feature request.


    — Jcode agent (automated triage), on behalf of @1jehuang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: swarmenhancementtriage: needs-decision

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions