Skip to content

test(sessions): gate snapshot reads instead of wall-clock sleeps - #557

Merged
ScriptedAlchemy merged 3 commits into
cursor/agent-hosts-retain-graph-port-cb93from
cursor/sessions-sleep-to-gates-4258
Aug 20, 2026
Merged

test(sessions): gate snapshot reads instead of wall-clock sleeps#557
ScriptedAlchemy merged 3 commits into
cursor/agent-hosts-retain-graph-port-cb93from
cursor/sessions-sleep-to-gates-4258

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Summary

  • Replaces the fake-IO thread::sleep(snapshot_delay_millis) in MemoryEvidenceGraphRuntime::verified_snapshot with a condvar-backed SnapshotReadGate (enable / entered-read await / release) in the sessions crate test support.
  • Converts the two cancel-mid-read tests to wait until the reader has actually entered the snapshot read, then cancel, then release — replacing racy sleep(10ms) timing with a deterministic ordering plus an explicit entered-before-cancel assertion.
  • Keeps the concurrent same-session merge test green with the barrier plus the gate (await first reader, release) instead of a 50 ms read delay.

Motivation

Coordinator / build-perf named these wall-clock waits: 50 ms fake snapshot IO plus 10 ms "hope the reader started" sleeps made the cancellation tests slow and timing-dependent. Gates make the ordering explicit and the assertions stronger (the reader is provably inside the read before cancellation).

Changes

  • crates/tracedecay-sessions/src/runtime/git_correlation/test_support.rsset_snapshot_read_delay removed; SnapshotReadGate added with gate_snapshot_reads / await_gated_snapshot_reader / release_gated_snapshot_reads / gated_snapshot_readers_entered. Release is the only wake-up, so tests store the cancellation signal before releasing and the reader's post-gate check observes it deterministically.
  • crates/tracedecay-sessions/src/runtime/git_correlation/tests.rsrecovery_observes_request_cancellation_while_reading_a_snapshot now awaits the gated reader, asserts it entered, cancels, releases.
  • crates/tracedecay-sessions/src/runtime/ingest/tests.rsadmitted_bounded_publication_observes_live_operation_cancellation converted the same way; concurrent_same_session_observations_merge_under_the_publication_lock uses the gate to hold the first recovery read open so lock-removal regressions still lose an observation and fail the merge asserts.

Production tokio::time::sleep(CONTROL_POLL_INTERVAL) polling in backfill/bounded/blocking.rs is untouched (production budget, out of scope). No asserts weakened; no tests removed.

Test plan

  • cargo test -p tracedecay-sessions — full crate suite green (git_correlation targets: 57 passed; ingest targets: 63 passed; 0 failed anywhere)
  • cargo fmt -p tracedecay-sessions --check clean
  • Tested manually (n/a — test-only change)

Checklist

  • CHANGELOG.md updated (test-support only; no user-facing behavior change)
  • No secrets, credentials, or .env files included
  • Breaking changes documented (none)
Open in Web Open in Cursor 

@changeset-bot

changeset-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fa00c70

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c730e4ab1d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +62 to +63
while state.entered == 0 {
state = self.changed.wait(state).unwrap();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound the wait for a gated reader

If a spawned recovery or publication returns or panics before reaching verified_snapshot, no thread increments entered or notifies this condition variable. Each converted test waits here before joining its worker, so the test suite hangs indefinitely instead of reporting the underlying failure; use a timed wait or coordination that also observes worker completion.

AGENTS.md reference: AGENTS.md:L108-L110

Useful? React with 👍 / 👎.

Comment on lines +556 to +557
store.graph.await_gated_snapshot_reader();
store.graph.release_gated_snapshot_reads();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prove both publishers contend before releasing the gate

The gate is released after only one publisher enters, while the barrier does not prove that the other publisher has attempted to acquire the publication lock. If that second worker is delayed and the lock is removed, the first can publish before the second reaches the permanently open gate; the second then reads the committed snapshot and all merge assertions still pass, so this test does not deterministically catch the lock-removal regression it targets.

AGENTS.md reference: AGENTS.md:L108-L110

Useful? React with 👍 / 👎.

Co-authored-by: Zack Jackson <ScriptedAlchemy@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/sessions-sleep-to-gates-4258 branch from c730e4a to 086f8e7 Compare August 20, 2026 06:38
@cursor
cursor Bot changed the base branch from cursor/bind-session-evidence-budget-label-1140 to cursor/agent-hosts-retain-graph-port-cb93 August 20, 2026 06:38
@ScriptedAlchemy
ScriptedAlchemy merged commit a46d1ad into cursor/agent-hosts-retain-graph-port-cb93 Aug 20, 2026
1 check passed
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.

2 participants