Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(code-reviews): report only unrecovered dispatch timeouts to Sentry - #13865

Open
eshurakov wants to merge 5 commits into
mainfrom
eshurakov/code-review-dispatch-timeout-noise
Open

eshurakov wants to merge 5 commits into
mainfrom
eshurakov/code-review-dispatch-timeout-noise

Conversation

@eshurakov

@eshurakov eshurakov commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Why

The web app sends code reviews to a separate review worker with a 10 second deadline. When the
deadline passes, the app cannot tell whether the worker received the review. It then asks the
worker for the review status:

  • if the worker has the review, the review continues;
  • if the worker has no record of it, the app releases the claim so the review can be dispatched
    again.

That recovery works. But the timeout was reported to the error tracker before the status check
ran, so every recovered timeout appeared as an error. In a normal day this made a handled
condition look like a service failure. This change reports the timeout only when the status check
cannot answer, and records each ambiguous dispatch failure as one structured log line so recovered
timeouts remain countable.

Summary

  • The review worker client marks deadline errors with the stable code CODE_REVIEW_WORKER_TIMEOUT,
    so callers can identify a timeout without matching the message.
  • The dispatch path emits one structured line per probed dispatch failure:
    code_review.dispatch_ambiguous_failure with dispatchFailure (timeout, connection_refused,
    other) and probeOutcome (queued, terminal, released, claim_changed, unrecovered).
    claim_changed means the worker has no state and the guarded release matched no row, so this
    dispatch no longer holds the claim. The release cannot tell why the claim changed.
  • A recovered timeout (worker has the review, or its claim was released or is no longer current)
    is no longer sent to the error tracker. An unrecovered timeout is sent once, with the probe
    failure as context.
  • A status response that cannot be written to the database is reported on its own:
    code_review.dispatch_probe_reconcile_failed in the logs, with the probe observation, the
    dispatch failure kind and the error class only; the log line has no database message. The
    database helper reports the error once under dispatch-review-probe-reconcile. Following the
    existing Drizzle error policy, the error tracker receives the database error class and its
    message as the exception value, plus the parameterized query and allowlisted extras. Bound
    values, session IDs and worker error text are not sent. It is not reported as an unrecovered
    dispatch timeout, and the review stays queued for the existing stale-queued recovery.
  • Other dispatch failures keep their existing error-tracker reports.

Verification

Automated tests only; no manual test. The change affects error reporting and log output, not UI.

  • pnpm --filter web test -- --runTestsByPath src/lib/code-reviews/client/code-review-worker-client.test.ts src/lib/code-reviews/dispatch/dispatch-pending-reviews.test.ts
    — 92 tests pass. New coverage: timeout error code, connection refusal is not a timeout, the
    queued, released, claim-changed and unrecovered probe outcomes (including the manual review whose
    dispatch and status probe are both refused), and a reconcile write failure through a real
    database helper for the attempt write and the parent review write, checking that synthetic
    session and error markers are absent from both the log and the error-tracker extras.
  • pnpm --filter web typecheck — pass.
  • pnpm --filter web lint — pass.

Visual Changes

N/A

Reviewer Notes

  • Timeout suppression is limited to timeout errors. Other ambiguous dispatch errors keep their
    existing error-tracker reports, so this change does not hide a different failure class.
  • When a dispatch timeout is unrecovered, the timeout is the single reported event and the probe
    error is carried in extra.statusProbeError. Reporting both would create two events for one
    review.
  • The structured line is emitted for every probed ambiguous dispatch failure, not only timeouts,
    so a log query can compare outcomes across failure kinds.
  • A no-state probe whose guarded release matched no row is recorded as claim_changed, not
    released. That result only proves that no row matched the guarded update; it does not say why
    the claim changed.
  • The status request and the database reconciliation have separate error handling. A request
    failure keeps the existing unrecovered behaviour. A reconciliation failure is captured once by
    the database helper, labelled with the dispatch-review-probe-reconcile operation, and leaves
    the review queued. The helper's error-tracker extras list only the review or attempt ID, the
    status and the terminal reason; they omit session IDs, worker error text and bound query values.

A dispatch timeout is ambiguous: the status probe decides whether the
Worker accepted the review. The dispatch catch reported the timeout
before that decision, so every recovered timeout became a Sentry error.

Mark deadline errors with a stable code, log one structured event per
probed dispatch failure with its outcome, and report the timeout to
Sentry only when the probe cannot answer.
…t release

The guarded release returns false when the review was superseded or
reclaimed while the status probe ran. The structured event counted that
as a release. Record claim_changed instead, keep both outcomes out of
Sentry, and cover the supersede race in a test.
@eshurakov

This comment has been minimized.

@eshurakov
eshurakov marked this pull request as ready for review December 4, 2026 06:05

@chrarnoldus chrarnoldus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bot: apps/web/src/lib/code-reviews/dispatch/dispatch-pending-reviews.ts:1099: If the Worker returns a terminal status but a database write fails, this catch reports an unrecovered Worker timeout and groups the database error under it. Isolate the status request in its own try/catch and report reconciliation failures separately.

A successful status response followed by a failed database write landed
in the status-probe catch, which reported an unrecovered dispatch
timeout and grouped the write error under it. Isolate the status request
in its own catch, and report reconcile failures with their own event and
operation tag while leaving the review queued.
@eshurakov

Copy link
Copy Markdown
Contributor Author

bot: Fixed in 98f7e21. The status request now has its own catch, so its failures keep the existing unrecovered handling. Database writes that follow a successful status response are reported separately: code_review.dispatch_probe_reconcile_failed in the logs and the database error under the dispatch-review-probe-reconcile operation. The review stays queued for stale-queued recovery, and the dispatch timeout is not reported for that case.

…e error

Drizzle error messages carry the SQL and its bound values, and the
reconcile path copied the message into the log stream. Log only
classification fields.

The database helpers captured the same error before the reconcile catch,
so Sentry deduplicated the second capture and lost the reconcile
operation tag. Let the helper that reports the error take the caller's
operation, and do not capture again. The test now fails a real attempt
update with a trigger and checks the log for absent bound values.
…ntry

The tagged error-tracker event still carried the attempt parameters and
parent update values, including session IDs and worker error text.
Report only the review or attempt ID, the status and the terminal
reason. Forward the capture override only when the caller passes one, so
ordinary callbacks keep their previous operation tags.

Cover both the attempt write and the parent review write with a real
trigger failure, and assert that synthetic markers are absent from the
log and the error-tracker extras.
@eshurakov

Copy link
Copy Markdown
Contributor Author

Manual QA — T-126

Pass · tested 9939dc85ac

  • Round 1 found no problems; all its scenarios pass again at this head. Recovered timeouts (queued, running, released, terminal, terminal failed, claim_changed) emit one code_review.dispatch_ambiguous_failure line and no Sentry event; an unrecovered timeout sends exactly one event.
  • The new reconcile handling works: a status response that cannot be written sends one event tagged dispatch-review-probe-reconcile with allowlisted extras, no bound values or worker text, and logs code_review.dispatch_probe_reconcile_failed instead of classifying the failure as an unrecovered timeout. The review keeps its queued claim.
  • Evidence: 15 scenario logs in qa/02/evidence/, plus sentry-envelopes.log holding 7 error envelopes total and envelope-summary.txt. Axiom ingestion and the production Sentry project are not reachable locally, so post-deploy checks cover them.
Test details and evidence

Scenarios

# Scenario Steps Expected Observed Evidence Result
1 Normal dispatch Worker acknowledges at once, one pending manual review Review queued, no ambiguous-failure line, no Sentry event dispatched: 1 in 57 ms, review queued, no line, no error envelope 01-fast.log pass
2 Recovered timeout, worker holds the review Worker delays /review 12 s past the 10 s deadline, status returns queued Line with timeout/queued, review kept, no Sentry event 10 056 ms, review queued, line emitted, no error envelope 02-timeout-queued.log pass
3 Recovered timeout, worker has no state Delay past the deadline, status returns 404 Claim released, review pending, line released, no Sentry event Reservation cleared, review pending, line emitted, no error envelope 03-timeout-released.log pass
4 Released claim is retried After scenario 3, worker answers normally and dispatch runs again The released review is dispatched Second run dispatched: 1, review queued 04-timeout-released-retry.log pass
5 Recovered timeout, terminal completed Delay past the deadline, status returns completed Review and attempt completed from the probe, line terminal, no Sentry event Review and attempt completed, sessionId stored, line emitted, no error envelope 06-timeout-terminal.log pass
6 Recovered timeout, terminal failed Delay past the deadline, status returns failed with upstream_error Review and attempt failed from the probe, line terminal, no Sentry event Review and attempt failed/upstream_error with worker text, line emitted, no error envelope 13-timeout-terminal-failed.log pass
7 Recovered timeout, status running Delay past the deadline, status returns running Treated as worker-held, line queued, no Sentry event 10 058 ms, dispatched: 1, review queued, line emitted, no error envelope 07-timeout-running.log pass
8 Timeout races a supersede Status endpoint holds 4 s, review cancelled during the probe, then 404 No release, line claim_changed, no Sentry event 14 088 ms, review stays cancelled/superseded, line emitted, no error envelope 05-timeout-claim-changed.log pass
9 Unrecovered timeout Delay past the deadline, status probe returns 500 Review keeps its claim, line unrecovered, one Sentry timeout event Review queued with reservation, line emitted, one envelope Request timeout after 10000ms, tag dispatch-review-worker-call, probeOutcome: unrecovered, statusProbeError: Failed to fetch review status: 500 08-timeout-unrecovered.log, envelope-summary.txt pass
10 Non-timeout dispatch failure Worker returns 500 on dispatch, status probe 500 Line other/unrecovered; existing reports unchanged Line emitted; two envelopes (Worker returned 500, Failed to fetch review status: 500), as before 09-dispatch-500.log, envelope-summary.txt pass
11 Connection-refused manual review No listener, dispatch and probe both refuse Review fails retryably, line connection_refused, dispatch error still reported Review and attempt failed/upstream_error with the retry message, line emitted, one envelope Code review worker request failed 10-connection-refused.log, envelope-summary.txt pass
12 Probe response cannot be written (attempt) Worker answers completed after the deadline; a database trigger rejects the attempt write One safe reconcile line, one Sentry event under its own operation, no timeout event, review stays queued Line dispatch_probe_reconcile_failed with probeObservation: completed, dispatchFailure: timeout, errorName; one envelope tagged dispatch-review-probe-reconcile; review queued with its reservation; attempt unchanged 11-reconcile-attempt-fail.log, envelope-summary.txt pass
13 Probe response cannot be written (parent review) Same, but the parent review write is rejected Same as 12; the attempt write stays applied Attempt completed, parent review queued with its reservation, one reconcile line and one reconcile envelope, no timeout event 12-reconcile-review-fail.log, envelope-summary.txt pass
14 Cron entry point, recovered timeout Backdated pending review, then the route's direct callee dispatchPendingCodeReviewOwners Owner drained, one ambiguous line, no Sentry event ownersConsidered: 1, reviewsDispatched: 1, line queued, no error envelope 14-cron-entrypoint-timeout-queued.log pass
15 Cron entry point, unrecovered timeout Same, status probe returns 500 Owner drained, line unrecovered, one Sentry timeout event ownersWithNoNewDispatch: 1, line emitted, one envelope with probeOutcome: unrecovered 15-cron-entrypoint-timeout-unrecovered.log, envelope-summary.txt pass

Total Sentry error envelopes: 7. Scenarios 9, 10 (2), 11, 12, 13, 15 account for all 7; no recovered timeout produced one. The remaining envelope traffic is SDK client reports about discarded spans, not errors.

The reconcile envelopes contain the parameterized query in contexts.drizzle_query, the allowlisted extras only (reviewId/attemptId, status), and the database cause message as the exception value. The markers planted in the worker response (session-marker-qa, error-marker-qa) and the string params: appear in no envelope and in no product log line.

Problems found

none

Note, not a failure: the PR text says the database message is not sent to the error tracker. The evidence shows the database cause message is the Sentry exception value (PostgresError with the trigger text), while the SQL, its bound values, session IDs and worker error text are not sent. This matches the binding decision (log line and Sentry extras carry classification only) and the existing Drizzle error policy, but the PR sentence is broader than the behavior.

Not tested

  • The Next.js HTTP route GET /api/cron/dispatch-pending-code-reviews and any browser view. The route only authenticates and calls dispatchPendingCodeReviewOwners, which I ran directly on the local database; no route code changed.
  • Axiom ingestion of code_review.dispatch_ambiguous_failure and code_review.dispatch_probe_reconcile_failed: not observable locally. Post-deploy checks cover both.
  • The production Sentry project: a local envelope sink received the same payloads through the real server initializer instead. A post-deploy check covers it.
  • Webhook (non-manual) reviews on the connection-refused path: the manual-only branch was exercised; the webhook branch keeps the queued claim, which scenario 9 and 12 already show for the queued outcome.

Verdict: pass

This branch has not been deployed

No deployments
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