Skip to content

Commit c7eb653

Browse files
committed
fix(extended-memory): transactional eviction and gofmt cleanup
- Move eviction after the ok check so atoms are only removed when the cap can be satisfied. - gofmt changed files in internal/memory/extended.
1 parent e9f319e commit c7eb653

5 files changed

Lines changed: 23 additions & 25 deletions

File tree

internal/memory/extended/config.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ import (
1616

1717
// Config controls the Extended Memory subsystem.
1818
type Config struct {
19-
Enabled *bool `json:"enabled,omitempty"`
20-
MaxSizeMB int `json:"max_size_mb,omitempty"`
21-
SemanticSearchTopK int `json:"semantic_search_top_k,omitempty"`
22-
SemanticSearchOverfetch int `json:"semantic_search_overfetch,omitempty"`
23-
SemanticSearchMinScore float32 `json:"semantic_search_min_score,omitempty"`
24-
SemanticSearchRerank *bool `json:"semantic_search_rerank,omitempty"`
25-
AtomMaxChars int `json:"atom_max_chars,omitempty"`
26-
MemoryBudgetChars int `json:"memory_budget_chars,omitempty"`
27-
DecayHalfLifeDays int `json:"decay_half_life_days,omitempty"`
28-
QuarantineTTLDays int `json:"quarantine_ttl_days,omitempty"`
29-
EvictionPolicy string `json:"eviction_policy,omitempty"`
30-
PredictiveIntents int `json:"predictive_intents,omitempty"`
31-
AutoExtractPerTurn *bool `json:"auto_extract_per_turn,omitempty"`
32-
InferUserState *bool `json:"infer_user_state,omitempty"`
33-
LLM *LLMConfig `json:"llm,omitempty"`
19+
Enabled *bool `json:"enabled,omitempty"`
20+
MaxSizeMB int `json:"max_size_mb,omitempty"`
21+
SemanticSearchTopK int `json:"semantic_search_top_k,omitempty"`
22+
SemanticSearchOverfetch int `json:"semantic_search_overfetch,omitempty"`
23+
SemanticSearchMinScore float32 `json:"semantic_search_min_score,omitempty"`
24+
SemanticSearchRerank *bool `json:"semantic_search_rerank,omitempty"`
25+
AtomMaxChars int `json:"atom_max_chars,omitempty"`
26+
MemoryBudgetChars int `json:"memory_budget_chars,omitempty"`
27+
DecayHalfLifeDays int `json:"decay_half_life_days,omitempty"`
28+
QuarantineTTLDays int `json:"quarantine_ttl_days,omitempty"`
29+
EvictionPolicy string `json:"eviction_policy,omitempty"`
30+
PredictiveIntents int `json:"predictive_intents,omitempty"`
31+
AutoExtractPerTurn *bool `json:"auto_extract_per_turn,omitempty"`
32+
InferUserState *bool `json:"infer_user_state,omitempty"`
33+
LLM *LLMConfig `json:"llm,omitempty"`
3434
Embedding *embedding.Config `json:"embedding,omitempty"`
3535
}
3636

internal/memory/extended/extended_memory.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ func (em *ExtendedMemory) enforceCap(ctx context.Context, newBytes int64) error
317317
need := total - maxBytes + 4096 // headroom
318318
before := len(atoms)
319319
ids, _, ok := em.evictor.SelectForEviction(sized, need)
320+
if !ok {
321+
return fmt.Errorf("extended memory: cannot free %s; all atoms are pinned or no evictable atoms exist", sizeLabel(need))
322+
}
320323
for _, id := range ids {
321324
_ = em.store.Remove(id)
322325
em.index.markDirty()
@@ -329,9 +332,6 @@ func (em *ExtendedMemory) enforceCap(ctx context.Context, newBytes int64) error
329332
}
330333
}
331334

332-
if !ok {
333-
return fmt.Errorf("extended memory: cannot free %s; all atoms are pinned or no evictable atoms exist", sizeLabel(need))
334-
}
335335
return nil
336336
}
337337

internal/memory/extended/extended_memory_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func TestExtendedMemoryAddAndSearch(t *testing.T) {
193193
}
194194

195195
atom := MemoryAtom{
196-
Text: "User prefers Go for backend services",
196+
Text: "User prefers Go for backend services",
197197
SourceClass: SourceUserSaid,
198198
Type: TypePreference,
199199
}
@@ -838,4 +838,3 @@ func TestAddAtomsBatchFailurePath(t *testing.T) {
838838
t.Errorf("expected 2 live atoms, got %d", len(live))
839839
}
840840
}
841-

internal/memory/extended/quarantine_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,3 @@ func TestQuarantineTTLDisabled(t *testing.T) {
112112
t.Errorf("expected 0 evicted with TTL disabled, got %d", removed)
113113
}
114114
}
115-

internal/memory/extended/recall.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212

1313
// Recall performs semantic search over the atom store.
1414
type Recall struct {
15-
store *AtomStore
16-
index *atomVectorIndex
17-
llm LLMClient
18-
cfg Config
15+
store *AtomStore
16+
index *atomVectorIndex
17+
llm LLMClient
18+
cfg Config
1919
}
2020

2121
// NewRecall creates a Recall instance.

0 commit comments

Comments
 (0)