Repository navigation
Description
Summary
Building MemoryManager without a project dir breaks project-scoped memory in two places:
- The
memorytool silently drops all project-scoped memories.remember(andtag/link) return success and emittool_rememberedevents, but nothing is written to the store on disk, andlist/search/recall/relatedalways returnNo memories stored.even when project memory files already exist under~/.jcode/memory/projects/. - The TUI memory chip always shows
0 memoriesfor the project scope even when that store file holds entries, because the counter path (gather_memory_info_inner) also builds an unscopedMemoryManager. Global count is unaffected.
Reproduce (on master)
From any project directory, via the agent's memory tool:
{"action":"remember","content":"probe","scope":"project"}-> returnsRemembered fact (project): "probe" [id: mem_...]{"action":"list","scope":"project"}-> returnsNo memories stored.~/.jcode/memory/projects/*.jsonis unchanged, but~/.jcode/logs/memory/memory-events-*.jsonlhas a matchingtool_rememberedentry.
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_graphis guarded byif let Some(path) = self.project_memory_path()?and silently no-ops on write (memory.rs:1779).load_project_graphreturns an emptyMemoryGraph::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 isolatedJCODE_HOME. - registry-level e2e through
Registry::executeusing the real (non-test-mode) memory tool, which additionally covers thectx.working_dirplumbing.
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(respectingJCODE_HOME).
Activity
hoangdq08 commentedon Jul 17, 2026
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_innerbuilt an unscopedMemoryManager).master: master...hoangdq08:jcode:fix/memory-tool-project-scopeBoth tests fail on
masterwithNo memories stored.and pass with the fix:tool::memory::tests::project_memory_round_trips_with_working_dir(tool level, viaMemoryTool::execute)tool::tests::registry_memory_tool_persists_project_scope_via_working_dir(registry level, via the real non-test-mode tool throughRegistry::execute, covering thectx.working_dirplumbing)I verified the regression both ways by temporarily reverting the scoping (manager ignores
ctx.working_dir), which reproducesNo memories stored.at both layers. The TUI chip fix is render-path code (no unit test); verified withcargo build -p jcode-tuiplus a check thatPathBufhashing of the session working dir matches the tool'sctx.working_dir, so the chip and tool resolve the same store file.hunxjunedo commentedon Jul 17, 2026
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.
fix(memory): scope memory tool and TUI chip to the session working dir
1jehuang commentedon Jul 18, 2026
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
fix(swarm): spawned workers keep real memory instead of test storage (f…
chore: sync fork with upstream (224 behind), preserve fork commits (#2)
fix(memory): scope memory tool and TUI chip to the session working dir
fix(swarm): spawned workers keep real memory instead of test storage (f…
fix(swarm): spawned workers keep real memory instead of test storage (f…
fix(memory): scope memory tool and TUI chip to the session working dir
fix(swarm): spawned workers keep real memory instead of test storage (f…
fix(swarm): spawned workers keep real memory instead of test storage (f…
fix(swarm): spawned workers keep real memory instead of test storage (f…
fix(swarm): spawned workers keep real memory instead of test storage (f…
fix(memory): scope memory tool and TUI chip to the session working dir