From d3a45a9ce4f3c6392ba85d64e46690a4dd02486d Mon Sep 17 00:00:00 2001 From: teknium1 Date: Mon, 31 Aug 2026 08:49:59 -0700 Subject: [PATCH] test(agent): update enqueue-after-close contract to the #94736 self-heal The old contract (write after close() raises AttributeError and drops the token delta) is superseded: the persistence boundary now reopens the connection, so the delta lands. Assert the new, stronger contract. --- tests/agent/test_async_token_accounting.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/agent/test_async_token_accounting.py b/tests/agent/test_async_token_accounting.py index e19ff3c291..7b678c92fb 100644 --- a/tests/agent/test_async_token_accounting.py +++ b/tests/agent/test_async_token_accounting.py @@ -277,18 +277,22 @@ class TestReaderFlush: assert _totals(db, "s-cc")["input_tokens"] == 4 - def test_enqueue_after_close_raises_at_call_site(self, tmp_path): - """After close() the synchronous fallback surfaces the failure to the - caller (whose try/except logs it) — the pre-queue contract — instead - of silently dropping the delta.""" + def test_enqueue_after_close_lands_via_reopen(self, tmp_path): + """After close() the synchronous fallback used to surface an opaque + AttributeError to the caller and drop the delta. Since the #94736 + self-heal, a write that reaches the store after a teardown close() + reopens the connection and LANDS instead — strictly better than the + old raise-and-lose contract: no delta is dropped, and the recovery + is loud (WARNING at the persistence boundary).""" db = SessionDB(db_path=tmp_path / "closed.db") db.create_session("s-closed", "test") db.queue_token_counts("s-closed", input_tokens=1, api_call_count=1) db.close() - with pytest.raises(Exception): - db.queue_token_counts("s-closed", input_tokens=2, api_call_count=1) + db.queue_token_counts("s-closed", input_tokens=2, api_call_count=1) assert not db._token_queue # not parked on a dead queue either + assert _totals(db, "s-closed")["input_tokens"] == 1 + 2 + db.close() # =========================================================================