Skip to content

fix(cli): handle Ctrl+C during bench catchup#297

Merged
shikhar merged 4 commits intomainfrom
codex/bench-ctrl-c-catchup
Mar 5, 2026
Merged

fix(cli): handle Ctrl+C during bench catchup#297
shikhar merged 4 commits intomainfrom
codex/bench-ctrl-c-catchup

Conversation

@shikhar
Copy link
Member

@shikhar shikhar commented Mar 5, 2026

Summary

  • make the catchup-delay wait in s2 bench respond to Ctrl+C instead of blocking in tokio::time::sleep

Testing

  • just fmt
  • cargo test -p s2-cli --no-run

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 5, 2026

Greptile Summary

This PR adds graceful Ctrl+C handling to the two phases of the bench catchup path that previously had no cancellation support: the pre-catchup delay (tokio::time::sleep) and the catchup-read loop (tokio::time::timeout_at). It achieves this through two small, well-scoped async helper functions (wait_or_cancel and timeout_or_cancel) backed by two purpose-built outcome enums, and covers each helper with unit tests for all three observable outcomes.

Key changes:

  • wait_or_cancel(delay, cancel) — races a sleep against a cancellation future, returns DelayOutcome::{Elapsed,Cancelled}.
  • timeout_or_cancel(deadline, future, cancel) — wraps tokio::time::timeout_at and adds a cancel arm, returning CatchupOutcome::{Item,TimedOut,Cancelled}.
  • Both are wired into run() at the catchup-delay site and inside the catchup-read loop; Cancelled in either case causes an early Ok(()) return.
  • Five #[tokio::test] cases cover every branch of both helpers using future::ready / future::pending as deterministic stand-ins.

Confidence Score: 5/5

  • This PR is safe to merge; the change is well-scoped, follows existing patterns, and all new logic is covered by unit tests.
  • The helpers are simple tokio::select! wrappers with exhaustively matched outcome enums. Tests are deterministic (using future::ready/future::pending), and the pattern of constructing a fresh ctrl_c() future per iteration is consistent with the main bench loop. No data races, no unsafe code, no unhandled edge cases.
  • No files require special attention

Sequence Diagram

sequenceDiagram
    participant User
    participant run() as run()
    participant wait_or_cancel
    participant timeout_or_cancel
    participant catchup_stream

    run()->>wait_or_cancel: wait_or_cancel(catchup_delay, ctrl_c())
    alt ctrl_c fires first
        User->>wait_or_cancel: Ctrl+C
        wait_or_cancel-->>run(): DelayOutcome::Cancelled
        run()-->>User: return Ok(())
    else delay elapses
        wait_or_cancel-->>run(): DelayOutcome::Elapsed
    end

    loop catchup read loop
        run()->>timeout_or_cancel: timeout_or_cancel(deadline, catchup_stream.next(), ctrl_c())
        alt ctrl_c fires first
            User->>timeout_or_cancel: Ctrl+C
            timeout_or_cancel-->>run(): CatchupOutcome::Cancelled
            run()-->>User: return Ok(())
        else deadline exceeded
            timeout_or_cancel-->>run(): CatchupOutcome::TimedOut
            run()-->>User: return Err(BenchVerification)
        else item received
            catchup_stream-->>timeout_or_cancel: Some(Ok(sample))
            timeout_or_cancel-->>run(): CatchupOutcome::Item(Some(Ok(sample)))
        else stream ended
            catchup_stream-->>timeout_or_cancel: None
            timeout_or_cancel-->>run(): CatchupOutcome::Item(None)
            run()-->>run(): break
        end
    end
Loading

Last reviewed commit: 71832d8

@shikhar shikhar merged commit 4391e9e into main Mar 5, 2026
16 checks passed
@shikhar shikhar deleted the codex/bench-ctrl-c-catchup branch March 5, 2026 20:27
@s2-release-plz s2-release-plz bot mentioned this pull request Mar 5, 2026
shikhar pushed a commit that referenced this pull request Mar 6, 2026
## 🤖 New release

* `s2-lite`: 0.29.19 -> 0.29.20 (✓ API compatible changes)
* `s2-sdk`: 0.24.6 -> 0.24.7 (✓ API compatible changes)
* `s2-cli`: 0.29.19 -> 0.29.20

<details><summary><i><b>Changelog</b></i></summary><p>

## `s2-lite`

<blockquote>

## [0.29.20] - 2026-03-06

### Features

- Default append pipelining with durability-gated acks
([#289](#289))

### Bug Fixes

- Keep follow sessions alive across dormancy
([#301](#301))

### Miscellaneous Tasks

- Dep updates ([#299](#299))

<!-- generated by git-cliff -->
</blockquote>

## `s2-sdk`

<blockquote>

## [0.24.7] - 2026-03-06

### Miscellaneous Tasks

- Dep updates ([#299](#299))

<!-- generated by git-cliff -->
</blockquote>

## `s2-cli`

<blockquote>

## [0.29.20] - 2026-03-06

### Bug Fixes

- Handle Ctrl+C during bench catchup
([#297](#297))

<!-- generated by git-cliff -->
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: s2-release-plz[bot] <262023388+s2-release-plz[bot]@users.noreply.github.com>
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.

1 participant