Skip to content

feat(output): change resubscription method#1011

Open
Molter73 wants to merge 1 commit into
mainfrom
mauro/feat/resubscription-change
Open

feat(output): change resubscription method#1011
Molter73 wants to merge 1 commit into
mainfrom
mauro/feat/resubscription-change

Conversation

@Molter73

@Molter73 Molter73 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Description

The new way for output components to resubscribe the broadcast channel distributing events is to send a oneshot sender back to the main task which will resubscribe from the broadcast sender and forward the receiver back.

While this approach might seem overly complicated, it ensures there will be no lingering receivers laying around, which in turn allows for Arc::unwrap_or_clone to properly unwrap all messages when only one output is in use.

Checklist

  • Patch has a change log entry OR does not need one.
  • Investigated and inspected CI test results
  • Updated documentation accordingly

Automated testing

  • Added unit tests
  • Added integration tests
  • Added regression tests

If any of these don't apply, please comment below.

Testing Performed

Used the changes from #1010 to run fact under DHAT with and without these changes. Without these changes the call to Arc::unwrap_or_clone in fact/src/output/grpc.rs is showing up as making a clone, with the changes this doesn't happen anymore.

@Molter73 Molter73 requested a review from a team as a code owner July 7, 2026 14:16
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The gRPC output client now requests a fresh broadcast receiver per connection through an mpsc/oneshot handshake. The output module adds an EventReceiver alias and subscription servicing, and the stdout client switches to the new receiver type.

Changes

Subscriber-based event receiver plumbing

Layer / File(s) Summary
EventReceiver alias and subscription channel wiring
fact/src/output/mod.rs
Adds EventReceiver type alias, creates an mpsc subscription channel passed into grpc::Client::new, starts stdout directly with broad_rx, extends the select loop to service subscription requests by subscribing per-request, and revises task termination/error handling (Ok(()) vs bail!).
gRPC Client subscriber field and stream setup
fact/src/output/grpc.rs
Replaces stored broadcast::Receiver with subscriber: mpsc::Sender<oneshot::Sender<EventReceiver>> in Client/Client::new, and updates run() to request an EventReceiver via oneshot before wrapping it in BroadcastStream, preserving lag/metrics handling.
stdout Client type update
fact/src/output/stdout.rs
Updates Client's rx field and Client::new parameter from broadcast::Receiver<Arc<Event>> to EventReceiver, removing now-unused imports.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: JoukoVirtanen, Stringy

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately describes the main change to output resubscription behavior.
Description check ✅ Passed The description follows the template with a clear summary, checklist, and testing notes, with only documentation left unchecked.
✨ 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 mauro/feat/resubscription-change

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

@codecov-commenter

codecov-commenter commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.64%. Comparing base (baebc56) to head (c98bda1).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
fact/src/output/grpc.rs 0.00% 15 Missing ⚠️
fact/src/output/mod.rs 0.00% 14 Missing ⚠️
fact/src/output/stdout.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1011      +/-   ##
==========================================
- Coverage   33.85%   32.64%   -1.21%     
==========================================
  Files          21       21              
  Lines        2812     2916     +104     
  Branches     2812     2916     +104     
==========================================
  Hits          952      952              
- Misses       1857     1961     +104     
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@fact/src/output/mod.rs`:
- Around line 60-65: The `tokio::select!` branch in `output::mod::start` that
reads from `subs_rx.recv()` should treat a closed subscription channel as
terminal instead of continuing. Update the `req = subs_rx.recv()` handling so
`None` breaks the loop or returns an error/finished state, and keep the existing
`req.send(rx)` path for valid requests. This prevents the `subs_rx` branch from
becoming immediately ready forever and lets the output task shut down cleanly.
🪄 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: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: 3b392f6c-31a6-4820-9a4e-d01a8281fa7f

📥 Commits

Reviewing files that changed from the base of the PR and between 17d94b4 and c51ec30.

📒 Files selected for processing (3)
  • fact/src/output/grpc.rs
  • fact/src/output/mod.rs
  • fact/src/output/stdout.rs

Comment thread fact/src/output/mod.rs
The new way for output components to resubscribe the broadcast channel
distributing events is to send a oneshot sender back to the main task
which will resubscribe from the broadcast sender and forward the
receiver back.

While this approach might seem overly complicated, it ensures there will
be no lingering receivers laying around, which in turn allows for
Arc::unwrap_or_clone to properly unwrap all messages when only one
output is in use.
@Molter73 Molter73 force-pushed the mauro/feat/resubscription-change branch from c51ec30 to c98bda1 Compare July 7, 2026 15:21
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.

2 participants