Skip to content

feat(memory): LLM-maintained fact files — cap errors, stats, eviction policy (M1-M4) - #162

Merged
jkyberneees merged 1 commit into
mainfrom
feat/memory-auto-eviction
Aug 30, 2026
Merged

feat(memory): LLM-maintained fact files — cap errors, stats, eviction policy (M1-M4)#162
jkyberneees merged 1 commit into
mainfrom
feat/memory-auto-eviction

Conversation

@jkyberneees

Copy link
Copy Markdown
Contributor

What

Makes fact-file memory self-maintaining by the agent: when a file fills, the agent evicts older entries itself — judgment stays in the ReAct loop, and every eviction is an explicit, auditable memory remove/replace call.

  • M1 — decision-ready cap errors (facts.go): cap failures in Add/Replace/ReplaceAt carry the full entry index ([n] size "rune-safe preview") + explicit memory remove/replace guidance, so the agent evicts without an extra read round-trip.
  • M2 — stats action (tool.go): memory(action:"stats", target:"env"){used, cap, entries:[{index, chars, preview}]} as a pre-flight fill check. view stays episodes-only (provenance gate).
  • M3 — eviction policy (tool.go): the tool description codifies the contract — git/GitHub-recoverable records evict first, pointers to untracked local work evict last.
  • M4 — near-cap hint (memory.go): the system-prompt memory block appends a one-line ⚠ env fact file NN% full — evict stale entries via memory remove only at ≥90% fill.
  • Docs: new "Automatic Cap Maintenance" section in docs/MEMORY.md.

Deliberately not built

  • No auto-consolidation on write — mid-flow LLM rewrites risk dropping load-bearing details and amplify provider throttling.
  • No date-based auto-eviction — age ≠ value; a days-old pointer to untracked work can be the only durable record of it.

Tests

RED-first: 9 tests in internal/memory/auto_eviction_test.go (cap-error index incl. the 4-byte § separator byte accounting, stats guards, rune-safe previews, hint threshold pinning). Verified: go test -race -count=1 ./internal/memory/... green, go build ./... clean, filtered cmd/odek Memory tests green, gofmt/vet clean.

… policy (M1-M4)

- M1: cap errors in Add/Replace/ReplaceAt carry the entry index
  (index, byte size, rune-safe preview) + remove/replace guidance,
  so the agent can evict without an extra read
- M2: new memory stats action — per-entry sizes + used/cap fill
- M3: tool description codifies the eviction policy (git/GitHub-
  recoverable records evict first, untracked-work pointers last)
- M4: system-prompt memory block warns at >=90% file fill
- docs/MEMORY.md: Automatic Cap Maintenance section

RED-first: auto_eviction_test.go (9 tests). Scoped -race green.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
odek 2963323 Commit Preview URL

Branch Preview URL
Aug 30 2026, 07:32 PM

@jkyberneees
jkyberneees merged commit a9c7d15 into main Aug 30, 2026
10 checks passed
@jkyberneees
jkyberneees deleted the feat/memory-auto-eviction branch August 30, 2026 19:36
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