1jehuang / 1jehuang/jcode

feat: Replace context compaction with a hybrid Mastra(Code) Observational Memory

Open
#901 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autonomous: no enhancement priority: medium triage: needs-decision
Dominant language
Rust
Stars
19.9k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
30

Description

Strategy (read this first)

Replace classic in-session compaction with a continuous observation + reflection loop (Mastra Observational Memory style), while keeping jcode’s long-term semantic memory graph unchanged.

  • What gets replaced: one-shot “summarize older turns” compaction for the active context window
  • What stays: the durable MemoryEntry graph (embeddings, cascade retrieval, supersedes/contradicts, ambient consolidation)
  • How they connect: a promotion bridge extracts durable facts from the session observation log into the existing graph

This is a hybrid: OM-style context for the current session, existing graph for cross-session knowledge. Not a rip-out of long-term memory.


Summary

jcode already has a strong long-term semantic memory graph (see MEMORY_ARCHITECTURE.md and AMBIENT_MODE.md).

In-session context still uses classic one-shot compaction (summarize older turns, keep recent tail). That works, but long single sessions can still hit the usual “lossy summary cliff.”

Proposal: replace that compaction path with a continuous observation + reflection style inspired by Mastra Observational Memory, and keep a clear bridge that promotes durable facts into the existing graph.

These layers solve different problems and are complementary.

Problem
Layer Current Gap
Long-term / cross-session Semantic memory graph Already strong
In-session context Classic compaction One-shot summaries can drop temporal detail, intermediate decisions, and priority signals
Proposed hybrid
  1. Session working context (replaces classic compaction)
    Maintain an append-mostly observation log (dated, priority-tagged notes) instead of a single compaction summary.
    Background Observer distills unobserved messages when a token threshold is hit; Reflector periodically condenses the log (merge, drop low-priority, keep high-value + temporal anchors).
    Design reference: Mastra OM / research results / implementation.

  2. Long-term graph (unchanged role)
    Existing MemoryEntry graph stays the durable store (Fact / Preference / Procedure / Correction, cascade retrieval, ambient garden).

  3. Promotion bridge
    During observation / reflection / ambient cycles, durable items are extracted into normal graph nodes (provenance Observed / Extracted). Transient session noise stays in the observation log and can decay under reflection.

  4. Prompt shape

    • Stable observation prefix (cache-friendly)
    • Recent unobserved messages
    • Graph memories still injected via existing passive recall

Full raw history remains available for session search / RAG, same as today.

Why this fits jcode
  • Fully async / non-blocking (reuse memory side-agent + ambient patterns)
  • No need for a new vector/graph DB for the session layer (text observation log)
  • Strengthens the existing graph with higher-quality, better-timed extractions
  • Optional / feature-flaggable; classic compaction can remain as emergency fallback
  • Aligns with current design docs: long-term graph vs in-session compaction are already separate concerns
Suggested phased approach
  1. Feature-flag observation log alongside current compaction
  2. Measure long-session coherence, token cost, cache behavior
  3. Add promotion rules into the graph
  4. Make observation-log the default compaction replacement; keep classic summary as hard fallback
References

Happy to refine the design or help prototype if this direction is interesting.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with docs/MEMORY_ARCHITECTURE.md and docs/AMBIENT_MODE.md, then compare the proposed session observation and reflection flow with the linked Mastra references. A complete implementation would preserve the existing durable memory graph, add the feature-flagged observation path and promotion bridge, and retain classic compaction as an emergency fallback.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
ai, cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.