Skip to content

swarm tool fails with 'Not in a swarm. Use a git repository to enable swarm features.' after /clear (member never re-registered) #874

Closed

Description

@sorairo-fullstack

Summary

After /clear, every swarm tool action that needs membership (spawn, list, start, …) fails with:

Not in a swarm. Use a git repository to enable swarm features.

The message points at git, but the repo is a valid git worktree (git rev-parse --is-inside-work-tree → true) and features.swarm = true. The actual cause is that the session created by /clear is never registered as a SwarmMember.

Version: v0.75.0 (5ae2385), Windows x86_64.

Root cause

In crates/jcode-app-core/src/server/client_session.rs, handle_clear_session:

  1. Removes the old session's member entry (intentional, per the comment "Do not migrate the old session's swarm membership"):
    let swarm_id_for_update = {
        let mut members = swarm_members.write().await;
        members.remove(client_session_id).and_then(|member| member.swarm_id)
    };
  2. Then calls update_member_status(&new_id, "ready", …) — but update_member_status_with_report_tldr (swarm.rs) only does members.get_mut(session_id) and silently no-ops in the else branch when the member does not exist. It never inserts.
  3. The only function that creates a member, ensure_client_swarm_member, is called exclusively from handle_subscribe. /clear never re-runs it, and the connection stays subscribed, so no new subscribe happens.
  4. The clear_done log then reports swarm_id_updated=true, which is misleading: it only means the old member had a swarm id to remove, not that the new session was registered.

Result: the new session has no SwarmMember entry, so every swarm_id_for_session(id) → members.get(id).and_then(|m| m.swarm_id) returns None, and all comm handlers answer "Not in a swarm."

Evidence (from ~/.jcode/logs/jcode-2026-08-10.log)

17:43:37 EVENT event=SESSION_LIFECYCLE … phase=clear_done old_session_id=session_guppy_… new_session_id=session_skunk_… swarm_id_updated=true
17:45:00 EVENT event=TOOL_LIFECYCLE … error="Not in a swarm." (swarm spawn)
17:45:08 EVENT event=TOOL_LIFECYCLE … error="Not in a swarm. Use a git repository to enable swarm features." (swarm list)

Every phase=swarm_member_registered event of the day belongs to sessions that went through handle_subscribe; none names the /clear-born session. Its state file ~/.jcode/state/swarm/session_session_skunk_….json does not exist.

Checked 5ae238574..origin/master on client_session.rs: no later commit fixes this. #816's fix (reset swarm plan state on clear, 5496ebb) is an ancestor of v0.75.0 and doesn't cover member re-registration.

Repro

  1. Open a jcode TUI session in a git repo, use any swarm action (works).
  2. /clear.
  3. swarm list → "Not in a swarm. Use a git repository to enable swarm features."

Workaround: quitting the client and jcode resume on the same session re-registers the member via handle_subscribe.

Suggested fix

In handle_clear_session, after swapping in the fresh agent and before update_member_status, re-register the replacement session, e.g. call ensure_client_swarm_member(&new_id, client_connection_id, …, swarm_enabled, …) (the old member's swarm_enabled can be captured before the remove). Alternatively, make the update_member_status no-op branch log a warning so the next silent drop of this kind is visible.

Also worth a tweak: the "Use a git repository to enable swarm features" wording sends users debugging git/config when membership is the actual gate.

Activity

  1. sorairo-fullstack commented on Aug 10, 2026

    @sorairo-fullstack
    Author

    Additional downstream symptom, same root cause: the swarm panel hotkey (Alt+N by default) permanently reports "Swarm view closed" after /clear.

    inline_swarm_gallery_active() (crates/jcode-tui/src/tui/app/tui_state.rs) requires !inline_swarm_members().is_empty(), and inline_swarm_members() scopes to the session's spawn subtree. Since every swarm spawn fails with "Not in a swarm." in the /clear-born session, the member list can never become non-empty, so cycle_swarm_panel_view() always falls into the Chat branch and the panel can never open.

  2. added
    bug
    priority: high
    triage: reproducible
    autonomous: clear
    on Aug 10, 2026
  3. 1jehuang commented on Aug 10, 2026

    @1jehuang
    Owner

    Thanks for the detailed root-cause analysis. I reproduced the lifecycle gap and opened #876 with a fix that registers the /clear replacement as a fresh swarm root while still removing the old swarm and plan participation. The focused clear-session regression test and affected-crate checks pass.

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

  4. added a commit that references this issue on Aug 12, 2026
    0e6a528
  5. added a commit that references this issue on Aug 15, 2026
    a8e0afd
  6. added 5 commits that reference this issue on Aug 30, 2026
    f06bb3e
    2647be3
    b0035d7
    5e19f24
    f097fca
  7. added a commit that references this issue on Sep 18, 2026
    41248b0
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

    autonomous: clearbugpriority: hightriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions