Skip to content

test: make the revive helper close strictly before the resume - #15377

Closed
bolichen97 wants to merge 1 commit into
mainfrom
fix/session-revive-windows-clock
Closed

bolichen97 wants to merge 1 commit into
mainfrom
fix/session-revive-windows-clock

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Make test/test_session_control_revive.py pass reliably on Backend Tests (Windows) (2), so that shard stops failing every pull request.

Since session_revive landed (#13110), a different subset of this file fails on every run of Backend Tests (Windows) (2). The Linux shards pass the same file. The errors include this 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

  • Changing the production compare-and-clear in clear_closed (history_projection.py). Its closed_at >= only_if_closed_before refusal stays exactly as it is.
  • Fixing coarse-clock timing in any other test file. The one other clock-sensitive test found (below) runs on a different shard and uses a different mechanism.
  • Changing any product behaviour on Windows. The possible production follow-up is described below and not attempted here.

What changed (motivation → approach → change)

The helper _archive closes a session through the real close verb, which stamps closed_at = time.time(). The revive that follows takes its own resume_started_at = time.time(). clear_closed(only_if_closed_before=resume_started_at) keeps the closed marker when the close is not strictly earlier. On Windows, Python 3.12's time.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, _archive moves closed_at one minute earlier through conversation_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 original closed_at read 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.time for the whole test:

test/test_session_control_revive.py real clock constant clock clock floored to 15.625 ms (3 runs)
base 64b0a33c9 97 passed 33 failed 22 / 23 / 20 failed
this PR 97 passed 97 passed 97 / 97 / 97 passed
  • With the constant clock, the base failures include every test named in test_session_control_revive.py is flaky on Backend Tests (Windows): 4 different tests fail across two attempts #15361, with the same messages the Windows job shows.
  • An ablation run turned off only the backdate: the 33 constant-clock failures came back. So the backdate alone explains them.
  • The last red shard-2 job on an unrelated PR (run 36689433863, job 109803571372) had 3 failures, all in this file and all in the set above.
  • Other tests that close or resume a session (93 files matching close_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 the note_slot_closed tombstone plus time.sleep(0.01) rather than close_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 (no website/ 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 (the time.monotonic() sibling is already in testing-conventions.md).

Possible production follow-up (not changed here): a client that sends DELETE /api/chat/slots/<key> and then POST /api/chat/slots/<key>/resume for the same key within one tick, on Windows with Python 3.12, gets a 200 while the closed marker 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. The session_revive path with the containment hook refuses visibly with resume_conflict instead.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

_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
@bolichen97
bolichen97 requested a review from a team as a code owner September 30, 2026 09:55
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 37d7684ea5f0e998352048d7cc89ae4850945619 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Confirm this PR's own Backend Tests (Windows) (2) run is green — the Linux tick-simulation is a proxy, not the real shard.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 37d7684ea5f0e998352048d7cc89ae4850945619 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 37d7684

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 37d7684ea5f0e998352048d7cc89ae4850945619: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 37d7684ea5f0e998352048d7cc89ae4850945619 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 37d7684

Verdict parsed from the review's SHA-scoped output markers for commit 37d7684ea5f0e998352048d7cc89ae4850945619.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 37d7684ea5f0e998352048d7cc89ae4850945619: <one-sentence reason>

@bolichen97

Copy link
Copy Markdown
Contributor Author

Windows evidence for head 37d7684: Backend Tests (Windows) (2) passed. The job is https://github.com/kirodotdev/KiroCrew/actions/runs/36699183514/job/109835123580 and it reported 22254 passed, 2059 skipped, 37 xfailed.

The shard's windows-pytest-progress-2 artifact shows all 97 tests in test/test_session_control_revive.py ran and passed (291 phase ends = 97 x setup/call/teardown, all passed). The same shard failed on this file on unrelated PRs, for example job 109803571372.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 30, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Closing as redundant: the same test-side fix (backdating closed_at in _archive so the close lands strictly before the resume) reached main in aec8141 via #14925. The production-side follow-up noted in this PR's body (DELETE then POST /resume within one Windows clock tick leaves the marker standing) still applies and is tracked in #15361.

@bolichen97 bolichen97 closed this Sep 30, 2026
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 30, 2026
@bolichen97
bolichen97 deleted the fix/session-revive-windows-clock branch October 5, 2026 08:09
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.

test_session_control_revive.py is flaky on Backend Tests (Windows): 4 different tests fail across two attempts

1 participant