Reset log selection at context boundaries instead of clamping on read - #700
Open
jvanbuel wants to merge 1 commit into
Open
Conversation
Two halves of the same problem. clear_state() dropped the log data on an environment switch but left logs.current and the scroll mode pointing into the previous environment's tries. state/context.rs already does the right thing when the task context changes; clear_state now uses the same two lines. current_index() re-derived a valid index on every read via 'self.current % self.all.len().max(1)', papering over a stale value rather than fixing it. update_logs now clamps current when it writes the list, so current is always valid and readers use it directly. Clamping also beats wrapping on the merits: after a shrink you want the newest try, not whichever one modular arithmetic lands on. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0127jzUgqqy8JVX5RydfQxh8
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Two halves of the same problem: log view state outliving the context it belonged to.
1.
clear_state()left log state behindSwitching environments cleared
logs.allbut leftlogs.current(which try is selected) andlogs.scroll_modepointing into the previous environment's tries. Land on a task with two tries carryingcurrent = 3from before, and you open on try 2 instead of try 1; a deepManual { position }scroll leaks into the next log you view.The codebase already knew how to do this —
state/context.rsdoes exactly the right thing when the task context changes:clear_state()now uses the same two lines.LogModel::reset_scroll()is documented "used when navigating to a new context" and simply wasn't being called on the environment-switch path.2.
current_index()clamped on read instead of fixing the writeThis re-derived a valid index on every single read, papering over a stale
currentrather than correcting it.update_logsnow clamps when it writes the list, socurrentis always valid and the three readers use it directly.current_index()is gone.Clamping also beats wrapping on the merits: after the try list shrinks you want the newest try, not whichever one modular arithmetic happens to land on. With
current = 4and three tries, wrapping gives try 2; clamping gives try 3.Test changes
current_index_wraps_when_selection_exceeds_lenencoded the workaround as intended behavior, so it's replaced by two tests on the new contract — one for the clamp, one for the empty list. The existingopen_ui_with_empty_logs_does_not_panicregression test still passes; with the modulo gone there is no division left to panic on.Verification
cargo test --workspace --lib --bins(95 passing),cargo clippy --workspace --all-targets --all-features -- -D warnings, andcargo fmt --all --checkall clean.🤖 Generated with Claude Code
https://claude.ai/code/session_0127jzUgqqy8JVX5RydfQxh8
Generated by Claude Code