Dream: The Real Mechanism
Verifying idle gating, DreamLock, background tidying, and the actual boundaries of memory write-back
THE QUESTION THIS PAGE ANSWERS
ANSWER FIRSTWhat is the key idea behind “Dream: The Real Mechanism”?
Verifying idle gating, DreamLock, background tidying, and the actual boundaries of memory write-back
Make the claim earn its place. Use this page as a decision aid, not a definition to memorize. Connect the idea to one real task, one observable result, and one failure that would change your mind.
Write one question you could answer with evidence after trying this idea.
A conclusion that sounds complete but leaves the key assumption untested.
Understand the complete chain from Dream's trigger to index rebuild, and explain what problems DreamGate, idempotency requirements, lock contention, and write-failure rollback each solve.
Dream State Machine
The diagram below is a teaching visualization. Node names come from the source code; layout and labels have been reorganized for instructional clarity.
1. Config Gate
MemoryDreamConfig.enabled defaults to true. Sub-Agent sessions skip Dream entirely.
2. Time Gate
min_hours defaults to 4. The lock file mtime records the last successful consolidation time.
3. Session Gate
min_sessions defaults to 3. Counts session Markdowns modified since the last consolidation, excluding the current session.
DreamLock is Best-Effort Coordination
.dream-lock stores the PID and uses mtime as the last-success timestamp. Returns Ok(None) while a live process holds a non-expired lock. Dead processes or stale locks can be reclaimed.
Source code comments explicitly note it is not strictly mutual-exclusive. Read-after-write reduces contention probability, but two processes can still both believe they won, so Dream must tolerate duplicate consolidations.
Success Boundary Defines Cleanup Boundary
- If the model returns empty, NO_REPLY, or no Markdown heading, nothing is written and no session is deleted.
- If writing MEMORY.md fails, rollback(prior) restores the old lock state.
- Sessions are cleaned only after a successful write; files still active within 5 minutes are skipped.
- The search index only removes actually deleted paths, then rebuilds the index and embedding for the new MEMORY.md.
pub fn check_dream_gates(
config: &MemoryDreamConfig,
lock: &DreamLock,
sessions_dir: &Path,
current_session_sid8: Option<&str>,
) -> DreamGate {
if !config.enabled { return DreamGate::Disabled; }
// Time gate, then session gate
...
DreamGate::Open { sessions }
}
Snapshot note: Code retains the real function signature and return type; the intermediate implementation is compressed with ellipsis. The state machine SVG in this page is a teaching visualization, not an architecture diagram generated from the repository.
Classroom Exercise: Locate System State After Failure
Scenario: Dream has completed the model call, but writing to MEMORY.md has failed. Answer: what state should the lock file be restored to? Which session files can be deleted? Does the index need updating? Provide evidence from the branches of execute_dream.
Why “Dream State Machine” can find relevant content
“Understand the complete chain from Dream's trigger to index rebuild, and explain what problems DreamGate , idempotency requirements, lock contention, and write-failure rollback eac…” moves retrieval beyond storing material: the real question is how to find what is relevant. That decision shapes the input quality of RAG, recommendation, and image-search systems.
Similarity is not the answer
In the flow described by “The diagram below is a teaching visualization.”, embeddings place items in a comparable semantic space and a neighbor index narrows the search. The final answer still depends on whether the retrieved chunks cover the question, whether the distance metric fits, and whether the evidence is current.
- If the model returns empty, NO_REPLY, or no Markdown heading, nothing is written and no session is deleted
- If writing MEMORY.md fails, rollback(prior) restores the old lock state
- Sessions are cleaned only after a successful write; files still active within 5 minutes are skipped
Separate findable from relevant
Turn “Scenario: Dream has completed the model call, but writing to MEMORY.md has failed.” into a small test: prepare queries with known answers, record relevance, misses, and distractors, then decide whether chunking, the index, or reranking needs to change.
From “Dream State Machine” to “1. Config Gate”
“Dream State Machine” grounds the problem in “The diagram below is a teaching visualization. Node names come from the source code; layout and labels have been reorganized for instructional clarity”. “1. Config Gate” then moves it toward “MemoryDreamConfig.enabled defaults to true. Sub-Agent sessions skip Dream entirely”. Together, they show that the lesson is not just a conclusion to remember, but a claim with conditions.
Carry the judgment into the next situation
The same logic applies to retrieval: define what counts as relevant, check whether recall covers the question, and then inspect whether ranking, chunking, or freshness pushed useful evidence out.
- “Dream State Machine”: The diagram below is a teaching visualization. Node names come from the source code; layout and labels have been reorganized for instructional clarity
- “1. Config Gate”: MemoryDreamConfig.enabled defaults to true. Sub-Agent sessions skip Dream entirely
- “The closing point”: The search index only removes actually deleted paths, then rebuilds the index and embedding for the new MEMORY.md
The final “The closing point” brings the discussion to “The search index only removes actually deleted paths, then rebuilds the index and embedding for the new MEMORY.md”. The useful thing to carry forward is knowing which judgments must be revisited when input, scale, or risk changes.
I turned one judgment from this article into a small experiment I could run today. Knowing what to observe next is more useful than simply remembering the conclusion.
After reading this, I first looked for the conditions behind the idea instead of copying the method into a project. That order made the later trade-offs much clearer.
When this judgment reaches real work, which constraint should be added first? I am curious which step matters most between reading and the first practical attempt.
No discussion on this article yet.