Repository navigation
test: make the revive helper close strictly before the resume - #15377
bolichen97 wants to merge 1 commit into
Conversation
_archive closes the peer through the production verb, which stamps closed_at with time.time(). The revive that follows captures resume_started_at the same way, and clear_closed keeps the closed marker when closed_at >= resume_started_at. On Windows under Python 3.12, time.time() advances once per ~15.6 ms clock tick, so the two stamps are often the same float: the marker is never cleared and the revive fails. A varying subset of test_session_control_revive.py failed on Backend Tests (Windows) (2) for every PR. _archive now moves closed_at a minute earlier through update_metadata, stating the "closed before the resume began" precondition the tests assume. The production guard is unchanged. Root cause identified by chenmingwei23 in #14925. Fixes #15361
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Confirm this PR's own [DESIGN-REVIEWED] 37d7684 Description read[DESCRIPTION-READ] 9433ee10b9444f2a5006229ea776b2a01e1c3f3298f7f51e5c1a2ec478aebfa8 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 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 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: |
Opus 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: |
|
Windows evidence for head 37d7684: The shard's |
|
Closing as redundant: the same test-side fix (backdating |
Problem / Motivation
Goal: Make
test/test_session_control_revive.pypass reliably onBackend Tests (Windows) (2), so that shard stops failing every pull request.Since
session_revivelanded (#13110), a different subset of this file fails on every run ofBackend Tests (Windows) (2). The Linux shards pass the same file. The errors includethis session changed while resuming; open it again,fixture did not actually clear the marker, and'resume_conflict' == 'linked_session_target'.Why it matters
The shard is red on every PR, whatever the PR changes. That blocks merges across the whole repo and trains people to rerun red Windows jobs instead of reading them.
Not a goal
clear_closed(history_projection.py). Itsclosed_at >= only_if_closed_beforerefusal stays exactly as it is.What changed (motivation → approach → change)
The helper
_archivecloses a session through the real close verb, which stampsclosed_at = time.time(). The revive that follows takes its ownresume_started_at = time.time().clear_closed(only_if_closed_before=resume_started_at)keeps theclosedmarker when the close is not strictly earlier. On Windows, Python 3.12'stime.time()only moves once per ~15.6 ms clock tick. So a close and the revive a few microseconds later often read the same float. The guard sees them as equal and keeps the marker, and the revive fails. Which tests fail depends on where each one falls against a tick boundary, which is why the failing subset changes between runs.The fix is test-only. After the real close,
_archivemovesclosed_atone minute earlier throughconversation_log.update_metadata. This states the precondition these tests already assume: the session was closed before the resume began. The file's mtime and every other metadata field stay the same. The three tests that check a refused revive restores the originalclosed_atread their "before" value after_archive, so they still compare like with like.Root cause and the reference hunk: chenmingwei23, in #14925 (and on #15364). This PR lifts that hunk into its own change, with a comment that passes the comment-history gate and names the Python version.
Backwards compatibility
Compatible: only a test helper changes. No production code, config or contract changes.
Tests
The Windows tick was simulated on Linux with a scratch pytest plugin (not committed) that patches
time.timefor the whole test:test/test_session_control_revive.py64b0a33c9close_target|clear_closed|closed_at|resume_slot_from_history|revive_session|close_slot|/resume) were swept with the constant clock. All 9437 passed on the real clock, and only one more test failed under the constant clock:test/test_rehydrate_async.py::test_a_close_predating_the_read_does_not_block. It runs on Windows shard 1, uses thenote_slot_closedtombstone plustime.sleep(0.01)rather thanclose_target/clear_closed, and is not red on shard 2, so it is left alone.test/test_session_control*.py: 568 passed. black, flake8, isort, the comment-history and brand gates and CI's Semgrep rule set (baseline mode): clean.local-gate.py --dry-run: 1 related backend file (this one); frontend not selected (nowebsite/change).Manual verification
N/A — test-only change. The key evidence is this PR's own
Backend Tests (Windows) (2)job.Related Issues
Fixes #15361
Pattern harvest
Rule candidate: agents-md
Pattern: a test orders two
time.time()stamps taken microseconds apart and relies on them differing. On Windows through Python 3.12 they can be equal, so the test must construct the order it needs (thetime.monotonic()sibling is already intesting-conventions.md).Possible production follow-up (not changed here): a client that sends
DELETE /api/chat/slots/<key>and thenPOST /api/chat/slots/<key>/resumefor the same key within one tick, on Windows with Python 3.12, gets a 200 while theclosedmarker stays on disk, so the tab disappears at the next restart. No shipped client sends that pair back to back: the frontend, built-in apps and MCP tools all have a human, LLM or permission round trip in between. Thesession_revivepath with the containment hook refuses visibly withresume_conflictinstead.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)