Skip to content

test(memory): seed the prompt-growth test in one transaction - #4750

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/memory-growth-test-bulk-seed
Oct 5, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/memory-growth-test-bulk-seed

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

The memory-cap test in the Windows unit job sometimes hit the 60 s pytest timeout, failing unrelated PRs (for example #4723) on a busy runner. It added about 925 memories one at a time, and every add saved to disk on its own, so a slow disk made the test crawl. It now adds each batch in one save. The checks are unchanged and the measured prompt sizes are byte-for-byte the same.

🔍 Technical details
  • MemoryStore.store() commits per row (one WAL fsync) and runs an FTS5 dedup query before each insert. Profiling showed commit ≈ 45% and execute ≈ 50% of runtime.
  • _seed_entries now calls MemoryStore.seed_bulk(): one transaction, no dedup. The prompt builder doesn't read source/last_used, the two fields where seed_bulk differs, so the rendered block is the same. I diffed the standalone growth table before and after: identical.
  • Skipping dedup is safe because _make_entry() produces unique entries by construction. test_dedup_did_not_collapse_seeded_entries still goes through store() (new _store_entries), so it keeps proving that.
  • Local timings (--durations): test_memory_block_never_exceeds_hard_cap 1.69 s → 0.24 s, test_print_growth_table 1.61 s → 0.25 s, the two 500-entry tests 0.8 s → under 0.06 s. Module total: 6.5 s → 1.3 s.

Test plan

  • python -m pytest tests/unit/test_memory_prompt_growth.py -v --durations=10 passes three runs in a row (1.2 to 1.5 s)
  • python tests/unit/test_memory_prompt_growth.py prints a growth table identical to main's
  • python util/lint.py --black --isort --flake8 passes
  • Unit Tests (Windows, py3.12) passes on this PR

The memory-cap test timed out on loaded Windows runners because it seeded
~925 entries through MemoryStore.store(), which commits (and fsyncs the WAL)
once per row and runs an FTS dedup search before each insert. Seeding now
goes through seed_bulk(), one commit per store; the rendered prompt and the
growth table are byte-identical to before.

The dedup sanity test still stores through store(), so it keeps proving the
generator never produces near-duplicates, which is what makes skipping dedup
in the other tests safe.
@github-actions github-actions Bot added the tests Test changes label Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve

This fixes a flaky timeout in the Windows unit job by seeding the memory prompt-growth test in a single save instead of hundreds. The test still checks the same things, and the author confirmed the growth table comes out identical to main's. Nothing blocks merge.

Real-world evidence

N/A: this PR only changes tests, and no evidence bundle was produced. The verdict rests on static review. I couldn't run pytest in this environment, so I'm relying on the author's local timings and the pending Windows CI check.

🔍 Technical details

Issues found

🟢 The docstring claims more than the dedup check covers (tests/unit/test_memory_prompt_growth.py:327): _seed_entries says skipping dedup is safe because test_dedup_did_not_collapse_seeded_entries proves it. That test only goes up to n=100 (for n in (10, 50, 100)), but the bulk path seeds up to 500 per measurement. Before this PR, a dedup collapse at N=250/500 would have shown up as stored < n in the growth table. Now stored is always n, because seed_bulk returns one UUID per item. The author's identical-table diff shows there is no collapse today. If the templates change later, a collapse at large N would go unnoticed. A cheap way to keep the guarantee is to add 500 to the dedup check's sizes. It runs through store(), so it costs roughly the 0.8 s this PR saved on that path, which is still well under the timeout.

        for n in (10, 50, 100, 500):

Strengths

  • It reuses the existing MemoryStore.seed_bulk() instead of adding a test-only bulk path. The fields seed_bulk handles differently (source, last_used) don't affect the rendered memory block.
  • Splitting the code into _entry_items / _store_entries / _seed_entries keeps dedup coverage on the real store() path while the timing-sensitive tests use the fast path.
  • The PR description gives measured before/after timings and confirms the output is byte-identical, which is the right evidence for a test-perf change.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 5, 2026
Merged via the queue into amd:main with commit 285c67a Oct 5, 2026
@kovtcharov-amd
kovtcharov-amd deleted the kalin/memory-growth-test-bulk-seed branch October 5, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants