Skip to content

feat(acp-nats): add GLOBAL JetStream stream for global agent subjects#70

Merged
yordis merged 1 commit into
mainfrom
feat/global-jetstream-stream
Mar 31, 2026
Merged

feat(acp-nats): add GLOBAL JetStream stream for global agent subjects#70
yordis merged 1 commit into
mainfrom
feat/global-jetstream-stream

Conversation

@yordis
Copy link
Copy Markdown
Member

@yordis yordis commented Mar 31, 2026

Summary

  • Add a fifth JetStream stream (GLOBAL) capturing global agent subjects: initialize, authenticate, session.new, and ext.> for audit durability
  • session.list remains on Core NATS only — pure read query with no replay value
  • Subjects are enumerated explicitly (not agent.>) to exclude session.list, since JetStream does not support subject exclusions

@cursor
Copy link
Copy Markdown

cursor Bot commented Mar 31, 2026

PR Summary

Medium Risk
Medium risk because it changes JetStream stream provisioning and subject routing, which can affect message durability and storage/retention behavior in production.

Overview
Adds a fifth JetStream stream, GLOBAL, and includes it in all_configs() so provisioning now creates five streams.

GLOBAL captures explicitly enumerated non-session agent subjects (e.g. agent.initialize, agent.authenticate, agent.session.new, agent.ext.>) and avoids broad agent.> coverage; tests are updated/added to assert the new stream name, subjects, and updated stream counts/idempotency.

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f7bc6b00-2677-4129-bd1a-ca8121a6967b

📥 Commits

Reviewing files that changed from the base of the PR and between c689960 and 3ded4c8.

📒 Files selected for processing (2)
  • rsworkspace/crates/acp-nats/src/jetstream/provision.rs
  • rsworkspace/crates/acp-nats/src/jetstream/streams.rs
✅ Files skipped from review due to trivial changes (1)
  • rsworkspace/crates/acp-nats/src/jetstream/provision.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • rsworkspace/crates/acp-nats/src/jetstream/streams.rs

Walkthrough

A new JetStream GLOBAL stream configuration and helpers were added; all_configs() now returns 5 stream configs instead of 4. Unit tests in provisioning were updated to expect the additional stream and assert the presence of the ACP_GLOBAL stream. No production provisioning logic changes.

Changes

Cohort / File(s) Summary
New Global Stream Configuration
rsworkspace/crates/acp-nats/src/jetstream/streams.rs
Added pub fn global_stream_name(prefix: &str) -> String and pub fn global_config(prefix: &str) -> Config. all_configs(prefix) changed to return 5 configs (was 4). New GLOBAL stream uses file storage, Limits retention, DEFAULT_STREAM_MAX_AGE, Old discard, and subjects for agent init/auth, sessions, and extensions. Unit tests updated/added to validate name, subjects, storage, retention, and max-age.
Test Expectations Update
rsworkspace/crates/acp-nats/src/jetstream/provision.rs
Updated tests to expect 5 created streams (was 4), assert ACP_GLOBAL stream name presence, and adjust idempotency expectation to 10 total streams after double provisioning (was 8). No runtime/provision_streams implementation changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A global stream now flows so wide,
Five configs hop and line up side by side,
Agents whisper on their newfound lane,
Tests updated, provision calls remain sane,
Hooray — I nibble code and dance again! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.71% 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 clearly and specifically describes the main change: adding a GLOBAL JetStream stream for global agent subjects.
Description check ✅ Passed The description is well-related to the changeset, explaining the purpose, subjects included, and reasoning for explicit enumeration.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/global-jetstream-stream

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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 31, 2026

badge

Code Coverage Summary

Details
Filename                                                     Stmts    Miss  Cover    Missing
---------------------------------------------------------  -------  ------  -------  ---------------------------------------------------------------------------------------------
crates/acp-nats-agent/src/connection.rs                       1356       9  99.34%   472, 669-671, 678, 1826-1827, 1840-1841
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-std/src/time/mock.rs                             123       0  100.00%
crates/trogon-std/src/time/system.rs                            24       0  100.00%
crates/acp-nats/src/acp_prefix.rs                               63       0  100.00%
crates/acp-nats/src/lib.rs                                      73       0  100.00%
crates/acp-nats/src/ext_method_name.rs                          85       0  100.00%
crates/acp-nats/src/config.rs                                  201       0  100.00%
crates/acp-nats/src/in_flight_slot_guard.rs                     32       0  100.00%
crates/acp-nats/src/pending_prompt_waiters.rs                  112       0  100.00%
crates/acp-nats/src/session_id.rs                               88       0  100.00%
crates/acp-nats/src/client_proxy.rs                            196       0  100.00%
crates/acp-nats/src/jsonrpc.rs                                   6       0  100.00%
crates/acp-nats/src/error.rs                                    84       0  100.00%
crates/trogon-std/src/args.rs                                   10       0  100.00%
crates/trogon-std/src/json.rs                                   30       0  100.00%
crates/acp-nats-stdio/src/config.rs                             72       0  100.00%
crates/acp-nats-stdio/src/main.rs                              113      11  90.27%   58, 106-113, 119-121, 138
crates/acp-nats/src/telemetry/metrics.rs                        65       0  100.00%
crates/trogon-nats/src/jetstream/traits.rs                      96       0  100.00%
crates/trogon-nats/src/jetstream/mocks.rs                      435       0  100.00%
crates/acp-nats/src/nats/token.rs                                8       0  100.00%
crates/acp-nats/src/nats/subjects.rs                           294       0  100.00%
crates/acp-nats/src/nats/extensions.rs                           3       0  100.00%
crates/acp-nats/src/nats/parsing.rs                            280       1  99.64%   151
crates/acp-nats/src/client/ext_session_prompt_response.rs      150       0  100.00%
crates/acp-nats/src/client/terminal_output.rs                  223       0  100.00%
crates/acp-nats/src/client/session_update.rs                    55       0  100.00%
crates/acp-nats/src/client/terminal_release.rs                 357       0  100.00%
crates/acp-nats/src/client/ext.rs                              365       8  97.81%   193-204, 229-240
crates/acp-nats/src/client/terminal_wait_for_exit.rs           396       0  100.00%
crates/acp-nats/src/client/rpc_reply.rs                         71       0  100.00%
crates/acp-nats/src/client/request_permission.rs               338       0  100.00%
crates/acp-nats/src/client/fs_read_text_file.rs                384       0  100.00%
crates/acp-nats/src/client/terminal_kill.rs                    309       0  100.00%
crates/acp-nats/src/client/fs_write_text_file.rs               451       0  100.00%
crates/acp-nats/src/client/mod.rs                             2981       0  100.00%
crates/acp-nats/src/client/terminal_create.rs                  294       0  100.00%
crates/acp-nats/src/jetstream/ext_policy.rs                     26       0  100.00%
crates/acp-nats/src/jetstream/consumers.rs                      76       0  100.00%
crates/acp-nats/src/jetstream/streams.rs                       227       0  100.00%
crates/acp-nats/src/jetstream/provision.rs                      57       0  100.00%
crates/acp-telemetry/src/signal.rs                               3       3  0.00%    4-43
crates/acp-telemetry/src/metric.rs                              35       4  88.57%   30-31, 38-39
crates/acp-telemetry/src/log.rs                                 70       2  97.14%   39-40
crates/acp-telemetry/src/trace.rs                               32       4  87.50%   23-24, 31-32
crates/acp-telemetry/src/service_name.rs                        16       0  100.00%
crates/acp-telemetry/src/lib.rs                                153      22  85.62%   39-46, 81, 86, 91, 105-120
crates/acp-nats/src/agent/bridge.rs                            142      13  90.85%   171-183
crates/acp-nats/src/agent/prompt.rs                           1085       1  99.91%   144
crates/acp-nats/src/agent/mod.rs                                61       0  100.00%
crates/acp-nats/src/agent/set_session_mode.rs                   79       0  100.00%
crates/acp-nats/src/agent/ext_method.rs                         92       0  100.00%
crates/acp-nats/src/agent/cancel.rs                            104       0  100.00%
crates/acp-nats/src/agent/ext_notification.rs                   88       0  100.00%
crates/acp-nats/src/agent/initialize.rs                         82       0  100.00%
crates/acp-nats/src/agent/js_request.rs                        296       0  100.00%
crates/acp-nats/src/agent/resume_session.rs                    113       0  100.00%
crates/acp-nats/src/agent/test_support.rs                      267       0  100.00%
crates/acp-nats/src/agent/close_session.rs                      72       0  100.00%
crates/acp-nats/src/agent/load_session.rs                      114       0  100.00%
crates/acp-nats/src/agent/fork_session.rs                      117       0  100.00%
crates/acp-nats/src/agent/new_session.rs                        91       0  100.00%
crates/acp-nats/src/agent/set_session_config_option.rs          76       0  100.00%
crates/acp-nats/src/agent/set_session_model.rs                  76       0  100.00%
crates/acp-nats/src/agent/authenticate.rs                       52       0  100.00%
crates/acp-nats/src/agent/list_sessions.rs                      50       0  100.00%
crates/trogon-std/src/env/system.rs                             17       0  100.00%
crates/trogon-std/src/env/in_memory.rs                          81       0  100.00%
crates/trogon-nats/src/mocks.rs                                304       0  100.00%
crates/trogon-nats/src/connect.rs                               96      16  83.33%   22-24, 37, 49, 68-151
crates/trogon-nats/src/client.rs                                25      25  0.00%    50-89
crates/trogon-nats/src/auth.rs                                 114       3  97.37%   45-47
crates/trogon-nats/src/messaging.rs                            533       4  99.25%   141-146, 156-157
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/acp-nats-ws/src/config.rs                                83       0  100.00%
crates/acp-nats-ws/src/upgrade.rs                               57       2  96.49%   59, 90
crates/acp-nats-ws/src/main.rs                                 157       2  98.73%   84, 247
crates/acp-nats-ws/src/connection.rs                           162      35  78.40%   71-78, 83-94, 110, 112-113, 118, 129-131, 138, 142, 146, 149-157, 168, 172, 175, 178-182, 216
TOTAL                                                        16035     198  98.77%

Diff against main

Filename                                      Stmts    Miss  Cover
------------------------------------------  -------  ------  --------
crates/acp-nats/src/jetstream/streams.rs        +51       0  +100.00%
crates/acp-nats/src/jetstream/provision.rs       +1       0  +100.00%
crates/acp-nats/src/agent/prompt.rs               0      -1  +0.09%
TOTAL                                           +52      -1  +0.01%

Results for commit: 3ded4c8

Minimum allowed coverage is 95%

♻️ This comment has been updated with latest results

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.

🧹 Nitpick comments (1)
rsworkspace/crates/acp-nats/src/jetstream/streams.rs (1)

270-282: Consider enhancing overlap detection to handle wildcard semantics.

The current test only checks for exact string duplicates. While the existing streams are designed with non-overlapping namespaces (session-scoped vs. global agent subjects), this wouldn't catch semantic overlaps if wildcards were introduced that could match the same concrete subjects.

For example, if a future change added {prefix}.agent.> to one stream, it could overlap with {prefix}.agent.ext.> in GLOBAL. The current test would pass but JetStream would route messages to both streams.

This is low priority since the current subject design is safe, but a more robust check could prevent accidental overlaps in future changes.

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

In `@rsworkspace/crates/acp-nats/src/jetstream/streams.rs` around lines 270 - 282,
The test no_subject_overlaps_between_streams currently only checks exact string
equality for subjects; update it to detect semantic overlaps under NATS wildcard
rules by adding a helper (e.g., subject_matches(pattern: &str, concrete: &str)
and patterns_overlap(a: &str, b: &str)) and use these in the test that iterates
all_subjects to assert that no pair of patterns can match the same concrete
subject (check both subject_matches(a,b) || subject_matches(b,a) or a dedicated
patterns_overlap(a,b)). Locate the test and the all_subjects collection and
replace the assert_ne! check with calls to the new helper(s) or use an existing
nats wildmatch utility to ensure wildcard patterns like "foo.>" and "foo.bar.>"
are detected as overlapping.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@rsworkspace/crates/acp-nats/src/jetstream/streams.rs`:
- Around line 270-282: The test no_subject_overlaps_between_streams currently
only checks exact string equality for subjects; update it to detect semantic
overlaps under NATS wildcard rules by adding a helper (e.g.,
subject_matches(pattern: &str, concrete: &str) and patterns_overlap(a: &str, b:
&str)) and use these in the test that iterates all_subjects to assert that no
pair of patterns can match the same concrete subject (check both
subject_matches(a,b) || subject_matches(b,a) or a dedicated
patterns_overlap(a,b)). Locate the test and the all_subjects collection and
replace the assert_ne! check with calls to the new helper(s) or use an existing
nats wildmatch utility to ensure wildcard patterns like "foo.>" and "foo.bar.>"
are detected as overlapping.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a4114f6f-e5e2-4ea9-a0d8-1c35f161d7c9

📥 Commits

Reviewing files that changed from the base of the PR and between 8dc7e33 and c689960.

📒 Files selected for processing (2)
  • rsworkspace/crates/acp-nats/src/jetstream/provision.rs
  • rsworkspace/crates/acp-nats/src/jetstream/streams.rs

Captures initialize, authenticate, session.new, and ext.> into
JetStream for audit durability. session.list stays on Core NATS
as a pure read with no replay value.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis force-pushed the feat/global-jetstream-stream branch from c689960 to 3ded4c8 Compare March 31, 2026 16:50
@yordis yordis merged commit 9962576 into main Mar 31, 2026
7 checks passed
@yordis yordis deleted the feat/global-jetstream-stream branch March 31, 2026 16:56
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