Skip to content

Commit 0c55f54

Browse files
authored
Merge pull request #567 from spacedriveapp/codex/land-memory-observation-p2
feat(memory): expand working-memory event semantics
2 parents af83922 + 4dabbe3 commit 0c55f54

12 files changed

Lines changed: 1205 additions & 177 deletions

docs/design-docs/working-memory-implementation-plan.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ pub enum WorkingMemoryEventType {
158158
CronExecuted,
159159
MemorySaved,
160160
Decision,
161+
UserCorrection,
162+
DecisionRevised,
163+
DeadlineSet,
164+
BlockedOn,
165+
Constraint,
166+
Outcome,
161167
Error,
162168
TaskUpdate,
163169
AgentMessage,
@@ -861,7 +867,8 @@ Update `prompts/en/memory_persistence.md.j2` to add:
861867
In addition to saving graph memories, identify key decisions and important events
862868
from the conversation. For each, include it in the `events` field of
863869
memory_persistence_complete. Events should be one-line summaries with a type
864-
("decision", "error", "system") and importance score (0.0-1.0).
870+
("decision", "user_correction", "decision_revised", "deadline_set", "blocked_on",
871+
"constraint", "outcome", "error", "system") and importance score (0.0-1.0).
865872
```
866873

867874
Update `src/tools/memory_persistence_complete.rs`:

docs/design-docs/working-memory.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ pub enum WorkingMemoryEventType {
7575
MemorySaved,
7676
/// A decision was made (extracted from conversation)
7777
Decision,
78+
/// The user corrected a prior assumption, instruction, or framing
79+
UserCorrection,
80+
/// A prior decision changed after feedback or new information
81+
DecisionRevised,
82+
/// A concrete due date, deadline, or scheduled milestone was set
83+
DeadlineSet,
84+
/// Progress is waiting on approval, missing input, or an external dependency
85+
BlockedOn,
86+
/// A hard requirement, limitation, or non-negotiable boundary was stated
87+
Constraint,
88+
/// A task, branch, or delegated step reached a clear terminal result
89+
Outcome,
7890
/// An error or failure occurred
7991
Error,
8092
/// A task was created or updated
@@ -455,19 +467,19 @@ The periodic memory persistence branch currently runs every 50 user messages. Re
455467

456468
### Persistence Branch Dual Output
457469

458-
The memory persistence branch gains a second responsibility: in addition to saving graph memories, it emits `Decision` and `MemorySaved` events into the working memory log. This connects the two systems:
470+
The memory persistence branch gains a second responsibility: in addition to saving graph memories, it emits typed conversational events into the working memory log. This connects the two systems:
459471

460472
```
461473
Persistence branch runs:
462474
1. Recalls existing graph memories (avoid duplicates)
463475
2. Reads conversation history since last run
464476
3. Saves new graph memories via memory_save (as today)
465477
4. Identifies key decisions and events
466-
5. Emits working memory events for each decision identified
478+
5. Emits working memory events for each important event identified
467479
6. Calls memory_persistence_complete
468480
```
469481

470-
Step 5 is new. The persistence branch prompt is updated to instruct it to identify decisions explicitly. The `memory_persistence_complete` tool gains an optional `events` field:
482+
Step 5 is new. The persistence branch prompt is updated to identify durable temporal events explicitly: decisions, user corrections, revised decisions, concrete deadlines, blockers, constraints, terminal outcomes, errors, and system events. The `memory_persistence_complete` tool gains an optional `events` field:
471483

472484
```rust
473485
pub struct MemoryPersistenceCompleteArgs {
@@ -477,7 +489,7 @@ pub struct MemoryPersistenceCompleteArgs {
477489
}
478490

479491
pub struct WorkingMemoryEventInput {
480-
pub event_type: String, // "decision", "error", etc.
492+
pub event_type: String, // "decision", "blocked_on", "outcome", etc.
481493
pub summary: String,
482494
pub importance: Option<f32>,
483495
}
@@ -490,14 +502,18 @@ The majority of working memory events are captured programmatically, with zero L
490502
| Event | Emitter | How |
491503
| ---------------- | -------------------------------------------- | -------------------------------------------------------------------- |
492504
| Worker spawned | `spawn_worker` tool handler | After successful spawn, write event with task description as summary |
493-
| Worker completed | Worker state machine terminal transition | Write event with worker result summary (truncated to 200 chars) |
494-
| Branch completed | Branch return path in channel | Write event with branch conclusion (truncated to 200 chars) |
505+
| Worker completed | Worker state machine terminal transition | Write typed result, blocker, constraint, or deadline event when the summary uses a recognized prefix; otherwise write `WorkerCompleted` |
506+
| Branch completed | Branch return path in channel | Write typed result, blocker, constraint, or deadline event when the summary uses a recognized prefix; otherwise write `BranchCompleted` |
495507
| Cron executed | Cron scheduler after job completes | Write event with cron name + outcome |
496508
| Memory saved | `memory_save` tool handler | Write event with memory type + content preview |
497-
| Task updated | Task tool handlers | Write event with task title + new status |
509+
| Task updated | Task tool handlers | Write `Outcome` when a task transitions to `done`; otherwise write `TaskUpdate` with task status |
510+
| Duplicate worker | `spawn_worker` duplicate guard | Write `BlockedOn` with the active worker ID and duplicate task preview |
511+
| Agent delegation | `send_agent_message` tool handler | Write `Outcome` when delegation creates the cross-agent task |
498512
| Error | SpacebotHook on tool failure, worker failure | Write event with error description |
499513
| System | Startup, config change, maintenance | Write event with description |
500514

515+
Branch and worker summaries may opt into richer event types with these prefixes: `outcome:`, `blocked_on:` or `blocked on:`, `constraint:`, and `deadline_set:` or `deadline:`. The prefix is stripped before rendering the event summary.
516+
501517
Each emitter calls `working_memory_store.record_event()` as a fire-and-forget `tokio::spawn`. The message processing pipeline never waits on event recording.
502518

503519
```rust

prompts/en/memory_persistence.md.j2

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ This is an automatic process triggered periodically during conversation. You are
3232
- `"decision"` for commitments or choices made
3333
- `"user_correction"` when the user corrects a prior assumption, instruction, or framing
3434
- `"decision_revised"` when a prior choice changes after feedback or new information
35+
- `"deadline_set"` when the conversation establishes a concrete due date, deadline, or scheduled milestone
36+
- `"blocked_on"` when progress is waiting on an approval, dependency, missing input, or external action
37+
- `"constraint"` when the user or system states a hard requirement, limitation, or non-negotiable boundary
38+
- `"outcome"` when a task, branch, or delegated step reaches a clear terminal result worth retaining in temporal memory
3539
- `"error"` for failures or problems
3640
- `"system"` for other notable events
3741
- `summary`: one-line description of what happened
3842
- Normalize relative time references to absolute dates/times with timezone
3943
(for example `2026-03-31T14:20:00-04:00`) so downstream memory checks are
4044
stable across sessions.
41-
- `importance`: 0.0-1.0 score (`decision`, `user_correction`, and `decision_revised` are typically 0.6-0.8)
45+
- `importance`: 0.0-1.0 score (`decision`, `user_correction`, `decision_revised`, `blocked_on`, and `outcome` are typically 0.6-0.8)
4246
- Events feed the agent's temporal working memory — they help the agent remember *what happened today*, not just facts.
4347

4448
5. **Finish with the terminal tool.** You must call `memory_persistence_complete` before finishing:

0 commit comments

Comments
 (0)