Skip to content

fix(repo): make ws re-harvest idempotence test clock-independent - #234

Merged
tonibergholm-codento merged 1 commit into
mainfrom
fix/223-flaky-ws-harvest
Oct 20, 2026
Merged

tonibergholm-codento merged 1 commit into
mainfrom
fix/223-flaky-ws-harvest

Conversation

@tonibergholm-codento

@tonibergholm-codento tonibergholm-codento commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #223

The test relied on two harvests landing in the same unix_now() second, aligning to a second boundary first. Under load the sequence could still cross a boundary.

Adds a #[cfg(test)] thread-local override (repo::TEST_NOW) read by unix_now(); the test pins it, so the re-minted candidate id matches deterministically. Production code is unchanged. The assertions are unchanged: re-harvest resolves to the existing landing tip, leaves no stray work-1 branch, and ends the session.

Verified: 200 runs of the test with two concurrent full-suite runs for load, 0 failures; clippy clean; cargo test -p scl-repo -p scl-cli passes. No other test uses a second-boundary trick (grep unix_now shows only this one).

Summary by CodeRabbit

  • Tests
    • Improved time-dependent test coverage by using a controlled timestamp rather than relying on wall-clock timing.
    • Added cleanup of the temporary test clock after validation, helping ensure isolated and repeatable test runs.
    • No user-facing behavior or public interfaces changed.

…g to a second boundary (ref #223)

The test needed two harvests to land in one unix_now() second and flaked
under load. Add a test-only thread-local override of unix_now and pin it,
so the re-minted candidate id is deterministic.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T08:37:56.171391Z 66537ef PR opened
🔒 Security Review ✅ Completed 2026-10-20T08:38:01.144974Z 66537ef PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 599bcadd-99c0-4a3f-bb16-f0f5d500d815
📥 Commits

Reviewing files that changed from the base of the PR and between 79c0ecd and 66537ef.

📒 Files selected for processing: 2
  • crates/repo/src/repo.rs
  • crates/repo/src/ws.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

The change adds a test-only timestamp override to unix_now and uses it in the crash-window harvest test. The test no longer waits for a wall-clock second boundary and clears the override after its assertions.

Changes: Harvest clock determinism

Layer / File(s) Summary
Clock override and reharvest test
crates/repo/src/repo.rs, crates/repo/src/ws.rs
unix_now uses the test-only timestamp when set and otherwise retains the system-clock behavior. The crash-window test pins the timestamp, updates its identical-commit comment, and clears the override after its assertions.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 66537

The change removes the test's wall-clock boundary dependency without affecting production time behavior.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: making the WebSocket re-harvest idempotence test independent of wall-clock timing.
Linked Issues check Passed Issue #223 requires removal of the wall-clock second-boundary dependency in ws::tests::harvest_reharvest_after_crash_window_is_idempotent. The PR adds the test-only repo::TEST_NOW thread-local ove…
Out of Scope Changes check Passed The changes are limited to the test-only clock override in crates/repo/src/repo.rs and its use in the linked WebSocket test in crates/repo/src/ws.rs. These changes directly support issue #223. No …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
Full details: Linked Issues check

Explanation

Issue #223 requires removal of the wall-clock second-boundary dependency in ws::tests::harvest_reharvest_after_crash_window_is_idempotent. The PR adds the test-only repo::TEST_NOW thread-local override and makes unix_now() use it when set. The test pins the timestamp before both harvests, so the candidate ID does not depend on load or a wall-clock boundary. The diff preserves the idempotence assertions and limits the override to #[cfg(test)].

Full details: Out of Scope Changes check

Explanation

The changes are limited to the test-only clock override in crates/repo/src/repo.rs and its use in the linked WebSocket test in crates/repo/src/ws.rs. These changes directly support issue #223. No unrelated production behavior or unrelated test behavior is changed.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@tonibergholm tonibergholm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved: test-only clock seam, loop-verified, CI green, Codex clean.

@tonibergholm-codento
tonibergholm-codento merged commit 5b9c9cc into main Oct 20, 2026
8 checks passed
@tonibergholm-codento
tonibergholm-codento deleted the fix/223-flaky-ws-harvest branch October 20, 2026 08:52
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.

Flaky: ws::tests::harvest_reharvest_after_crash_window_is_idempotent depends on a wall-clock second boundary

2 participants