Skip to content

test(decay): deflake reinforced-memory guard against coarse clocks - #190

Merged
Coding-Dev-Tools merged 1 commit into
mainfrom
fix/decay-test-timestamp-race
Sep 3, 2026
Merged

test(decay): deflake reinforced-memory guard against coarse clocks#190
Coding-Dev-Tools merged 1 commit into
mainfrom
fix/decay-test-timestamp-race

Conversation

@Coding-Dev-Tools

Copy link
Copy Markdown
Owner

Problem

tests/test_decay_idempotent.py::test_reinforced_memory_is_not_decayed_that_interval failed intermittently in full-suite runs on this Windows host:

AssertionError: assert 2.1281674200679393e-09 < 1e-09

It always passed in isolation.

Root cause

The test simulated reinforcement with last_access = now_ts() immediately after a decay pass had written last_decay = now_ts() as its anchor. On hosts with coarse clock resolution (consecutive time.time() calls can return the same value — observed on Windows), last_access == last_decay, so the production guard

if last_access > anchor:   # strict >

does not fire, and the pass legitimately decays one clock tick's interval. At a 7-day half-life, one ~1 ms tick decays stability by ~2.1e-9 — just over the test's 1e-9 bit-identity threshold. This is a test race against wall-clock granularity, not a recurrence of the compounding-decay regression the test exists to pin.

Fix (test-only)

  • Set last_access = now + 1.0 (one second past the pass anchor) so the guard condition holds deterministically on every host, regardless of clock resolution.
  • Extend coverage: assert the guard across 50 rapid subsequent passes, not just the first one — that is the actual invariant (a reinforced memory is never decayed again until new real time passes).

No production code changed. The strict > guard is correct: with last_access == anchor on a first pass (last_decay IS NULL, anchor derived from last_access), the 10-day interval must decay; changing it to >= would break first-pass decay.

Verification

  • tests/test_decay_idempotent.py passes 8/8 consecutive runs (previously flaked ~1 in 3 full-suite runs).
  • 20/20 same-tick stress trials: stability bit-identical across rapid passes.
  • Full offline gate: 4503 passed, 39 skipped, ruff clean, pyright 0 errors, all eval gates green.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

The test simulated reinforcement by setting last_access = now_ts(), then
asserted the next decay pass leaves stability bit-identical (1e-9). On
hosts with coarse clock resolution (observed on Windows: consecutive
time.time() calls can return the same value), last_access can equal the
just-written last_decay anchor, so the strict 'last_access > anchor'
guard misses and the pass legitimately decays one tick's interval
(~2.1e-9 stability drift) — a race, not the compounding regression this
test pins.

Set last_access one second past the pass anchor so the guard condition
holds deterministically on every host, and extend coverage to 50 rapid
passes to pin the guard, not just the first one after the update.

Reproduced: full-suite runs failed this test intermittently (stability
drift 2.13e-9 vs 1e-9 threshold) while it passed in isolation; 20/20
same-tick stress trials now stable across 8 consecutive test runs.
@Coding-Dev-Tools
Coding-Dev-Tools force-pushed the fix/decay-test-timestamp-race branch from f07c93f to 12f6bf1 Compare September 3, 2026 14:27
@Coding-Dev-Tools
Coding-Dev-Tools merged commit aea7e9c into main Sep 3, 2026
40 of 43 checks passed
@Coding-Dev-Tools
Coding-Dev-Tools deleted the fix/decay-test-timestamp-race branch September 3, 2026 14:45
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