feat(trogon-source-linear): publish unroutable payloads to DLQ#97
feat(trogon-source-linear): publish unroutable payloads to DLQ#97
Conversation
PR SummaryMedium Risk Overview This introduces a Reviewed by Cursor Bugbot for commit 65d9885. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 16 minutes and 34 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
WalkthroughThe changes extend the Linear webhook handler to route validation failures to a dedicated NATS subject. A new constant defines the rejection reason header, crate documentation describes the new routing behavior for unroutable messages, and server logic adds a publish helper and validation failure handlers. Changes
Sequence DiagramsequenceDiagram
participant Client as Webhook Client
participant Server as Linear Handler
participant NATS as NATS Stream
Client->>Server: POST webhook payload
alt Signature Valid
alt Validation Passes
Server->>NATS: Publish to linear.event
NATS-->>Server: Ack
Server-->>Client: 200 OK
else Validation Fails
rect rgba(220, 53, 69, 0.5)
Note over Server: Invalid JSON, stale timestamp,<br/>missing/invalid type or action
Server->>NATS: publish_unroutable(body, reason)
NATS-->>Server: Ack
Server-->>Client: 400 BAD_REQUEST
end
end
else Signature Invalid
Server-->>Client: 401 UNAUTHORIZED
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Code Coverage SummaryDetailsDiff against mainResults for commit: 65d9885 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
rsworkspace/crates/trogon-source-linear/src/lib.rs (1)
20-23: Consider linking docs to the exported constant name.Using a rustdoc link (e.g.
[`crate::constants::NATS_HEADER_REJECT_REASON`]) instead of a raw header literal would reduce future drift.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@rsworkspace/crates/trogon-source-linear/src/lib.rs` around lines 20 - 23, Replace the raw header literal in the crate-level doc comment with a rustdoc link to the exported constant to avoid drift: change the `{LINEAR_SUBJECT_PREFIX}.unroutable` doc or the `X-Linear-Reject-Reason` literal to use a link like [`crate::constants::NATS_HEADER_REJECT_REASON`] (reference the existing constant name NATS_HEADER_REJECT_REASON) so the documentation points to the canonical constant; update the doc comment in lib.rs accordingly.
🤖 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/trogon-source-linear/src/server.rs`:
- Around line 66-79: publish_unroutable currently swallows DLQ publish failures
by only logging outcome.log_on_error and the outer request handlers still return
400, which discards payloads when the DLQ is unavailable; change
publish_unroutable (and each validation-failure branch that calls it) to
propagate the publish outcome so callers can map a DLQ publish failure to a 500
instead of always returning 400: have publish_unroutable return a Result<(),
PublishError> (or the existing Outcome type) from publish_event rather than
void, surface that Result back to the request handler, and in the handlers where
publish_unroutable is invoked (the validation-failure branches that call
publish_event/publish_unroutable) convert an Err into an internal-server-error
response while still returning 400 for validation errors only when the DLQ
publish succeeded; keep logging via outcome.log_on_error but don't treat logging
as sufficient error handling.
- Around line 66-70: Replace the raw &str "reason" with a domain-specific
RejectReason enum/value object and update call sites: change the
publish_unroutable<P: JetStreamPublisher>(..., reason: &str, ...) signature to
accept a RejectReason (or &RejectReason) and implement conversion to the wire
string (Display/ToString or as_str) inside publish_unroutable; add a
RejectReason enum (with all allowed variants used at current call sites) and
factory/functions for construction so invalid reasons are unrepresentable, then
update every site that currently passes string literals (the call sites around
the ranges listed) to use the corresponding RejectReason variant or constructor
and ensure any serialization uses the enum’s string form when publishing.
---
Nitpick comments:
In `@rsworkspace/crates/trogon-source-linear/src/lib.rs`:
- Around line 20-23: Replace the raw header literal in the crate-level doc
comment with a rustdoc link to the exported constant to avoid drift: change the
`{LINEAR_SUBJECT_PREFIX}.unroutable` doc or the `X-Linear-Reject-Reason` literal
to use a link like [`crate::constants::NATS_HEADER_REJECT_REASON`] (reference
the existing constant name NATS_HEADER_REJECT_REASON) so the documentation
points to the canonical constant; update the doc comment in lib.rs accordingly.
🪄 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: CHILL
Plan: Pro
Run ID: 113f1821-8b52-4bfd-89aa-95df60273b0b
📒 Files selected for processing (3)
rsworkspace/crates/trogon-source-linear/src/constants.rsrsworkspace/crates/trogon-source-linear/src/lib.rsrsworkspace/crates/trogon-source-linear/src/server.rs
81305ca to
f1a5abf
Compare
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
f1a5abf to
65d9885
Compare
Summary
{prefix}.unroutableDLQ pattern already used by trogon-source-slack, publishing rejected payloads tolinear.unroutablewith anX-Linear-Reject-Reasonheader