fix(tui): anchor the Agents rail cursor to its row, not its offset - #222
Conversation
Co-authored-by: Medulla <medulla@tinyhumans.ai>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThe Agents rail now uses stable row anchors and lane-aware cursor helpers. Rendered rail hits carry target metadata and validate against current rows. Navigation, focus, selection, overflow handling, and tests use the shared cursor state. ChangesAgents rail cursor flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant AgentsRail
participant MouseInput
participant App
User->>AgentsRail: click rendered rail row
AgentsRail->>MouseInput: provide RailHit metadata
MouseInput->>App: validate target and set rail cursor
App-->>MouseInput: dispatch row action
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3f2fc2866
ℹ️ 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".
# Conflicts: # src/tui/src/ui/app/commands/dispatch.rs # src/tui/src/ui/app/input/nav.rs # src/tui/src/ui/app/keys/agents.rs # src/tui/src/ui/app/rail.rs # src/tui/src/ui/app/render/agents/mod.rs # src/tui/src/ui/app/session_control.rs # src/tui/src/ui/app/state.rs # src/tui/src/ui/app/types.rs
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4b85ba6149
ℹ️ 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".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b62c96851
ℹ️ 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".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e830d9dabe
ℹ️ 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".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa8894ea3e
ℹ️ 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".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: daff7b1017
ℹ️ 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".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f9ce202262
ℹ️ 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".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 69ca9cec29
ℹ️ 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".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a9ee3f671
ℹ️ 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".
# Conflicts: # src/tui/src/ui/app/rail/mod.rs
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4afae70a7b
ℹ️ 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".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5bc66ce831
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 08515963ca
ℹ️ 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".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/tui/src/ui/app/input/nav.rs`:
- Around line 58-59: Use one lane snapshot for every rail operation: in
src/tui/src/ui/app/input/nav.rs lines 58-59, capture lanes before calling
rail_rows_in, then resolve the cursor and selected lane from that same snapshot;
in lines 119-123, build rows and anchors from one snapshot and carry a stable
lane key rather than a lane index across rebuilt projections; in
src/tui/src/ui/app/session_focus.rs lines 121-122, capture lanes before building
rows and pass that same slice to set_rail_cursor_in. Ensure all rows, anchors,
paging, and focus operations use the matching lane snapshot.
In `@src/tui/src/ui/app/keys/agents.rs`:
- Around line 56-72: Use one captured lane snapshot for rail-row construction
and cursor resolution at all affected sites. In
src/tui/src/ui/app/keys/agents.rs lines 56-72, capture lanes, call
rail_rows_in(&lanes), and pass &lanes to rail_cursor_in. Apply the same pattern
in src/tui/src/ui/app/agent_control.rs lines 150-155; lines 274-281 and 284-296
must also pass &lanes to set_rail_cursor_in after constructing rows with
rail_rows_in(&lanes).
In `@src/tui/src/ui/app/types/model.rs`:
- Around line 6-10: Split the oversized model.rs state definitions into cohesive
responsibility-based Rust modules, keeping each source file under 500 lines of
code excluding comments. Preserve the existing App fields, private helper types,
and visibility needed by sibling App impl modules, and update types/mod.rs to
provide the module wiring and re-exports so existing references remain
unchanged.
In `@src/tui/src/ui/app/types/rail_hit.rs`:
- Around line 65-70: Update the row-to-target classification in the rail hit
mapping to handle RailRow::WorkflowRun before the generic session_id() branch,
returning a dedicated RailHitTarget containing the workflow and run IDs. Extend
the click dispatch for that target to call open_workflow_run, while preserving
existing Session handling for other rows.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d53d0ff4-837b-495b-b887-ebf8bf1141c6
📒 Files selected for processing (19)
src/tui/src/ui/app/agent_control.rssrc/tui/src/ui/app/commands/dispatch.rssrc/tui/src/ui/app/input/mouse.rssrc/tui/src/ui/app/input/nav.rssrc/tui/src/ui/app/input/tests.rssrc/tui/src/ui/app/keys/agents.rssrc/tui/src/ui/app/rail/cursor.rssrc/tui/src/ui/app/rail/mod.rssrc/tui/src/ui/app/rail/tests.rssrc/tui/src/ui/app/rail/types.rssrc/tui/src/ui/app/render/agents/mod.rssrc/tui/src/ui/app/render/agents/rail/mod.rssrc/tui/src/ui/app/session_control_tests.rssrc/tui/src/ui/app/session_focus.rssrc/tui/src/ui/app/state.rssrc/tui/src/ui/app/tests/mod.rssrc/tui/src/ui/app/types/mod.rssrc/tui/src/ui/app/types/model.rssrc/tui/src/ui/app/types/rail_hit.rs
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 30499350a0
ℹ️ 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".
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5a295b3f28
ℹ️ 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".
| #[cfg(test)] | ||
| mod cursor_tests; |
There was a problem hiding this comment.
Restore cursor tests to rail/tests.rs
Fresh evidence after the earlier thread reported this fixed is that the reviewed tree again declares rail/cursor_tests.rs as a separate unit-test child. The repository's mandatory directory-module convention requires these tests to live in the canonical rail/tests.rs module; consolidate or relocate the coverage while refactoring fixtures as needed to preserve the 500-line ceiling.
AGENTS.md reference: AGENTS.md:L63-L63
Useful? React with 👍 / 👎.
The bug
Spawning an agent while the operator is inside a harness pane tears the TUI out from under them: the keyboard is released back to the chrome mid-keystroke, the composer and work panel reclaim the right column, and the harness is resized and repainted. It reads as the TUI resetting itself.
The Agents rail cursor was a bare row offset (
App::agent_index), butrail_rows()is rebuilt from live state every frame, and operator-started harnesses are appended last:When the orchestrator spawns an agent, its lane and task sublane are inserted above the harness group and every row below shifts down. The stored offset then names a different row. In
render/agents/mod.rs:agents_selection()that meansselection.harnessgoesNone, which callsrelease_harness(), which flipsshow_composer/show_work, which re-lays-out the right column, which resizes the PTY and makes the harness reflow.The same defect hit task sublanes on their own: they are ordered running-first by recency, so they reorder under a positional cursor with nothing being spawned at all.
The fix
The cursor is remembered by identity; its offset is re-derived whenever the rows are rebuilt.
src/tui/src/ui/app/rail.rsgains:RailAnchor—NewHarness/Harness(session_id)/Lane(lane_key)/Task { lane, task_id }. Dividers and the+N morecounter have none, matchingRailRow::selectable.rail_anchor(row, lanes)andresolve_rail_cursor(rows, lanes, anchor, fallback). When an anchored row genuinely disappears — a harness exits and is forgotten, a task falls past the sublane cap — it falls back to the last offset, clamped, and the caller re-anchors from whatever that lands on, so the fallback is used for one frame at most.App::rail_cursor{,_in},set_rail_cursor{,_in},reset_rail_cursor.Every read of the cursor now goes through those (
agents_selection,watch_target,kill_target,on_new_harness_row,selected_agent_task,on_orchestrator_lane, and theagent_index()inspection seam), and every write does too (arrow nav, rail clicks,select_harness_row, the type-to-jump-to-the-orchestrator path).new_threaddeliberately clears the anchor — that reset should not follow the old row.Public API
App::agent_index()(test/inspection seam) now resolves through the anchor rather than returning the stored offset, so it answers with the row the operator is on even when the rail has grown since the last draw. No signature change.Tests
New
src/tui/src/ui/app/rail_tests.rs:/bin/shharness on a real pty, attaches to it, injects the spawn event, and asserts the operator is still attached and still on their harness row.Reverting the fix makes that last test fail with
attached_harness()returningNoneimmediately after the spawn — the reported symptom.ui::app::testshelpers that pokedagent_indexdirectly now useset_rail_cursor.Validation
cargo fmt --checkcargo clippy --all-targets -- -D warningscargo testOne failure,
e2e_login::login_scopes_the_home_to_the_backends_underscore_id, is pre-existing: it fails identically on the stashed baseline (backend rejected session token on GET /auth/me).Summary by CodeRabbit
Bug Fixes
Tests