Skip to content

memory tool silently drops all project-scoped memories (remember acks, list/search return empty) #491

Closed

Description

@hoangdq08

Summary

Building MemoryManager without a project dir breaks project-scoped memory in two places:

  1. The memory tool silently drops all project-scoped memories. remember (and tag/link) return success and emit tool_remembered events, but nothing is written to the store on disk, and list/search/recall/related always return No memories stored. even when project memory files already exist under ~/.jcode/memory/projects/.
  2. The TUI memory chip always shows 0 memories for the project scope even when that store file holds entries, because the counter path (gather_memory_info_inner) also builds an unscoped MemoryManager. Global count is unaffected.

Reproduce (on master)

From any project directory, via the agent's memory tool:

  1. {"action":"remember","content":"probe","scope":"project"} -> returns Remembered fact (project): "probe" [id: mem_...]
  2. {"action":"list","scope":"project"} -> returns No memories stored.
  3. ~/.jcode/memory/projects/*.json is unchanged, but ~/.jcode/logs/memory/memory-events-*.jsonl has a matching tool_remembered entry.

Expected: step 2 lists the memory written in step 1.
Actual: the write is acknowledged but never persisted; reads come back empty (split-brain between the event log and the store).

Global scope ("scope":"global") is not affected.

Root cause

MemoryTool builds its MemoryManager once in MemoryTool::new() and never adopts the per-call working directory:

// crates/jcode-app-core/src/tool/memory.rs:15-19
pub fn new() -> Self {
    Self { manager: MemoryManager::new() }
}

MemoryManager::new() sets project_dir: None (crates/jcode-base/src/memory.rs:199). The runtime does populate ctx.working_dir (ctx.working_dir set in execute_tool, crates/jcode-app-core/src/agent/turn_execution.rs:473, and forwarded unchanged by Registry::execute, crates/jcode-app-core/src/tool/mod.rs:609), but the tool ignores it.

With project_dir == None, project_memory_path() returns None (memory.rs:260-263), so:

  • save_project_graph is guarded by if let Some(path) = self.project_memory_path()? and silently no-ops on write (memory.rs:1779).
  • load_project_graph returns an empty MemoryGraph::new() on read (memory.rs:1659-1661).

Why this slipped past tests

enable_memory_test_mode swaps in MemoryTool::new_test() (tool/mod.rs:355-357), and new_test() sets test_mode = true, which makes project_memory_path() return Some(<test dir>) unconditionally (memory.rs:254-257). So the debug/test path always has a valid project path and never exercises the project_dir == None branch that the real MemoryTool::new() hits.

Suggested direction (not prescriptive)

Scope the manager to the working dir per call. The exact pattern already exists in manager_for_working_dir (crates/jcode-base/src/memory_agent.rs:161-165), which uses .with_project_dir(dir) (with an empty-path guard). Both the memory tool and the TUI chip's gather_memory_info_inner (crates/jcode-tui/src/tui/app/helpers.rs) just never adopted it. For the chip, the session working dir is already available as App::working_dir (crates/jcode-tui/src/tui/app/tui_state.rs) and produces the same PathBuf hash as the tool's ctx.working_dir, so scoping the chip resolves the identical projects/<hash>.json file.

Failing tests (repro / regression)

I have two tests that fail on master and pass once the tool is scoped to ctx.working_dir:

  • tool-level round-trip through MemoryTool::execute (remember project -> list project reads it back), under an isolated JCODE_HOME.
  • registry-level e2e through Registry::execute using the real (non-test-mode) memory tool, which additionally covers the ctx.working_dir plumbing.

Both fail on master with No memories stored. and pass with the working-dir scoping applied. Happy to attach them (or a reference branch) if useful.

Environment

  • macOS (aarch64), built from master.
  • Storage root ~/.jcode (respecting JCODE_HOME).

Activity

  1. hoangdq08 commented on Jul 17, 2026

    @hoangdq08
    Author

    Reference branch with the two failing tests and a candidate fix (working-dir scoping, mirroring manager_for_working_dir), for repro convenience. Not opened as a PR per the contributing guidelines, just a reference. The branch now also fixes the TUI memory chip (same root cause: gather_memory_info_inner built an unscoped MemoryManager).

    Both tests fail on master with No memories stored. and pass with the fix:

    • tool::memory::tests::project_memory_round_trips_with_working_dir (tool level, via MemoryTool::execute)
    • tool::tests::registry_memory_tool_persists_project_scope_via_working_dir (registry level, via the real non-test-mode tool through Registry::execute, covering the ctx.working_dir plumbing)

    I verified the regression both ways by temporarily reverting the scoping (manager ignores ctx.working_dir), which reproduces No memories stored. at both layers. The TUI chip fix is render-path code (no unit test); verified with cargo build -p jcode-tui plus a check that PathBuf hashing of the session working dir matches the tool's ctx.working_dir, so the chip and tool resolve the same store file.

  2. hunxjunedo commented on Jul 17, 2026

    @hunxjunedo

    hey @FabianAmherd, I'd like to work on this one. I'm confident this will be a cool and interesting issue to solve. Please Assign.

  3. added a commit that references this issue on Jul 18, 2026
    45cabd6
  4. 1jehuang commented on Jul 18, 2026

    @1jehuang
    Owner

    Fixed in 45cabd6 (auto-closed): the memory tool now scopes its MemoryManager to ctx.working_dir per call, and the TUI memory chip counter scopes to the session working dir, so both resolve the same projects/.json store. Added a non-test-mode round-trip regression test (remember project -> list project) that fails on the old code. Great diagnosis, the writeup made this a fast fix. Ships in the next release.

    — Jcode agent

  5. added 7 commits that reference this issue on Aug 30, 2026
    fd9cd76
    62367c3
    50fe8c7
    2112b5b
    96c96be
    f31cc80
    d2d95c0
  6. added a commit that references this issue on Sep 18, 2026
    ef9acf3
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions