Skip to content

feat(memory-v3): live shadow via memoryRetrieval middleware (inject v2, log v3)#31989

Merged
velissa-ai merged 1 commit into
velissa-ai/memory-v3-buildfrom
run-plan/memory-v3/pr-15
May 25, 2026
Merged

feat(memory-v3): live shadow via memoryRetrieval middleware (inject v2, log v3)#31989
velissa-ai merged 1 commit into
velissa-ai/memory-v3-buildfrom
run-plan/memory-v3/pr-15

Conversation

@velissa-ai
Copy link
Copy Markdown
Collaborator

Summary

  • Register a memoryRetrieval middleware that, only when config.memory.v3.enabled && shadow, runs the v3 loop alongside v2, logs v3 selections as mode='v3_shadow', and returns the v2 result unchanged (inject v2 only), off the critical path.
  • Flag-off (default) is a byte-for-byte pass-through; no DB migration (reuses the activation-log table with a new mode value).

Note: post-compaction reinjection (reinjectCachedMemory in conversation-graph-memory.ts, called directly from the overflow-reducer reinjectForMode callback in conversation-agent-loop.ts ~L2058) bypasses the memoryRetrieval pipeline, so the shadow does not cover it. Per the plan this is left as-is (no scope expansion); the shadow covers per-turn and context-load retrieval, which both flow through the pipeline.

Part of plan: memory-v3-build.md (PR 15 of 19)

@velissa-ai velissa-ai merged commit 93da857 into velissa-ai/memory-v3-build May 25, 2026
@velissa-ai velissa-ai deleted the run-plan/memory-v3/pr-15 branch May 25, 2026 07:33
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8042e34a07

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Detached — never awaited on the path that returns the result, so the
// shadow can neither block nor slow the live turn. Errors are swallowed
// inside `runShadowAndLog`.
void runShadowAndLog(args, args.signal);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep shadow logs on the same turn’s message backfill

Do not fire the shadow write fully detached without turn-scoped backfill plumbing: runShadowAndLog inserts memory_v2_activation_logs rows with messageId = null, and backfillMemoryV2ActivationMessageId later links all null rows for the conversation to whichever assistant message is finishing. Because this call is detached, a slow shadow run can miss its own turn’s backfill and then get linked to a later turn’s message, corrupting per-turn inspector/analysis attribution.

Useful? React with 👍 / 👎.

export const memoryV3ShadowMiddleware: Middleware<MemoryArgs, MemoryResult> =
async function memoryV3Shadow(args, next) {
const v3 = getConfig().memory.v3;
if (!v3.enabled || !v3.shadow) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Skip v3 shadow retrieval for untrusted actors

Add the same trust gate used by default memory retrieval before launching shadow work. Right now the middleware only checks feature flags, so when v3.shadow is enabled it will run v3 retrieval/logging even for non-guardian turns that the default path intentionally excludes from memory-graph retrieval. This changes behavior for untrusted channels and can leak memory-processing side effects/cost into requests that should bypass memory retrieval.

Useful? React with 👍 / 👎.

velissa-ai added a commit that referenced this pull request May 25, 2026
#31990)

* feat(memory-v3): tree-node on-disk format + node store (#31971)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): config schema + cheap/capable LLM call sites (#31972)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): curated edge-expansion lane (#31973)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): write-path job types + config (no behavior) (#31974)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): gate decision (ready/more) + final selection (#31975)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): tree index with DAG adjacency + cache (#31976)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): always-on scouts over the v2 substrate (#31977)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): compose node index from children + routing hints (#31978)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): fast filter judging dense hits (sticky bypass) (#31979)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): parallel-fan-out traversal with cycle/visited guards (#31980)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): tree validator (orphans, cycles, dangling refs, freshness) (#31981)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): scout-seeded tree-walk descent driver (#31982)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): assistant memory v3 validate/tree CLI + routes (#31983)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): retrieval loop (scouts->filter->tree->edges->gate) (#31984)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): consolidation drains shared buffer into tree + maintains standing-context files (#31985)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): v3 Retriever as comparand #2 in the compare harness (#31986)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): pass-1->pass-2 co-activation logging (#31987)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): weighted, decaying auto-edge learning job (#31988)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* feat(memory-v3): live shadow via memoryRetrieval middleware (inject v2, log v3) (#31989)

Co-authored-by: Vellum Assistant <assistant@vellum.ai>

* fix(memory-v3): null-safe shadow gate when memory.v3 config is absent

The live-shadow middleware runs on every turn and read `config.memory.v3.enabled`
unguarded. Configs built outside the Zod schema (agent-loop test fixtures) have no
`memory.v3` block, so the gate threw `TypeError: undefined is not an object` and
aborted the turn — cascading across ~13 agent-loop test files. Guard with optional
chaining (matches the loop's existing `write?.coactivation` pattern) and add a
regression test for the absent-v3 config.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(memory-v3): add route policies for memory/v3/validate + tree

PR #31983 registered the two read-only v3 routes but never added their
ACTOR_ENDPOINTS entries in route-policy.ts; the per-PR run skipped CI so the
route-policy coverage guard never ran. Add both as settings.read (mirroring the
v2 read routes), satisfying guard-tests.test.ts.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Vellum Assistant <assistant@vellum.ai>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant