feat(workspace): load workspace memory on demand, and show it in the memory tool

Merged
SA
3mo ago
+610-57

Summary

Closes the half of the read requirement that was never built: memory loaded at session start, but "on the user's demand" had no entry point at all, and the memory tool could not see workspace memory even when the model had been given it.

Both gaps were found by auditing the shipped code against the requirement, then confirmed live before being fixed — not assumed.

1. A session could never pick up newer memory

hydrate is idempotent for the life of a session — deliberately, so the per-turn injection stays cheap. But nothing ever reset it, and the CLI exposed no command to force a reload. A session started before a teammate (or this user on another machine) wrote a block never saw it, for its entire life.

Proven against a live backend: a running session re-hydrated and still could not see a block written after it started, while a brand-new session saw it immediately.

Adds refresh(sessionID) — drops the session's cached state (overlay, hydration promise and timed-out latch together) so the next hydrate genuinely refetches — exposed as a new altimate_memory_refresh tool. In an agentic CLI the natural "on demand" surface is the user asking; the agent calls the tool.

2. The memory tool disagreed with the prompt

altimate_memory_read read MemoryStore only, while injection merged the workspace overlay. A user asking "what do you remember?" was shown strictly less than the model actually had.

It now merges the same overlay, filtered to the requested scope. mergeOverlay is exported rather than duplicated, so the tool and the injection path cannot drift.

Verification

Live E2E (local backend + real mem0), with controls that fail on the old behaviour:

Check
session starts with the early block✅
(control) a block written mid-session reaches the workspace✅
(control) plain hydrate still cannot see it✅
refresh pulls it in✅
altimate_memory_read lists both the early and the late block✅

Mutation-checked — removing the state clear in refresh, or the merge in the read tool, each fails a test. The read-tool test drives the real tool through the initTool fixture rather than asserting on mergeOverlay directly, because the helper-level assertion passed even with the tool's merge deleted.

Suite: 11286 pass, typecheck clean. The two failures in the full run are unrelated and pre-existing — Truncate > cleanup fails identically at the merge-base, and the subprocess suite is load-flaky and passes 5/5 on its own.

Notes for review

  • Stacked on feat/workspace-memory.
  • No behaviour change when the pilot flag is off or the project is unlinked: refresh returns 0 and the tool reports that there is nothing to reload.
  • A refresh failure never fails the turn — the session keeps whatever it already had.

🤖 Generated with Claude Code

https://claude.ai/code/session_012wmN54fRA4WLgdVJVunaNk


Summary by cubic

Loads workspace memory on demand, shows it in the memory tool, and mirrors local memory to the bound workspace so users see what the model sees across machines. Before: sessions never picked up memory written after start and the read tool omitted workspace memory; after: refresh is safe and race‑proof, reads return the merged local + workspace view, and local saves sync to the workspace with backfill on bind.

  • New Features

    • Adds refresh(sessionID) with per‑session serialization and explicit outcomes; preserves prior memory on failure and never clears mid‑load.
    • Introduces the altimate_memory_refresh tool (gated by ALTIMATE_WORKSPACE) with clear user outcomes and no turn failures.
    • Updates altimate_memory_read to await hydration, merge the workspace overlay via exported mergeOverlay, include workspace‑only blocks on by‑id reads, return all scope matches, and apply expiry to overlay blocks.
    • Mirrors saves to the workspace, archives on local delete, and seeds existing local memory on bind; indexing prevents duplicates and is awaited by link.
  • Bug Fixes

    • Hydration and overlays are keyed per session and generation‑checked so stale loads cannot overwrite newer results.
    • Mirroring, archiving, and backfill resolve the binding and local‑existence check from the writing directory, preventing skipped writes and cross‑workspace attribution.
    • Writes are suppressed against truncated views; TTL is mirrored and enforced on read; sibling project training entries are labelled and remote blocks do not increment the applied counter.
    • No migration required; behavior remains gated by Altimate memory flags; writes fail closed on service errors, and reads distinguish disabled, unlinked, and unreachable workspaces.