Skip to content

swarm-spawned (inline/headless) agents unconditionally get isolated test-mode memory storage, can never see real project/global memory #729

Closed

Description

@jonschull

Summary

Every inline/headless swarm-spawned agent has its memory tool silently and unconditionally forced into isolated test-mode storage, so spawned workers can never read or durably write real project/global memory, regardless of any fix to #491 or #720. This is a distinct bug from those two (different root cause, different fix shape) found while investigating the follow-up the maintainer requested on #720 (verifying the swarm-spawn path).

Root cause

create_headless_session in crates/jcode-app-core/src/server/headless.rs unconditionally calls:

let registry = Registry::new(provider.clone()).await;

registry.enable_memory_test_mode().await;

enable_memory_test_mode (crates/jcode-app-core/src/tool/mod.rs) replaces the registry's memory tool with MemoryTool::new_test(), which sets MemoryManager { test_mode: true, .. }. With test_mode: true, project_memory_path() (crates/jcode-base/src/memory.rs) always resolves to ~/.jcode/memory/test/, completely ignoring ctx.working_dir — this is presumably by design for the debug/test harness path, but create_headless_session is also the production code path for real swarm-spawned agents:

// crates/jcode-app-core/src/server/comm_session.rs:654-680
let (new_session_id, is_headless_fallback) = match visible_spawn {
    Ok((new_session_id, true)) => Ok((new_session_id, false)),
    Ok((_, false)) | Err(_) => {
        ...
        create_headless_session(
            sessions, global_session_id, provider_template, &cmd,
            swarm_members, swarms_by_id, swarm_coordinators, swarm_plans,
            soft_interrupt_queues, coordinator_is_canary, spawn_model.clone(),
            spawn_provider_key.clone(), spawn_route_api_method.clone(),
            spawn_effort.clone(), Some(Arc::clone(mcp_pool)),
            Some(req_session_id.to_string()),
        )
        .await
        ...

This is reached whenever a visible (windowed) spawn isn't used or falls back, i.e. the default agents.swarm_spawn_mode = "inline" config, and likely headless mode too. There is no parameter distinguishing "this is a debug-socket admin create_session command" (debug_session_admin.rs, where isolated test storage is presumably intentional) from "this is a real swarm-spawned worker" (comm_session.rs, where it should use real memory scoped to the spawn's working dir).

Reproduce

  1. In an interactive session at directory D, write a project-scoped memory via the memory tool: action=remember, content="probe", scope="project". Confirm it's durably written to ~/.jcode/memory/projects/<hash-of-D>.json.

  2. From the same session, spawn a swarm agent in the same directory (swarm spawn, inline/headless mode, the default). From the spawned agent, run memory action=search query="probe" and memory action=list scope="all". Both return empty, despite the store containing the entry and ctx.working_dir correctly matching the parent session's directory (confirmed via swarm status).

  3. ~/.jcode/memory/test/ (not projects/<hash>.json) is where the spawned agent's writes/reads actually land, because test_mode: true short-circuits project_memory_path() before ctx.working_dir/with_project_dir is ever consulted.

Suggested fix

Thread an explicit flag (e.g. is_debug_admin_session: bool) through create_headless_session's callers so:

Related

Environment

  • macOS (aarch64), jcode v0.64.2 (6c6fbba) / master, agents.swarm_spawn_mode = "inline" (default).

Activity

  1. added a commit that references this issue on Aug 2, 2026
    3e85509
  2. 1jehuang commented on Aug 2, 2026

    @1jehuang
    Owner

    Confirmed and fixed. Thanks for taking the #720 follow-up seriously enough to find a genuinely separate bug.

    Verified the root cause exactly as you describe. What makes it especially clear is that enable_memory_test_mode's own doc comment says "Called when session is marked as debug", yet create_headless_session called it unconditionally, and that same function is the production path for real swarm workers. The comment describes the intended contract; the code had quietly stopped honouring it.

    Fix follows your suggestion: isolation is now an explicit parameter, set by each caller.

    • debug_session_admin.rs (debug-socket admin sessions): true, isolation is the point there.
    • comm_session.rs (real swarm spawns, i.e. the default inline mode and headless): false, so workers keep real project/global memory scoped to their working directory.

    Confirmed those are the only two callers, so the change is fully enumerated rather than a guess.

    You are right that this is distinct from #491 and #720: those fix working-dir scoping in paths that never reach this override, so neither would have helped here. #720 remains open and is a real bug on its own.

    Commit: 3e8550913, shipping in #727.

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

  3. added
    bug
    priority: high
    triage: reproducible
    autonomous: clear
    triage: fixed-pending-release
    recurring-theme
    on Aug 2, 2026
  4. 1jehuang commented on Aug 2, 2026

    @1jehuang
    Owner

    Follow-up: added a test that pins the invariant behind this bug, so the severity of the override stays visible.

    The test asserts that a MemoryManager in test mode cannot see real project memory even when handed the correct project directory, and that a non-test manager on that same directory does see it. That isolates the cause to test mode itself rather than to a bad path, which is the precise mechanism you identified: project_memory_path() short-circuits before the directory is ever consulted.

    That test passes, and the full memory suite is green at 82 tests.

    Together with the fix, the failure you reported can no longer happen silently: enabling test mode on a production path would now have to be an explicit decision at the call site, and its consequence is documented by a test rather than buried in a function whose doc comment said "called when session is marked as debug" while being called unconditionally.

    Commit: 3e8550913 (fix), f0df4784f (invariant test).

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

  5. 1jehuang commented on Aug 2, 2026

    @1jehuang
    Owner

    One more hardening pass on this, prompted by your point that the two call sites needed to be distinguishable.

    The isolation flag is no longer a bare bool. A boolean at a call site is one typo away from silently reintroducing exactly this bug, and the original defect had that shape: an unconditional call whose intent lived only in a comment on the function being called. The call sites now state their intent:

    comm_session.rs         HeadlessMemoryScope::RealProject
    debug_session_admin.rs  HeadlessMemoryScope::IsolatedTest

    So picking the wrong one is hard to do by accident and obvious in review, and the enum's own docs record why real swarm workers must never get throwaway storage.

    Combined with the invariant test from the previous comment, the failure you found is now guarded at three levels: the call sites name their choice, the enum documents the consequence, and a test proves test mode cannot see real project memory even with the correct working directory.

    Commits: 3e8550913 (fix), f0df4784f (invariant test), d3303bad6 (named choice).

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

  6. 11 remaining items

  7. added 4 commits that reference this issue on Sep 18, 2026
    06eaf5c
    3595f9a
    3f384a6
    71cd296
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: highrecurring-themetriage: fixed-pending-releasetriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions