fix(snapshot): saturate session counters#1878
Merged
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | b837165 | Commit Preview URL | Jun 05 2026, 01:12 AM |
There was a problem hiding this comment.
Pull request overview
This PR hardens snapshot/restore session accounting against counter overflow by switching exec/session counter increments to saturating arithmetic, preventing panics (debug) or wraparound (release) when restoring forged/extreme snapshot values.
Changes:
- Replace
+= 1withsaturating_add(1)for command and session exec-call counters inExecutionCounters. - Add unit tests to verify counters saturate at
usize::MAX/u64::MAXinstead of overflowing. - Add an integration regression test ensuring restoring
session_exec_calls = u64::MAXdoesn’t panic/wrap and still blocks furtherexec()calls via session limits.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/bashkit/src/limits.rs | Use saturating increments for counters; add unit tests covering saturation behavior. |
| crates/bashkit/tests/integration/snapshot_tests.rs | Add regression test for restoring extreme exec-call counters without overflow/wrap. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
is_err() alone could be satisfied by unrelated failures; verify the error text contains "session exec() call limit" to pin the exact failure path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
u64::MAXand the subsequent unchecked+= 1would overflow or wrap, allowing a forged snapshot to crash the process or bypass session exec-call limits.Description
+= 1withsaturating_add(1)intick_commandandtick_exec_callincrates/bashkit/src/limits.rs.test_command_counter_saturates_on_overflowandtest_exec_counter_saturates_on_overflowincrates/bashkit/src/limits.rsto assert counters saturate at their max values.snapshot_restore_extreme_exec_counter_errors_without_overflowincrates/bashkit/tests/integration/snapshot_tests.rsto assert restoringsession_exec_calls = u64::MAXdoes not panic or wrap and still enforces limits.Testing
cargo fmt --all -- --checkand it passed.cargo test -p bashkitand the new tests passed.cargo test -p bashkit --test integration snapshot_tests::and the snapshot suite (including the new regression) passed (all tests green).Codex Task