fix(gl): only report registered: false on 404 in whoami (#220)#223
fix(gl): only report registered: false on 404 in whoami (#220)#223Gravirei wants to merge 5 commits into
Conversation
|
Thanks for the contribution. A couple of things will help us review this faster:
See CONTRIBUTING.md. Update the PR and these notes will clear automatically. |
|
Warning Review limit reached
Next review available in: 1 minute Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesAgent lookup error handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
jatmn
left a comment
There was a problem hiding this comment.
I found issues that need to be addressed before this is ready.
Findings
-
[P1] Bound and sanitize the node-supplied error body before displaying it
crates/gl/src/whoami.rs:59
This new branch callsResponse::json()on every non-404 response and interpolates the remotemessagedirectly into the CLI error. A node chosen via--node/GITLAWB_NODEcan return a huge JSON body, which reqwest buffers in full before parsing, exhausting the CLI's memory; it can also put ANSI/OSC or bidi controls inmessage, which are decoded and emitted to the terminal. This is newly reachable because the previous code discarded error bodies. Use the existing capped-read and terminal-sanitization pattern insync.rs(and add hostile-body/control-character coverage) before including any remote text in the diagnostic. -
[P2] Do not treat every route-level 404 as proof of an unregistered identity
crates/gl/src/whoami.rs:54
A 404 also occurs whenGITLAWB_NODEpoints at an older node or a wrong/misrouted server that does not implement/api/v1/agents/{did}. In that case this command still emitsregistered: false, recreating the false verdict the PR is intended to eliminate.gl agent showalready recognizes this ambiguity and tells the user the node may not support the agents API. Preserve that distinction here (or otherwise verify endpoint support) rather than treating an undifferentiated 404 as an authoritative registration result.
36eadc5 to
cec0c8b
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/gl/src/whoami.rs (1)
246-248: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the response-message contract.
These tests only verify the status. Also assert
"forbidden"and"internal error"so they protect the required status-and-message error output.Also applies to: 273-275
🤖 Prompt for 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. In `@crates/gl/src/whoami.rs` around lines 246 - 248, Update the error assertions in the tests around run(args).await.unwrap_err() to verify the response message includes the required text in addition to status 403. Assert that the formatted error contains both “forbidden” and “internal error”, preserving the existing diagnostic output for failures.
🤖 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 `@crates/gl/src/whoami.rs`:
- Around line 55-60: Update the 404 response branch in the whoami request
handling to set registered = Some(false) and continue through the successful
result path instead of calling bail!. Restore
test_whoami_with_node_not_registered to assert a successful response with the
agent marked unregistered, replacing its unwrap_err() expectation.
---
Nitpick comments:
In `@crates/gl/src/whoami.rs`:
- Around line 246-248: Update the error assertions in the tests around
run(args).await.unwrap_err() to verify the response message includes the
required text in addition to status 403. Assert that the formatted error
contains both “forbidden” and “internal error”, preserving the existing
diagnostic output for failures.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 74b2127a-1bdd-4210-9b87-b9fa1244aeea
📒 Files selected for processing (2)
crates/gl/src/sync.rscrates/gl/src/whoami.rs
jatmn
left a comment
There was a problem hiding this comment.
I found issues that need to be addressed before this is ready.
Findings
- [P2] Do not treat an undifferentiated 404 as proof of an unregistered identity
crates/gl/src/whoami.rs:55
This endpoint-level 404 is also what an older node, a reverse-proxy mistake, or another misroutedGITLAWB_NODEreturns when/api/v1/agents/{did}is not implemented.gl whoamitherefore exits successfully and emitsregistered: falsefor an identity whose registration was never queried—the false verdict this change is intended to eliminate.gl agent showalready preserves this ambiguity for the identical route; retain that error path here (or establish endpoint support before reportingfalse) and cover the unsupported-node case separately from a genuine missing agent.
Summary
gl whoaminow only reportsregistered: falseon a genuine 404. All other non-2xx responses (403, 429, 5xx) and transport failures surface an error instead of fabricating an unregistered verdict.Motivation & context
Closes #220
gl whoamirouted every non-2xx response and transport error toregistered = Some(false), meaning a 403/429/5xx or network failure for an existing identity was presented as unregistered. Only a 404 fromGET /api/v1/agents/{did}means the agent does not exist.Kind of change
What changed
crates/gl/src/whoami.rs— split the match arm in the agent lookup:404→registered = Some(false)(agent not found on node)How a reviewer can verify
cargo test -p gl -- whoamiAll 269 tests pass.
Before you request review
cargo test --workspacepasses locallycargo fmt --allandcargo clippy --workspace --all-targets -- -D warningsare cleanfix(...))Summary by CodeRabbit