Repository navigation
test(memory): stamp distinct write instants in startup-lesson tie tests - #16441
Conversation
Two cases #16293 added rest on recency between rows written back to back: one asserts the newer of two rows tied on every score renders first, the other asserts, as its fixture precondition, that recency puts the newer of a capped pair first. updated_at comes from vector_memory._now_iso(), which reads datetime.now; on Windows under Python 3.12 that clock ticks about every 15.6 ms, so consecutive writes can share a stamp, and get_lessons orders on updated_at alone. Backend Tests (Windows) (8) failed the capped-pair case on main and both cases on a PR merge ref built on main. Both cases now take distinct write stamps from a fixture that patches vector_memory._now_iso, the seam the sibling lesson-ranking suites already use. With every host-clock write frozen to one instant both fail on the base and pass with this change.
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that this PR's Backend Tests (Windows) (8) shard passes. It is the only Windows evidence for a fix that was proven by simulating Windows' coarse clock on Linux. [DESIGN-REVIEWED] c4cab31 Description read[DESCRIPTION-READ] e2d4aefd39f545396a0c2be4bbcde33223bdd8848e6f5fc75c5f2ad4e4fb7b68 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
Design Review's check request ("Backend Tests (Windows) (8) shard passes"), answered for
|
Problem / Motivation
Goal: Backend Tests (Windows) (8) goes green again on main and on every PR, because two startup-lesson ranking tests stop depending on how finely the wall clock ticks.
Two tests that #16293 added fail on Windows:
TestTheKeywordHalfStaysBounded::test_two_rows_at_the_cap_are_ordered_by_rarity_not_recencyfails its own fixture check,fixture assumes shorter is the newer of the tied pair(assert 7 < 6). It failed on main at 4c735e3: job 111152617267.TestOneKeywordMeasureAcrossTheVectorBoundary::test_the_first_embedded_row_does_not_reshuffle_the_rows_behind_itfails with'Keep cat dog crates stacked' != 'Walk cat dog routes daily'. Both tests failed on fix(dashboard): await the chat_done payload when a refusal replay is aborted at consume #16403: job 111157790305.Why it matters
The Windows (8) shard is a required check, so this red blocks every open PR, whatever it touches. Whether it fails depends on runner speed, so it looks like a flake when it is really two fixtures.
Not a goal
updated_at. Product ordering does not change.What changed (motivation → approach → change)
Both tests assume that a row written later sorts as newer. One asserts that the newer of two rows tied on every score renders first. The other asserts that recency would put the newer of a capped pair first, because that is what lets its
-lexicalmutation check catch anything.updated_atcomes fromvector_memory._now_iso(), which readsdatetime.now. On Windows under Python 3.12 that clock ticks about every 15.6 ms, so two writes in a row can get the same stamp.get_lessonssorts onupdated_atalone, so a tied pair comes back in write order, oldest first. Both CI failures show exactly that.In
test/test_lesson_startup_embedding.py, a new fixture,distinct_write_instants, patchesvector_memory._now_isoto hand out increasing stamps. It is the same seam and the same tick pattern thattest_lesson_ranking.py,test_lesson_keyword_scoring.pyandtest_lesson_turn_injection.pyalready use. Only the two tests take it, and their docstrings say why.Why there is no product change: the spec orders exact ties "then newest-first" (
docs/system-specs/modules/memory-skills-hooks.md:3149). Two rows with one stamp have no newest, so the product keeps its own contract. Arowidtie-break is not an option either. On a crew-lineage storesemantic_memoryis a view, and a view has norowid.Backwards compatibility
Compatible: test-only change; no product code, config or stored data changes.
Removes nothing: the diff adds a test fixture and applies it to two tests.
Tests
The two tests take
distinct_write_instantsand pin the same behaviour as before, now on any clock resolution. The proof was run on Linux (Python 3.12,-n0) with a throwaway pytest plugin. The plugin replacesdatetime.nowinsidekiro_crew.vector_memory, which sits under_now_iso:_now_iso-lexical[index]from the vector-branch sort key still failstest_two_rows_at_the_cap_are_ordered_by_rarity_not_recencyat its final assertion. Its mutation check works on any clock.test_vector_memory_composition_contract.pypasses.local-gate.py --dry-runselects 1 backend file, this one.Manual verification
N/A — unit coverage sufficient: the change is a test fixture, proven red then green above.
Related Issues
no linked issue: main-red fix for the two #16293 tests above, with no tracking issue.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)