Skip to content

feat(acp-nats): add prompt handler#20

Merged
yordis merged 1 commit intomainfrom
feat/acp-nats-prompt
Mar 2, 2026
Merged

feat(acp-nats): add prompt handler#20
yordis merged 1 commit intomainfrom
feat/acp-nats-prompt

Conversation

@yordis
Copy link
Member

@yordis yordis commented Feb 28, 2026

Summary

Replaces the prompt stub with the real prompt handler from the add-acp migration. Prompt publishes session/prompt requests to NATS and awaits responses via the pending waiter mechanism. The bridge acts as a pass-through; session and cancel state are owned by the backend.

Changes

  • prompt handler: Session validation (AcpSessionId), backpressure gating, waiter registration, publish with flush, timeout handling
  • Bridge expansion: PendingSessionPromptResponseWaiters, deliver_prompt_response (public API for host to deliver responses), try_acquire_prompt_slot/release_prompt_slot, session_ready task tracking
  • cancel handler: Validates session ID and publishes to backend (fire-and-forget). Backend owns session state and responds to in-flight prompt with stopReason cancelled.
  • config: prompt_timeout (default 2h), max_concurrent_client_tasks (default 256)
  • NATS subject: session_prompt

Tests

  • prompt: validation, duplicate waiter rejection, backpressure, timeout, publish subject, resolve waiter via deliver_prompt_response, metrics
  • cancel: validation, publish subject, publish-failure metric, success metrics
  • config: prompt_timeout, max_concurrent_client_tasks
  • subjects: session_prompt

Not in this slice

  • client/ext_session_prompt_response subscriber (separate slice; host calls deliver_prompt_response when it receives responses)
  • tests/ integration module
  • acp-nats-stdio crate

@cursor
Copy link

cursor bot commented Feb 28, 2026

PR Summary

Medium Risk
Adds a new async prompt execution path with bounded concurrency, timeout handling, and in-process waiter correlation, which can affect request latency/behavior under load. While well-tested, it introduces new concurrency and timeout semantics plus new config defaults (2h prompt timeout, 256 concurrent tasks).

Overview
Implements the previously stubbed Agent::prompt path: publishes session.prompt work to NATS, registers a per-session waiter to await an out-of-band response, enforces a max in-flight prompt limit (backpressure), and returns structured errors/metrics for publish failure, timeout, parse failure, and channel closure.

Expands Bridge and config to support prompt handling, adding prompt_timeout (default 2h) and max_concurrent_client_tasks (default 256), plus new internal modules pending_prompt_waiters and prompt_slot_counter.

Adds the agent::session_prompt NATS subject helper and updates cancel handling/metrics so request success reflects publish outcome (and invalid session ID errors are attributed to cancel).

Written by Cursor Bugbot for commit ca5db16. This will update automatically on new commits. Configure here.

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds a full prompt request/response flow: new prompt handler, per-session waiter registry, prompt concurrency controls, session prompt NATS subject helper, prompt-related config, integration into Bridge, and related metric/test adjustments including cancel handling tweaks.

Changes

Cohort / File(s) Summary
Prompt handler & Bridge integration
rsworkspace/crates/acp-nats/src/agent/prompt.rs, rsworkspace/crates/acp-nats/src/agent/mod.rs
New prompt::handle implements slot acquisition, session validation, cancel checks, NATS publish to a session prompt subject, waiter registration, timeout handling, metrics, and integrates into Bridge with try_acquire_prompt_slot, release_prompt_slot, deliver_prompt_response, and agent_prompt_requests_in_flight.
Pending waiters coordinator
rsworkspace/crates/acp-nats/src/agent/pending_prompt_waiters.rs
New crate-visible PendingSessionPromptResponseWaiters managing per-session oneshot waiters, timed-out-waiter suppression, registration, resolution, and cleanup.
Config additions
rsworkspace/crates/acp-nats/src/config.rs
Adds DEFAULT_PROMPT_TIMEOUT, DEFAULT_MAX_CONCURRENT_CLIENT_TASKS, new prompt_timeout and max_concurrent_client_tasks fields, builders (with_*) and accessors.
NATS subject helper
rsworkspace/crates/acp-nats/src/nats/subjects.rs
Adds session_prompt(prefix, session_id) subject generator and unit test.
Cancel handling & metrics
rsworkspace/crates/acp-nats/src/agent/cancel.rs
Doc clarifications, metric operation rename to "cancel" for invalid session ID, adjusted publish error inspection (borrowed), and metric now reflects actual publish success; tests updated accordingly.
Tests, docs & deps
rsworkspace/crates/AGENTS.md, rsworkspace/crates/acp-nats/Cargo.toml
Adds developer guidance for crate layout/observability and enables tokio dev-dependency with test-util for tests.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Bridge as Agent Bridge
    participant SlotMgr as Slot Manager
    participant NATS
    participant Waiters as Waiter Registry
    participant Backend

    Client->>Bridge: prompt(request)
    activate Bridge
    Bridge->>SlotMgr: try_acquire_prompt_slot()
    SlotMgr-->>Bridge: slot acquired
    Bridge->>Bridge: validate session_id / check cancelled
    Bridge->>NATS: publish(<prefix>.<sid>.agent.session.prompt, request)
    NATS-->>Bridge: publish result
    Bridge->>Waiters: register_waiter(session_id)
    Note over Bridge: await response with timeout
    deactivate Bridge

    Backend->>NATS: receive prompt subject, produce response
    NATS->>Bridge: deliver message -> deliver_prompt_response(session_id, response)
    activate Bridge
    Bridge->>Waiters: resolve_waiter(session_id, response)
    Waiters-->>Bridge: oneshot notified
    Bridge-->>Client: PromptResponse / error (with StopReason)
    Bridge->>SlotMgr: release_prompt_slot()
    deactivate Bridge
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐇 I hopped a prompt into the air so fleet,
NATS carried whispers between paws and feet,
Waiters kept watch while time softly spun,
Slots released gently when the answering's done,
A rabbit cheers code where sessions meet!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 67.74% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(acp-nats): add prompt handler' accurately and concisely describes the main change—implementing the prompt handler functionality in the acp-nats crate.
Description check ✅ Passed The description comprehensively details the changes, including the prompt handler implementation, bridge expansion, cancel handler updates, configuration additions, and test coverage that align with the changeset.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/acp-nats-prompt

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.

Copy link

@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

🧹 Nitpick comments (2)
rsworkspace/crates/acp-nats/src/agent/prompt.rs (1)

101-109: Add an explicit error metric on prompt publish failure.

This branch logs and returns InternalError, but it currently does not emit acp.errors.total like other prompt failure paths. Emitting one here will keep error observability consistent.

Proposed fix
             if let Err(e) = nats::publish(nats, &subject, &args, publish_options).await {
                 bridge
                     .pending_session_prompt_responses
                     .remove_waiter(&args.session_id);
                 warn!(session_id = %args.session_id, error = %e, "Failed to publish prompt request");
+                bridge.metrics.record_error("prompt", "prompt_publish_failed");
                 return Err(Error::new(
                     ErrorCode::InternalError.into(),
                     format!("Failed to publish prompt request: {}", e),
                 ));
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/acp-nats/src/agent/prompt.rs` around lines 101 - 109, The
publish failure branch that calls nats::publish in prompt.rs removes the waiter
and logs a warning but does not increment the error metric; add an increment of
the acp.errors.total metric (same metric used on other prompt failure paths)
immediately after
bridge.pending_session_prompt_responses.remove_waiter(&args.session_id) and
before returning Err so failures are counted; modify the branch around
nats::publish to call the metric increment helper (or
metrics::increment_counter! / equivalent used elsewhere) and keep the existing
warn! and Err return intact.
rsworkspace/crates/acp-nats/src/nats/subjects.rs (1)

18-20: Use domain value objects for session_prompt inputs.

This helper exposes raw &str for both prefix and session ID, so invalid subject tokens can still be constructed at this boundary if a caller bypasses upstream checks. Prefer typed inputs (AcpPrefix, AcpSessionId) for this new subject helper as well.
As per coding guidelines: Prefer domain-specific value objects over primitives (e.g., AcpPrefix not String). Each type's factory must guarantee correctness at construction—invalid instances should be unrepresentable.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/acp-nats/src/nats/subjects.rs` around lines 18 - 20,
Replace the primitive &str parameters on session_prompt with the domain value
objects so invalid tokens cannot be constructed: change pub fn
session_prompt(prefix: &str, session_id: &str) -> String to take AcpPrefix and
AcpSessionId (e.g., pub fn session_prompt(prefix: &AcpPrefix, session_id:
&AcpSessionId) -> String), use their canonical string accessor (e.g.,
prefix.as_str() or prefix.to_string()/into_inner() depending on the type API)
when formatting the subject, update callers to pass AcpPrefix/AcpSessionId
instances, and add the necessary use/import for AcpPrefix and AcpSessionId so
the module compiles.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@rsworkspace/crates/acp-nats/src/agent/cancel.rs`:
- Around line 1-7: The file fails Rustfmt; run rustfmt across the workspace
(e.g., cargo fmt --all) or format
rsworkspace/crates/acp-nats/src/agent/cancel.rs and related modules so imports
and use statements (e.g., Bridge, CancelNotification, PromptResponse,
StopReason, agent_client_protocol types) conform to rustfmt style; commit the
formatted changes so the CI formatting check passes.

In `@rsworkspace/crates/acp-nats/src/agent/mod.rs`:
- Around line 204-206: has_pending_session_ready_tasks can return true due to
stale finished join handles left in session_ready_publish_tasks; before checking
emptiness prune completed handles (those where JoinHandle::is_finished() is
true). Update has_pending_session_ready_tasks (or extract a small helper used by
both) to borrow_mut() the session_ready_publish_tasks and retain only handles
where !handle.is_finished(), then return !is_empty(); reference the
functions/fields: has_pending_session_ready_tasks, register_session_ready_task,
and session_ready_publish_tasks.

In `@rsworkspace/crates/acp-nats/src/agent/prompt.rs`:
- Around line 46-52: The code calls bridge.metrics.record_request twice for
invalid session IDs: once inside the AcpSessionId::try_from(...).map_err(...)
closure and again at the function end; remove the duplicated record_request from
the map_err closure so map_err only records the error
(bridge.metrics.record_error) and returns the mapped error, letting the existing
final bridge.metrics.record_request call (with success=false) handle request
counting and timing. Apply the same change for the similar map_err block at the
other occurrence (lines around the second AcpSessionId::try_from use).

---

Nitpick comments:
In `@rsworkspace/crates/acp-nats/src/agent/prompt.rs`:
- Around line 101-109: The publish failure branch that calls nats::publish in
prompt.rs removes the waiter and logs a warning but does not increment the error
metric; add an increment of the acp.errors.total metric (same metric used on
other prompt failure paths) immediately after
bridge.pending_session_prompt_responses.remove_waiter(&args.session_id) and
before returning Err so failures are counted; modify the branch around
nats::publish to call the metric increment helper (or
metrics::increment_counter! / equivalent used elsewhere) and keep the existing
warn! and Err return intact.

In `@rsworkspace/crates/acp-nats/src/nats/subjects.rs`:
- Around line 18-20: Replace the primitive &str parameters on session_prompt
with the domain value objects so invalid tokens cannot be constructed: change
pub fn session_prompt(prefix: &str, session_id: &str) -> String to take
AcpPrefix and AcpSessionId (e.g., pub fn session_prompt(prefix: &AcpPrefix,
session_id: &AcpSessionId) -> String), use their canonical string accessor
(e.g., prefix.as_str() or prefix.to_string()/into_inner() depending on the type
API) when formatting the subject, update callers to pass AcpPrefix/AcpSessionId
instances, and add the necessary use/import for AcpPrefix and AcpSessionId so
the module compiles.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48ab41d and 92ef9e2.

📒 Files selected for processing (5)
  • rsworkspace/crates/acp-nats/src/agent/cancel.rs
  • rsworkspace/crates/acp-nats/src/agent/mod.rs
  • rsworkspace/crates/acp-nats/src/agent/prompt.rs
  • rsworkspace/crates/acp-nats/src/config.rs
  • rsworkspace/crates/acp-nats/src/nats/subjects.rs

yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 92ef9e2 to 753ac4a Compare February 28, 2026 04:48
yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 753ac4a to 0952857 Compare February 28, 2026 04:50
yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 0952857 to 24679d9 Compare February 28, 2026 04:51
@github-actions
Copy link

github-actions bot commented Feb 28, 2026

badge

Code Coverage Summary

Details
Filename                                         Stmts    Miss  Cover    Missing
---------------------------------------------  -------  ------  -------  --------------------------------------------
crates/acp-nats/src/telemetry/metrics.rs            32       0  100.00%
crates/acp-nats/src/nats/token.rs                    8       0  100.00%
crates/acp-nats/src/nats/extensions.rs               3       0  100.00%
crates/acp-nats/src/nats/subjects.rs                76       0  100.00%
crates/trogon-std/src/time/system.rs                24       0  100.00%
crates/trogon-std/src/time/mock.rs                 123       0  100.00%
crates/acp-nats/src/agent/load_session.rs          330       0  100.00%
crates/acp-nats/src/agent/authenticate.rs          180       2  98.89%   106, 111
crates/acp-nats/src/agent/initialize.rs            196       2  98.98%   113, 118
crates/acp-nats/src/agent/set_session_mode.rs      219       0  100.00%
crates/acp-nats/src/agent/mod.rs                    36       0  100.00%
crates/acp-nats/src/agent/prompt.rs                555       0  100.00%
crates/acp-nats/src/agent/ext_notification.rs      222       0  100.00%
crates/acp-nats/src/agent/cancel.rs                197       0  100.00%
crates/acp-nats/src/agent/new_session.rs           313       0  100.00%
crates/acp-nats/src/agent/ext_method.rs            289       0  100.00%
crates/acp-nats/src/pending_prompt_waiters.rs      112       0  100.00%
crates/acp-nats/src/acp_prefix.rs                   63       0  100.00%
crates/acp-nats/src/ext_method_name.rs              85       0  100.00%
crates/acp-nats/src/prompt_slot_counter.rs          78       0  100.00%
crates/acp-nats/src/session_id.rs                   88       0  100.00%
crates/acp-nats/src/config.rs                       77       0  100.00%
crates/trogon-std/src/dirs/fixed.rs                 84       0  100.00%
crates/trogon-std/src/dirs/system.rs                98      11  88.78%   57, 65, 67, 75, 77, 85, 87, 96, 98, 109, 154
crates/trogon-std/src/fs/system.rs                  29      12  58.62%   17-19, 31-45
crates/trogon-std/src/fs/mem.rs                    220      10  95.45%   61-63, 77-79, 133-135, 158
crates/trogon-nats/src/connect.rs                   96      16  83.33%   21-23, 36, 50, 69-152
crates/trogon-nats/src/auth.rs                     114       3  97.37%   49-51
crates/trogon-nats/src/messaging.rs                507      12  97.63%   14-16, 51-52, 135-140, 150-151, 203-205
crates/trogon-nats/src/mocks.rs                    256       0  100.00%
crates/trogon-nats/src/client.rs                    25      25  0.00%    47-86
crates/trogon-std/src/env/in_memory.rs              76       3  96.05%   48-50
crates/trogon-std/src/env/system.rs                 17       0  100.00%
TOTAL                                             4828      96  98.01%

Diff against main

Filename                                         Stmts    Miss  Cover
---------------------------------------------  -------  ------  --------
crates/acp-nats/src/nats/subjects.rs                +8       0  +100.00%
crates/acp-nats/src/agent/mod.rs                   -14       0  +100.00%
crates/acp-nats/src/agent/prompt.rs               +555       0  +100.00%
crates/acp-nats/src/agent/cancel.rs                 -2       0  +100.00%
crates/acp-nats/src/pending_prompt_waiters.rs     +112       0  +100.00%
crates/acp-nats/src/prompt_slot_counter.rs         +78       0  +100.00%
crates/acp-nats/src/config.rs                      +30       0  +100.00%
TOTAL                                             +767       0  +0.38%

Results for commit: ca5db16

Minimum allowed coverage is 90%

♻️ This comment has been updated with latest results

yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 24679d9 to 92fc3ba Compare February 28, 2026 04:53
yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 92fc3ba to 428aa3a Compare February 28, 2026 04:53
yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 428aa3a to 1e9de54 Compare February 28, 2026 04:58
yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 1e9de54 to 8d4c507 Compare February 28, 2026 05:03
yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 8d4c507 to dbab690 Compare February 28, 2026 05:05
Copy link

@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.

♻️ Duplicate comments (1)
rsworkspace/crates/acp-nats/src/agent/prompt.rs (1)

49-55: ⚠️ Potential issue | 🟠 Major

acp.request.count is double-recorded for invalid session IDs

Line 50-54 records a failed request inside map_err, and Line 182-186 records the request again for the same path. This inflates failed prompt counts.

💡 Suggested fix
             let session_id = AcpSessionId::try_from(&args.session_id).map_err(|e| {
-                bridge.metrics.record_request(
-                    "prompt",
-                    bridge.clock.elapsed(start).as_secs_f64(),
-                    false,
-                );
                 bridge.metrics.record_error("prompt", "invalid_session_id");
                 Error::new(
                     ErrorCode::InvalidParams.into(),
                     format!("Invalid session ID: {}", e),
                 )
             })?;

Also applies to: 182-186

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/acp-nats/src/agent/prompt.rs` around lines 49 - 55, The
code double-records failed requests when an invalid session ID occurs because
AcpSessionId::try_from(&args.session_id).map_err(...) records a failed request
via bridge.metrics.record_request/record_error inside the map_err closure and
the request is also recorded later (same path around the second block that calls
bridge.metrics.record_request for the prompt); remove the duplicate recording by
moving metric/error recording out of the map_err closure and instead return the
mapped error there, then ensure the single bridge.metrics.record_request and
bridge.metrics.record_error call path (the existing later block that handles
errors for the prompt) is the sole place that records metrics for this error, or
alternatively make the map_err closure only construct/return the error without
invoking bridge.metrics.* so the later error handler records it once.
🧹 Nitpick comments (2)
rsworkspace/crates/AGENTS.md (1)

3-3: Consider clarifying the export pattern for infallible or generic-error value objects.

The prescribed export pattern pub use {module}::{Type, TypeError} assumes every value object has an associated TypeError. However, some value objects might be infallible (e.g., validated at compile time via newtypes) or use generic error types like anyhow::Error.

Consider adding guidance on when to export just Type or alternative patterns for different error-handling strategies.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/AGENTS.md` at line 3, The guidance currently assumes every
value object exports both Type and TypeError (pub use {module}::{Type,
TypeError}), but some value objects are infallible (newtypes) or use generic
error types (e.g., anyhow::Error); update AGENTS.md to document export variants:
1) for infallible/newtype value objects export only Type (pub use
{module}::Type), 2) for objects with a module-local error type export both Type
and TypeError as before, and 3) for objects that use generic/shared error types
document exporting Type and optionally re-exporting the shared error alias
(e.g., pub use {module}::Type and pub use crate::errors::SharedError as
TypeError) or note not to re-export concrete anyhow::Error; reference the file
layout rule and lib.rs export examples (Type, TypeError) and add a short
decision rule for which pattern to use.
rsworkspace/crates/acp-nats/src/nats/subjects.rs (1)

18-20: Use value-object inputs for session_prompt

session_prompt accepts raw &str for both prefix and session id, which weakens the type guarantees already enforced elsewhere (AcpPrefix, session-id value object types).

As per coding guidelines, rsworkspace/crates/**/*.rs: Prefer domain-specific value objects over primitives (e.g. AcpPrefix not String).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/acp-nats/src/nats/subjects.rs` around lines 18 - 20,
Change session_prompt to take the domain value objects instead of raw &str:
replace the signature pub fn session_prompt(prefix: &str, session_id: &str) ->
String with one that accepts the domain types (e.g. &AcpPrefix and &SessionId or
other project-specific session-id value object). Inside session_prompt, use the
value-object accessors or Display/AsRef<str> impls (e.g. prefix.as_ref() or
format!("{}", prefix) and session_id.as_ref() or format!("{}", session_id)) to
compose the subject string ("{}.{}.agent.session.prompt"). Update any call sites
to pass the value objects instead of raw strings.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@rsworkspace/crates/acp-nats/src/agent/prompt.rs`:
- Around line 49-55: The code double-records failed requests when an invalid
session ID occurs because AcpSessionId::try_from(&args.session_id).map_err(...)
records a failed request via bridge.metrics.record_request/record_error inside
the map_err closure and the request is also recorded later (same path around the
second block that calls bridge.metrics.record_request for the prompt); remove
the duplicate recording by moving metric/error recording out of the map_err
closure and instead return the mapped error there, then ensure the single
bridge.metrics.record_request and bridge.metrics.record_error call path (the
existing later block that handles errors for the prompt) is the sole place that
records metrics for this error, or alternatively make the map_err closure only
construct/return the error without invoking bridge.metrics.* so the later error
handler records it once.

---

Nitpick comments:
In `@rsworkspace/crates/acp-nats/src/nats/subjects.rs`:
- Around line 18-20: Change session_prompt to take the domain value objects
instead of raw &str: replace the signature pub fn session_prompt(prefix: &str,
session_id: &str) -> String with one that accepts the domain types (e.g.
&AcpPrefix and &SessionId or other project-specific session-id value object).
Inside session_prompt, use the value-object accessors or Display/AsRef<str>
impls (e.g. prefix.as_ref() or format!("{}", prefix) and session_id.as_ref() or
format!("{}", session_id)) to compose the subject string
("{}.{}.agent.session.prompt"). Update any call sites to pass the value objects
instead of raw strings.

In `@rsworkspace/crates/AGENTS.md`:
- Line 3: The guidance currently assumes every value object exports both Type
and TypeError (pub use {module}::{Type, TypeError}), but some value objects are
infallible (newtypes) or use generic error types (e.g., anyhow::Error); update
AGENTS.md to document export variants: 1) for infallible/newtype value objects
export only Type (pub use {module}::Type), 2) for objects with a module-local
error type export both Type and TypeError as before, and 3) for objects that use
generic/shared error types document exporting Type and optionally re-exporting
the shared error alias (e.g., pub use {module}::Type and pub use
crate::errors::SharedError as TypeError) or note not to re-export concrete
anyhow::Error; reference the file layout rule and lib.rs export examples (Type,
TypeError) and add a short decision rule for which pattern to use.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92ef9e2 and 8d4c507.

📒 Files selected for processing (8)
  • rsworkspace/crates/AGENTS.md
  • rsworkspace/crates/acp-nats/src/agent/cancel.rs
  • rsworkspace/crates/acp-nats/src/agent/cancelled_sessions.rs
  • rsworkspace/crates/acp-nats/src/agent/mod.rs
  • rsworkspace/crates/acp-nats/src/agent/pending_prompt_waiters.rs
  • rsworkspace/crates/acp-nats/src/agent/prompt.rs
  • rsworkspace/crates/acp-nats/src/config.rs
  • rsworkspace/crates/acp-nats/src/nats/subjects.rs

yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from dbab690 to 3d26705 Compare February 28, 2026 05:24
yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 3d26705 to ce67f76 Compare February 28, 2026 05:28
yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from ce67f76 to b742439 Compare February 28, 2026 05:29
yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
yordis added a commit that referenced this pull request Feb 28, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 198b8bd to 1b74ca5 Compare February 28, 2026 21:38
yordis added a commit that referenced this pull request Mar 1, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 1b74ca5 to d3165d0 Compare March 1, 2026 19:21
yordis added a commit that referenced this pull request Mar 1, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from d3165d0 to 4624b7c Compare March 1, 2026 19:22
yordis added a commit that referenced this pull request Mar 2, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 4624b7c to 9ab1f21 Compare March 2, 2026 03:33
yordis added a commit that referenced this pull request Mar 2, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 9ab1f21 to e387fa8 Compare March 2, 2026 04:06
yordis added a commit that referenced this pull request Mar 2, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from e387fa8 to 29e63da Compare March 2, 2026 04:30
yordis added a commit that referenced this pull request Mar 2, 2026
- Add prompt handler with session validation, cancel pre-flight, backpressure
- Expand Bridge with CancelledSessions, PendingSessionPromptResponseWaiters
- Update cancel to mark sessions cancelled and resolve pending prompt waiters
- Add prompt_timeout and max_concurrent_client_tasks to config
- Add session_prompt NATS subject

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 29e63da to df2643c Compare March 2, 2026 04:34
yordis added a commit that referenced this pull request Mar 2, 2026
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from df2643c to 93ae914 Compare March 2, 2026 04:51
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

yordis added a commit that referenced this pull request Mar 2, 2026
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 93ae914 to 50e3211 Compare March 2, 2026 05:17
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/acp-nats-prompt branch from 50e3211 to ca5db16 Compare March 2, 2026 05:39
@yordis yordis merged commit 3af5a23 into main Mar 2, 2026
4 checks passed
@yordis yordis deleted the feat/acp-nats-prompt branch March 2, 2026 06:14
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