CXH-2196: stop dropping SendGrid teammate permissions on scope drift #40
All Vouch review confidence checks passed
Residual risk 0.40 = Change Risk (0.75) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #40"
general
weight: 0.35
c1-squire-dev[bot]
CXH-2196: stop dropping SendGrid teammate permissions on scope drift
Linear: CXH-2196
What was asked
teammateBuilder.Grantsresolved every teammate scope against a hand-maintained 197-entrySendGridScopesmap and silently skipped any scope the map did not contain (Debug log +continue). On the audited account the connector dropped 70 genuine permissions (an adminteammate reports 255 granted scopes; C1 emitted 178) — including
sso.settings.andteammates.— with nothing above debug level to indicate it, because the map's premise("Sendgrid does not provide an api to list scopes") was false:
GET /v3/scopesexists. Theticket also appended a second defect to fix in the same change: the error surface mangled
or dropped vendor error detail (literal
.jsonin field error text, flat{"message"}envelopes silently ignored, error-status bodies decoded into success targets).
What changed
pkg/connector/teammates.go). Every scope stringSendGrid reports on a teammate is emitted as a grant — including scopes absent from both
the static floor and
GET /v3/scopes. The only non-emission path is an explicit,documented rule for SendGrid's non-grantable account/UI state flags (
2fa_exempt,2fa_required,sender_verification_eligible,signup.trigger_confirmation,ui.),logged once per teammate at Debug naming the rule. The
skipping unknown scopedrop pathno longer exists.
pkg/connector/scopes.go,client/client.go,models/models.go,connector.go). New client methodGetScopes(GET
v3/scopes; response shape per the Twilio doc: a single-page string array).scopeBuilder.Listemits the sorted union of the compatibility floor with the liveresponse, so the catalog is additive-only by construction:
/v3/scopesis key-scoped, andon a restricted key the floor guarantees today's 197 resources never disappear. A
GetScopesfailure fails the sync with a wrappedbaton-sendgrid:error — no floorfallback, no partial catalog with a nil error. The floor's false-premise comment is
rewritten to state its new role.
doRequest(pkg/connector/client/client.go).The response body is read once; error-status bodies are parsed as errors and never decoded
into the call's success target; a 2xx with an undecodable body returns a wrapped error,
never a silent empty result; the vendor envelope (flat
{"message"}and fielded{"errors":[…]}) is parsed for EVERY non-2xx status and joined onto the uhttp-classifiederror — preserving
status.Code(err)(pinned SDK mapping verified in source: 429 and all5xx →
codes.Unavailable, 501 →Unimplemented). The literal.jsonno longer appearsin field error text;
CustomErrnow implementserrorcorrectly.docs/connector.mdx): teammate grants mirror all reported scopes; the scopecatalog is refreshed from
GET /v3/scopesunioned with the built-in baseline.client_test.go(error surface: flat/fieldedenvelopes, 401 body never lands in the success struct, 429/503 detail joined with correct
gRPC codes, 2xx decode failure),
scopes_test.go(union semantics, floor survives anarrow live list,
GetScopesfailure propagates),teammates_test.go(fixture teammatecarrying the documented dropped families —
billing.create(in the compatibility floor,absent from live
GET /v3/scopes) andemail_testing(absent from both the floor andthe live response) — emits grants, with the grant-discovered off-catalog scope resource
inserted via the
InsertResourceGrantsresponse annotation; pseudo-flags excluded withthe documented message; zero
skipping unknown scopeentries).Breaking-change assessment (BP4)
scope string (derived by
scopeResource); the assignment entitlement slugassignedisunchanged; no resource type, entitlement, or identifier is removed or renamed.
previously-dropped scopes appear as NEW resources and grants. No migration path needed.
GET /v3/scopesbecomesa hard sync dependency: an API key that cannot call it now fails a sync that previously
"succeeded" with a silently wrong catalog. That is the requested trade (fail loudly, never
drift silently), and it is documented in
docs/connector.mdx.How far this is verified
validate-changes.sh(scoped build/vet/test over thetouched packages) passes on the final head;
check-kind-rules.shreports 0 violations,0 hints.
none blocking).
+5 grants vs
main, replayed against a doc-derived mock recording (the mock isdeliberately thin, so the gains prove the mechanism, not the audited account's numbers).
cmd/baton-sendgridbuilds and starts. NOTE: this repo declares no mock, sono sync was exercised by the smoke gate — the change is unproven against a live or mocked
upstream by the smoke itself; the advisory eval replay and the tester's real mock syncs
(below) are the sync evidence this batch has, and no live SendGrid account was exercised
in this batch.
evidence from real syncs against the doc-derived mock (scope grants 8 → 13 on the
fixtures with 0 lost; union catalog 197 → 220; pseudo-flags excluded with the documented
log; crafted 401/400 error scenarios carrying the vendor reason with zero
.jsonoccurrences; zero
skipping unknown scopelines). Mock-based only; the tester's cloneshares this repo's CI toolchain state, not a clean room.
seen none of the batch) found two real defects —
sender_verification_legacymissingfrom the exclusion set (the Twilio doc lists eight auto-added non-grantable flags; the
set covered seven) and a silent-success path on a degenerate empty-body 200 (the
mass-revocation class) — both fixed, with the fix's own regression caught and repaired
(
res != nildecode guard restored for the nil-target provisioning calls). Round 2verified the fixes and one doc-citation nit was corrected.
every review thread answered and resolved.
What to look at hardest
1.
,GET /v3/scopesas a new hard sync dependency — scoped-down API keys (403 on theendpoint) now fail the sync by design. If that turns out to be common in production,
that is a new decision with new evidence, not something to pre-hedge here.
2. The pseudo-flag exclusion set is hand-maintained (
2fa_ui.*,sender_verification_eligible,signup.trigger_confirmation). The failure directionafter this change is "one extra visible grant", never a missing permission; extending the
set is a one-line map edit.
3. Error-text changes — vendor detail is now joined onto error messages for every
non-2xx status (previously dropped for 429/5xx); anything matching exact error strings
will see new text.
status.Code(err)behavior is preserved.