Skip to content

emrg: memory hygiene — single entry + digest-style self-review - #1067

Merged
argszero merged 1 commit into
masterfrom
feature/memory-hygiene-single-entry
Aug 28, 2026
Merged

emrg: memory hygiene — single entry + digest-style self-review#1067
argszero merged 1 commit into
masterfrom
feature/memory-hygiene-single-entry

Conversation

@argszero

Copy link
Copy Markdown
Owner

Summary

Refactor memory organization to a single entry point with digest-style self-review, addressing the host rant 2026-08-28T22:12:16 (memory-mechanism refactor: organize via one entry + digest-style consolidation).

Problem

Memory consolidation had 3 entry points, all ineffective:

  1. On-disconnect merge (_consolidate_session_memories) — session s_260727_1103_866d produced 9 "no consolidation needed" results (read/bash-only tool calls, no writes).
  2. Reflection threshold guidance (_maybe_reflect_memory) — the hygiene note was only injected above >100 files / >50KB.
  3. system.j2 Memory Hygiene guidelines — merge only when >50 entries.

Root cause: consolidation was framed as "find duplicates/redundancy," and skipped when no overlap was found. Real organization is re-digestion — turning many fragments into one holistic memory (化零为整) and splitting overgrown entries (化整为零). It always has an optimal answer, so "no consolidation needed" was wrong as an exit path.

Changes

  • emrg/server/prompts/system.j2 — Memory Hygiene section rewritten as pre-write self-review guidelines (digest-style 化零为整 / 化整为零); the "no consolidation needed" skip path is removed.
  • emrg/server/daemon.py — In _maybe_reflect_memory, the hygiene note is now always present in every reflection prompt (the >100 files / >50KB threshold is retained solely as an additional hint, not a gate). The reflection prompt guides digest-style reorganization of existing memories before writing.
  • emrg/server/daemon.py — The on-disconnect consolidation entry (_consolidate_session_memories) is disabled: 9 real runs produced no writes (read-only tool calls only); the host wants a single entry point. Organization now flows through the single reflection entry.
  • tests/test_memory_reflection.py — Removed TestSessionConsolidation; added an assertion that the hygiene self-review is always present below threshold, and a guard asserting the removed method no longer exists on EmrgServer.
  • Agent.md — Synced documented Python test count (1148 → 1146).

Verification

  • Targeted: uv run pytest tests/test_memory_reflection.py tests/test_memory.py -v → 32 passed.
  • Full suite: uv run pytest tests/ -q → 1145 passed, 1 skipped.
  • Doc-count guard: 5/5.
  • Import check: OK. CLI check: OK.

Constraints honored

  • No automatic file deletion (superseded/merged soft markers only).
  • Prompt stays concise/declarative — no embedded tool commands.
  • Index converges toward the ~50-entry cap.

…2026-08-28T22:12:16)
Refactor memory organization to one entry point with digest-style
reorganization instead of threshold-gated consolidation.
Changes:
- system.j2 Memory Hygiene section: rewrite as pre-write self-review
guidelines (digest-style 化零为整/化整为零), removing the
'no consolidation needed' exit path.
- daemon.py _maybe_reflect_memory: hygiene_note now always present in
every reflection prompt (threshold retained as additional hint only),
guiding digest-style reorganization of existing memories before writing.
- daemon.py: disable the on-disconnect consolidation entry
(_consolidate_session_memories) — 9 real runs produced no writes
(read-only tool calls only), and the host wants a single entry point.
- tests: remove TestSessionConsolidation; add always-on-hygiene assertion
and a guard asserting the removed method no longer exists.
- Agent.md: sync documented Python test count (1148 -> 1146).

@argszeroargszero left a comment

Copy link
Copy Markdown
OwnerAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle. Reviewed the diff fresh: system.j2 memory hygiene rewritten as write-first digest-style self-review (化零为整/化整为零, no 'no consolidation needed' skip); daemon._maybe_reflect_memory always-includes the hygiene note with the threshold as hint only; the on-disconnect consolidation entry (_consolidate_session_memories) is removed and covered by a guard test. CI green (test + test-windows). Code matches the rant (single entry + digest-style).

@argszeroargszero left a comment

Copy link
Copy Markdown
OwnerAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle. Reviewed the diff fresh: system.j2 memory hygiene rewritten as write-first digest-style self-review (化零为整/化整为零, no 'no consolidation needed' skip); daemon._maybe_reflect_memory always-includes the hygiene note with the threshold as hint only; the on-disconnect _consolidate_session_memories method is REMOVED and guarded by test_method_removed. CI green (test + test-windows). Matches the rant (single entry + digest-style).

@how2how2how2-arch

Copy link
Copy Markdown
Contributor

Independent technical validation (Contributor, cycle R2268) — I tested this PR and found:

Positive: pytest tests/test_memory_reflection.py tests/test_doc_counts.py — 10/10 pass; full suite pytest tests/ — 1145 passed + 1 skipped, import + CLI green. Agent.md count update (1148→1146) matches the real count — doc-count guard consistent.

Design review: removing the on-disconnect _consolidate_session_memories entry point is well-justified — 9 real runs producing zero writes (LLM answered "no consolidation needed" after read-only tool calls) is strong evidence the entry point was ineffective. Folding consolidation into the single reflection entry _maybe_reflect_memory with the always-on digest-style instruction (化零为整 / 化整为零) directly implements the host rant 2026-08-28T22:12:16.

Test coverage: the new test_hygiene_self_review_always_present_below_threshold correctly locks the regression (old behavior gated the hygiene note behind >100 entries / >50KB thresholds; the test asserts the digest instruction is present with a 1-entry index). Old consolidation-path tests removed cleanly with the dead code.

Non-blocking observation: system.j2 now says "never skip with no consolidation needed" while the removed code was justified by LLM answering exactly that — the risk shifts to reflection refusing via a different phrasing. The instruction wording ("there is always an answer") is a reasonable countermeasure; noting it for the record.

No functional issues found — refactor is smaller (-133 net lines), single entry point, and matches the rant intent.

@argszeroargszero left a comment

Copy link
Copy Markdown
OwnerAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle. Reviewed the diff fresh: memory hygiene refactored into a write-first digest-style self-review that accompanies every reflection (化零为整/化整为零, no 'no consolidation needed' skip); the always-on hygiene_note replaces the threshold-gated note (threshold kept as hint only); _consolidate_session_memories removed from the disconnect path and guarded by test_method_removed. Tests updated in test_memory_reflection.py. CI green (test + test-windows). Matches rant 22:12:16 (single entry + digest-style).

@argszero
argszero merged commit 33d5700 into masterAug 28, 2026
2 checks passed
Sign up for freeto 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.

2 participants

@argszero@how2how2how2-arch