Skip to content

fix: is_generating was stale and could make the chat unresponsive#178

Merged
carlos-algms merged 11 commits intomainfrom
fix/is-generating-staleness
Apr 2, 2026
Merged

fix: is_generating was stale and could make the chat unresponsive#178
carlos-algms merged 11 commits intomainfrom
fix/is-generating-staleness

Conversation

@carlos-algms
Copy link
Copy Markdown
Owner

No description provided.

Prevents is_generating from staying true after session cancel,
which blocked user interaction on restore, new session, and provider switch.
Previously, stop_generation() sent session/cancel but never set
is_generating = false. If the provider ignored the cancel or crashed,
the flag stayed stuck true forever, blocking all user interaction.
Also stops the spinner immediately instead of waiting for the
callback that may never arrive.
- Prevents orphaned callbacks when provider crashes mid-generation
- send_prompt, create_session, load_session callbacks now receive
  proper error on disconnect instead of hanging forever
…rompt guard

Allows users to escape stuck is_generating=true state by typing /new,
even when the generation guard would otherwise block all input.
…change

Captures request_session_id before send_prompt and skips the finish
message + stop-animation if session_id changed by the time the
response arrives (cancel/restore/new session).
…ives nil

Fixes invalid ACP schema sent when stop_generation() cancels pending permissions.
Previously, nil option_id produced { outcome = "selected", optionId = nil }
which violates the schema. Now sends { outcome = "cancelled" } instead.
Prevents a stale callback from session A incorrectly clearing
is_generating on session B if B is mid-generation.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 85508c2d-99ae-4e06-9395-d63af8ac48ef

📥 Commits

Reviewing files that changed from the base of the PR and between 7ec2bd7 and e1ed6e1.

📒 Files selected for processing (3)
  • lua/agentic/acp/acp_client.test.lua
  • lua/agentic/session_manager.lua
  • lua/agentic/session_manager.test.lua

📝 Walkthrough

Walkthrough

The PR adds ACPClient:_drain_pending_callbacks(reason) and updates ACPClient:_set_state to capture, clear, and schedule invocation of pending callbacks with a TRANSPORT_ERROR when the client enters "disconnected" or "error". Tests verify drained callbacks receive an ACPError with the appropriate code and message, and that client.callbacks is emptied. Session management changes: SessionManager._handle_input_submit now handles /new before the submit-guard, send_prompt callbacks ignore stale responses by comparing session_id, and _cancel_session plus Agentic.stop_generation now set session.is_generating = false and stop the session status_animation. Multiple unit tests were added/updated to cover these behaviors.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client
participant ACPClient
participant CallbackRegistry
participant Scheduler

Client->>ACPClient: send_prompt(request, callback)
ACPClient->>CallbackRegistry: register callback (id)
ACPClient->>/* Transport */: send request
Note over ACPClient,CallbackRegistry: callbacks remain pending

ACPClient->>ACPClient: on_state_change("disconnected"/"error")
ACPClient->>ACPClient: _drain_pending_callbacks(reason)
ACPClient->>CallbackRegistry: capture & clear callbacks
ACPClient->>ACPClient: create TRANSPORT_ERROR(reason)
ACPClient->>Scheduler: schedule pcall(callback, nil, error) for each
Scheduler->>Client: invoke each callback (pcall) with (nil, ACPError)

Possibly related PRs

Poem

🐰 I hopped through queues where pending calls lay,
Drained the stale echoes and sent errors away,
Sessions unspun and animations cease,
New prompts may spring while old ones find peace,
A rabbit's small thump for tidy release ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No description was provided by the author; this is a lenient check that only fails if the description is completely off-topic. Add a brief description explaining what caused the is_generating staleness, how it was fixed, and the impact of the changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: addressing staleness in is_generating that could cause UI responsiveness issues.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/is-generating-staleness

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.

❤️ Share

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

The drain fires from a libuv exit callback (uv.spawn on_exit),
not from vim's main loop. Callbacks like create_session access
Neovim APIs directly without vim.schedule, which would cause
"fast event" errors. Wrapping in vim.schedule ensures safety.
`{ outcome = "selected", optionId = nil }` serializes to
`{ "outcome": "selected" }` in JSON — nil fields are omitted.
The original code was correct.
@carlos-algms carlos-algms marked this pull request as ready for review April 2, 2026 10:38
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lua/agentic/session_manager.lua`:
- Line 983: The _cancel_session() path only resets self.is_generating = false
but doesn't stop the status animation like Agentic.stop_generation() does;
update _cancel_session() to also call self.status_animation:stop() (or check for
existence before calling) so it mirrors the behavior of
Agentic.stop_generation() and ensures the animation is explicitly stopped
whenever generation is cancelled.
🪄 Autofix (Beta)

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: ASSERTIVE

Plan: Pro

Run ID: 968c70b1-6a0b-4713-b90c-e70e61623b64

📥 Commits

Reviewing files that changed from the base of the PR and between 8f1cbc7 and 48f027b.

📒 Files selected for processing (6)
  • lua/agentic/acp/acp_client.lua
  • lua/agentic/acp/acp_client.test.lua
  • lua/agentic/agentic.test.lua
  • lua/agentic/init.lua
  • lua/agentic/session_manager.lua
  • lua/agentic/session_manager.test.lua

Comment thread lua/agentic/session_manager.lua
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lua/agentic/acp/acp_client.test.lua`:
- Line 287: The LuaCATS diagnostic directive is missing a space after the
triple-dash; update the annotation string '---@diagnostic disable-next-line:
duplicate-set-field' to follow the project's style by inserting a space so it
reads '--- `@diagnostic` disable-next-line: duplicate-set-field' (adjust any other
similar annotations in the same file if present) to ensure consistent LuaCATS
formatting.

In `@lua/agentic/session_manager.lua`:
- Line 603: The pattern match for the `/new` command is too permissive and will
match inputs like `/newabc`; update the check in session_manager.lua that
currently uses input_text:match("^/new%s*") to require a token boundary so only
real `/new` invocations trigger new_session(); e.g., change to a pattern that
demands end or whitespace such as input_text:match("^/new(%s.*)?$") (affects the
block that calls new_session() using the input_text variable).

In `@lua/agentic/session_manager.test.lua`:
- Around line 815-849: The test for SessionManager:_cancel_session only asserts
session.is_generating is false; update the test to also assert that the
session.status_animation.stop method was called — locate the test that
constructs the session table and calls session:_cancel_session() (uses
SessionManager._cancel_session and local session variable) and replace or
augment the status_animation.stop stub with a spy (or wrap it) so you can assert
it was invoked after calling session:_cancel_session().
🪄 Autofix (Beta)

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: ASSERTIVE

Plan: Pro

Run ID: 34c621fe-938d-4ea2-b3e7-0945f500ef02

📥 Commits

Reviewing files that changed from the base of the PR and between 48f027b and 7ec2bd7.

📒 Files selected for processing (4)
  • lua/agentic/acp/acp_client.lua
  • lua/agentic/acp/acp_client.test.lua
  • lua/agentic/session_manager.lua
  • lua/agentic/session_manager.test.lua

Comment thread lua/agentic/acp/acp_client.test.lua Outdated
Comment thread lua/agentic/session_manager.lua Outdated
Comment thread lua/agentic/session_manager.test.lua
@carlos-algms carlos-algms merged commit 9c40fc5 into main Apr 2, 2026
8 checks passed
@carlos-algms carlos-algms deleted the fix/is-generating-staleness branch April 2, 2026 17:28
PeterCardenas pushed a commit to PeterCardenas/agentic.nvim that referenced this pull request Apr 11, 2026
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