Skip to content

fix: align cmd_compress dict keys with compression_stats() return values#569

Merged
bensig merged 3 commits intoMemPalace:developfrom
arnoldwender:fix/compress-stats-keys
Apr 11, 2026
Merged

fix: align cmd_compress dict keys with compression_stats() return values#569
bensig merged 3 commits intoMemPalace:developfrom
arnoldwender:fix/compress-stats-keys

Conversation

@arnoldwender
Copy link
Copy Markdown
Contributor

Summary

  • Fixed cmd_compress in cli.py to use the correct dict keys returned by Dialect.compression_stats()

Problem

cmd_compress accesses stats["compressed_chars"], stats["original_tokens"], stats["compressed_tokens"], and stats["ratio"] — but compression_stats() returns "summary_chars", "original_tokens_est", "summary_tokens_est", and "size_ratio". This causes a KeyError crash every time mempalace compress is run.

Changes

Old key (broken) New key (matches compression_stats())
compressed_chars summary_chars
original_tokens original_tokens_est
compressed_tokens summary_tokens_est
ratio size_ratio

original_chars was already correct and unchanged.

Test plan

  • Run mempalace compress --dry-run — should display stats without crashing
  • Run mempalace compress — should store compressed drawers with correct metadata

Copy link
Copy Markdown

@web3guru888 web3guru888 left a comment

Choose a reason for hiding this comment

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

Straightforward crash fix —
No palace found at /root/.mempalace/palace
Run: mempalace init

then mempalace mine has been broken for anyone who ran it. The key name mismatch between and is the kind of thing that slips through because the function call succeeds and only the dict access fails at runtime.

The key mapping in the PR description is clean and verifiable: , , , — all match the return values.

One small suggestion: add a test that calls against a mock palace with known content and asserts the stats keys are present. Right now there's no CI coverage catching this class of mismatch, which is presumably how it survived until now.

Clean fix otherwise.

jphein added a commit to jphein/mempalace that referenced this pull request Apr 10, 2026
…compress keys

- Default new collections to cosine distance (hnsw:space=cosine) instead
  of L2 — fixes negative similarity scores (MemPalace#568)
- Filter unexpected MCP tool args before dispatch — prevents TypeError
  crash from extra params like top_k (MemPalace#572)
- Rotate WAL at 10 MB with one backup to prevent unbounded growth (MemPalace#573)
- Fix cmd_compress KeyError: align dict keys with compression_stats()
  return values (MemPalace#569)
- Fix spellcheck _load_known_names: read from "people" key, use dict
  keys as canonical names (MemPalace#570)
- Repair command uses cosine distance for rebuilt collection

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copy link
Copy Markdown

@web3guru888 web3guru888 left a comment

Choose a reason for hiding this comment

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

Clear bug fix — KeyError crash on every mempalace compress run is a regression that would affect anyone using the compress command.

The key mapping is correct: verified against compression_stats() return values. Test mocks updated to match the real return shape. Clean, targeted fix.

LGTM.


[MemPalace-AGI integration — 215 tests, 710 KG entities]

@jphein
Copy link
Copy Markdown
Collaborator

jphein commented Apr 10, 2026

Incorporated into #562 — aligned all dict key references in cmd_compress and tests with compression_stats() return values (summary_chars, original_tokens_est, summary_tokens_est, size_ratio).

Copy link
Copy Markdown

@web3guru888 web3guru888 left a comment

Choose a reason for hiding this comment

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

Correct, narrow fix. LGTM.


[MemPalace-AGI integration — 215 tests, 710 KG entities]

Copy link
Copy Markdown
Collaborator

@bensig bensig left a comment

Choose a reason for hiding this comment

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

Two issues found in review:

  1. The Total: summary line (post-loop accumulator in cmd_compress) uses the renamed keys but neither test_cmd_compress_dry_run nor test_cmd_compress_stores_results asserts on that output. If someone reverts just the accumulator line, no test catches it. Please add assert "Total:" in captured.out (or assert token counts) to at least one of those tests.

  2. test_compression_stats_keys_match_dialect tests Dialect.compression_stats() directly but lives in tests/test_cli.py. It should be in tests/test_dialect.py — a failure here would point to the wrong file and gives false confidence that cmd_compress integration is covered.

The key renames themselves are correct and verified against dialect.py. These are test coverage gaps, not bugs in the fix.

@arnoldwender
Copy link
Copy Markdown
Contributor Author

Both addressed in 6f615a6:

  1. Added assert "Total:" in out to both test_cmd_compress_dry_run and test_cmd_compress_stores_results
  2. Moved test_compression_stats_keys_match_dialect to tests/test_dialect.py as TestCompressionStats::test_compression_stats_keys

All 59 tests pass.

Copy link
Copy Markdown

@web3guru888 web3guru888 left a comment

Choose a reason for hiding this comment

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

@arnoldwender — both of @bensig's concerns addressed in 6f615a6:

  1. Total: assertion added to both test_cmd_compress_dry_run and test_cmd_compress_stores_results
  2. test_compression_stats_keys_match_dialect moved to tests/test_dialect.py

LGTM.


[MemPalace-AGI integration — 540+ discoveries, 5,251 KG triples]

@bensig bensig changed the base branch from main to develop April 11, 2026 22:21
@bensig bensig requested a review from igorls as a code owner April 11, 2026 22:21
@bensig bensig merged commit 89c0a58 into MemPalace:develop Apr 11, 2026
6 checks passed
NickShtefan pushed a commit to NickShtefan/mempalace that referenced this pull request Apr 12, 2026
…ues (MemPalace#569)

* fix: align cmd_compress dict keys with compression_stats() return values

* test: align compress test mocks with actual compression_stats() keys

* fix: address review — add Total: assertion, move stats key test to test_dialect.py
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.

4 participants