← Back to Pull requests

CXH-144: do not fail the PagerDuty sync on 404 schedule-not-found #39

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 31, 2026 19:17 UTC
Author

PagerDuty schedules can be deleted while a sync is running. Until now that
failed the whole sync with a 404 "Schedule Not Found" error, and the only
recovery was re-running it from the support dashboard. A schedule that stops
resolving between the connector's list phase and its per-schedule grants phase
is a normal race, not a broken credential or a dead API — this change treats
it that way: the connector now skips the vanished schedule's on-call grants
and finishes the sync. Everything the ticket asked for in one sentence: we
should not error on 404.

Linear: CXH-144

What was asked

The Gemini_Trust tenant's sync failed listing on-call users with 404 "Schedule
Not Found" (tenant 35elOxCryc76IdzTjP9zdPIttUF, app 36ZPL4Yfh2Yt9UJQUBZhXiin5Io).
The issue was only recoverable by manually re-running the sync from the support
dashboard. The acceptance bar from the ticket: a 404 on that listing must not
fail the sync — handle it gracefully so no dashboard re-run is needed.

What changed

The fix follows the connector's own error-handling rules
(patterns-error-handling.md Rule 4, ci-review.md S5/S6): a 404 may be
skipped only when it is about the item being fetched, and only once the
vendor's 404 semantics are established in the code. Both halves are in the
diff.

pkg/connector/errors.go

Where: notFoundOnItem ~L39-52, after wrapPagerDutyError ~L13

What changed

  • One new helper: notFoundOnItem(err) wraps errors.As into

  • pagerduty.APIError and apiErr.NotFound(), which the vendored SDK
    (go-pagerduty v1.8.0, client.go:234-237) defines as HTTP 404 OR vendor
    error code 2100.
  • Its doc comment is the canonical statement of PagerDuty's 404 semantics:

  • 404 means the addressed object is gone; permission denial is 403. It
    cross-references wrapPagerDutyError, which already maps the same
    predicate to gRPC codes.NotFound. wrapPagerDutyError itself is
    unchanged.

    Why

  • The vendor-404 determination is the load-bearing fact behind any skip

  • guard: on APIs that answer 404 for authorization failures (GitHub, some
    SCIM servers), a 404 skip silently wipes data. Establishing it once in a
    named, tested helper keeps the guard honest and makes the next call site
    with the same shape a two-line change.

    pkg/connector/schedule.go

    Where: Grants guard ~L183-196, at the ListOnCallUsersWithContext ~L176
    error branch

    What changed

  • The unconditional return wrapPagerDutyError("failed to list on-call

  • users", err)
    became a two-way branch: on a genuine 404, one Debug log line
    naming the schedule, then return rv, "", nil, nil — the member grants
    already built from the resource profile still emit; only the on-call grants
    of the vanished schedule are dropped. Every other error still fails the
    sync through wrapPagerDutyError unchanged.
  • The call-site comment records why a 404 here is necessarily about this

  • schedule: the call is a single-object GET of /schedules/{id}/users, so
    there is no second object the 404 could be about.

    Why

  • A deleted schedule legitimately has no on-call users; emitting without it

  • is the correct state, and returning the error (the old behavior) fails the
    whole sync and buckets nothing. Skipping on any other error class would be
    the destructive shape — a 401/403/429 might be about every schedule on the
    page — so they keep failing.

    pkg/connector/user.go

    Where: Delete ~L185

    What changed

  • user.Delete's inline 404 guard now calls the shared notFoundOnItem helper instead of duplicating the predicate inline — behavior-identical. This is the diff's only provisioning-path touch outside the schedule seam.
  • Why

  • The helper exists so the next call site with the same shape is a two-line change; Delete was that next call site.
  • pkg/connector/errors_test.go and pkg/connector/schedule_test.go (new)

    Where: TestNotFoundOnItem ~L45; TestScheduleResourceType_Grants ~L83;
    both reuse the existing newMockServer httptest pattern

    What changed

  • Table-driven predicate test: HTTP 404 and API code 2100 (including 2100 on

  • a non-404 HTTP status, isolating the SDK's code arm) are skippable; 403,
    429, 500, a non-APIError, and nil are not.
  • End-to-end Grants test through a real SDK client against a mock server:

  • 404 on the on-call endpoint returns the member grants with a nil error and
    no on-call grant; 500 surfaces as Unavailable, 401 as Unauthenticated,
    403 as PermissionDenied.
  • A zapcore-backed log assertion verifies the skip logs exactly one DEBUG

  • line and no ERROR/WARN — the log-level contract is pinned, not just
    claimed.

    Why

  • The destructive failure mode (skip too much, or return empty on error) is

  • what these tests exist to catch if the guard is ever widened by mistake.

    How far this is verified

  • scripts/validate-changes.sh (build + vet + test of ./pkg/connector,

  • the packages this diff touches): exit 0.
  • scripts/check-kind-rules.sh: 0 violations, 0 hints.

  • Editing adversarial review (findings → fix → re-review loop): verdict SHIP;

  • the round-2 fixes were test-only hardening (log-level assertion, code-2100
    isolation, trailing newline), and commit 80b8ec46 consolidates user.Delete's
    inline 404 guard onto the shared notFoundOnItem helper (behavior-identical).
  • Smoke: the binary builds and starts. NOTE: this repo declares no mock, so

  • no sync was exercised
    by the smoke gate — the change is unproven against
    a live or mocked upstream by that gate alone. The batch's connector-eval
    tool separately replayed a full sync against a mock of the PagerDuty API
    built from its official docs: object-for-object identical to main on the
    same recording (0 resources/entitlements/grants lost or gained; see
    connector-eval below).
  • CI: green at head 80b8ec46 (pr-review, verify/lint). The repository's

  • review bot accepted the change after one fix pass: it flagged that the
    SDK's NotFound() predicate treats API error code 2100 as absence on any
    HTTP status — wider than a bare "404 = absence" claim — so the doc comment
    was corrected to state the wider semantics precisely (the guard code is
    byte-identical; the bot's own suggested resolution, and the repo's own
    idiom elsewhere in the package).
  • End-to-end test (VERA, fresh clone of this branch): 7/7 acceptance

  • criteria WORKS. Highlights: a real sync of the built binary against a mock
    that force-404s the on-call listing completes exit 0, and a grant diff
    against the base recording shows the ONLY delta is the vanished schedule's
    2 on-call grants (all member grants intact); forcing a 500 on the same seam
    still fails the sync. The tester shared this VM's toolchain (clean checkout,
    not a clean VM), and the live PagerDuty API was NOT exercised (no
    credentials in the environment — all probes ran against the
    vendor-documented mock).
  • Independent deep review: CLEAR after 2 rounds, 2 findings, both

  • answered and resolved on the PR. Round 1: the new notFoundOnItem helper
    duplicated the identical inline predicate in user.Delete — fixed by
    consolidating user.Delete onto the helper (commit 80b8ec46,
    behavior-identical; the diff's only provisioning-path touch). Round 2: the
    PR body did not document that provisioning-path touch — fixed by updating
    this description (no code change). A reader who had never seen this batch
    read it cold and raised two things; both were fixed and resolved.

    connector-eval (advisory): regression — "regression on the matched
    requests; 1 requests not in the recording (re-ran with --allow-unmatched)".
    Investigated before ranking: the one unmatched request is the on-call listing
    itself (GET /schedules/{id}/users), whose since/until parameters are
    derived from the clock and change between runs, so the recording cannot
    exact-match it — the base (main) run shows the identical limitation, and the
    object diff is 0/0/0 with no new static findings. Connector-eval is advisory
    in this pipeline; the verdict is a recording artifact shared by every
    candidate, not a behavior change.

    What to look at hardest

  • The 404-skip guard in Grants — the whole change lives in one branch;

  • check that the comment's claim (single-object GET, so 404 = this schedule)
    still holds if the call ever moves to a multi-schedule endpoint.
  • Scope: team.go's per-team member listing has the same theoretical

  • shape and still fails the sync on a mid-sync team deletion. That is
    deliberate — the ticket scopes the fix to the reported schedule seam, and
    the new notFoundOnItem helper makes that follow-up a two-line change.
  • Member grants on a vanished schedule: the profile snapshot's member

  • grants still emit for the schedule that disappeared; the next full sync's
    list phase removes the schedule and its grants. One self-healing cycle of
    lag, per the ticket's requirement that the sync not fail.

    Release Notes

    baton-pagerduty no longer fails a sync when a PagerDuty schedule is deleted
    (or otherwise stops resolving) mid-sync: the connector now skips that
    schedule's on-call grants, logs at debug, and completes the sync instead of
    erroring with 404 "Schedule Not Found" and requiring a support-dashboard
    re-run.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: c1-squire-dev[bot] Review duration: 24230m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #39"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30.4% · Safe to merge
    30.4%