Skip to content

fix(cloud): wake 401 refusals record which token check failed; auth-refusals floor - #48570

Merged
Jinwoo-H merged 1 commit into
mainfrom
jinwoo/wake-refuse-reason
Nov 25, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
jinwoo/wake-refuse-reason

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When the wake Worker turns away a desktop's token, it now records why (expired, not valid yet, wrong audience, unknown key, and so on), not just "token". Separately, the auth-refusal alert no longer pages on a couple of refusals in a quiet window.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​62 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​48 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​34

What Changed

  • Refuse detail (cloud/apps/connector-wake/src/jwt.ts, index.ts, metrics.ts):
    • verifyWakeToken returns a code for an invalid token, from a fixed set, WAKE_REFUSE_CODES:
      • from jose's error class and claim: exp, nbf, iat, aud, iss, sub, signature, kid (no matching key), alg, malformed;
      • from the Worker's own checks: claims (schema/purpose), host (not a host id), missing (no bearer), other.
    • The refuse metric writes it as a new sixth blob, detail. Every other metric writes '' there.
    • reason stays token, so the alerts' refuse_401 column and any existing query are unchanged.
    • Nothing from the token goes in: no payload, sub, mid or ids. Only the class of the check that failed.
  • auth-refusals floor (alerts-rules.ts):
    • auth-refusals (more than 0.5% of upgrades refused) now also needs at least 5 refusals beyond the alerts' own probes, and at least AUTH_MIN_UPGRADES upgrades (default 200, never below MIN_VOLUME).
    • Below that floor, auth-refusals-low-volume takes over with the same 5-refusal bar, so there's no gap between the two.

Why

  • On 2026-11-24, two hosts (GRU and FRA) were refused repeatedly after a token refresh, and the dataset could only say token. An exp or nbf detail would have pointed straight at clock skew between auth and the colo.
  • With production MIN_VOLUME 20, 2 refusals in 36 upgrades (5.6%) paged auth-refusals, and so did 2 in 306 (0.65%). One host with a bad token isn't worth a page.
  • Replay of the full day of production data (every 5-minute run): neither rule fires today, before or after this change. The floor only removes the small-window pages.

Linked Issue

N/A (internal)

Visual Proof

N/A: cloud Worker metrics and alert rules, no UI.

Testing

  • test/auth.test.ts:
    • audience → aud, purpose → claims, bad host id → claims;
    • a token expired 5 min ago → exp; nbf 5 min ahead → nbf; unknown kid → kid; another key → signature; garbage → malformed;
    • the refuse metric's blobs are [refuse, 401, version, token, place, code] and other events get ''.
  • test/alerts.test.ts:
    • 2 refusals at 36 and at 306 upgrades → quiet;
    • 5 at 309 → auth-refusals; 5 at 109 → auth-refusals-low-volume;
    • AUTH_MIN_UPGRADES override, never below MIN_VOLUME.
  • Mutation checks: the old rule fails the small-window test; dropping the exp mapping fails the codes test.
  • Run locally: vitest run test/alerts.test.ts test/auth.test.ts (27 passed) and tsc --noEmit (clean).
  • Note: jose rejects a future iat only under maxTokenAge, which the Worker doesn't set. A token from a clock that runs ahead is refused only if it carries nbf. The test pins that, and I didn't change what the Worker accepts.

Performance

None, because the refuse path only adds one class check on an error that already happened, and every metric gains one empty string blob.

Risk

Level: Low.

  • The refuse detail takes effect with a wake Worker deploy (staged, staging first).
  • The floor takes effect with an alerts Worker deploy.
  • Both reach production only after cloud/connector-wake-source-revision in stablyai/orca-cloud is bumped, with Jinwoo's OK.
  • The wake Worker's 401/accept decisions are unchanged.
  • This branches from main beside fix(cloud): wake reconnect-surge ignores object retirement waves, still fires on real drops #48497 and touches different lines of alerts-rules.ts and its test.
  • Plain revert.

@Jinwoo-H
Jinwoo-H force-pushed the jinwoo/wake-refuse-reason branch from 97d2dab to 4b6072d Compare November 24, 2026 23:39
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 351d5481-c429-4c9a-b751-fbf6686845de
Commits

Reviewing files that changed from the base of the PR and between 47b0ff4 and 754bbf5.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Wake-token verification now assigns fixed codes to invalid-token results, and refusal metrics record the code or missing. Auth-refusal alert rules now use a configurable upgrade threshold and require at least five non-probe refusals.

Merge Risk: Minimal · previous review 47b0f

This change adds fixed-class failure details to wake refusal metrics and raises the alert volume floor. No concrete merge-blocking risk was identified, and existing metric columns and token acceptance are unchanged.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names both main changes: wake 401 refusals now record which token check failed, and the auth-refusals alert gets a volume floor. It uses the conventional commit prefix. It is slightly long a…
Description check Passed The description follows the template closely. It has ELI5, What Changed, Why, Linked Issue (marked N/A internal), Visual Proof (N/A with reason), Testing, Performance, and Risk with a level and rollba…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names both main changes: wake 401 refusals now record which token check failed, and the auth-refusals alert gets a volume floor. It uses the conventional commit prefix. It is slightly long at 82 characters, but it is specific and matches the changeset.

Full details: Description check

Explanation

The description follows the template closely. It has ELI5, What Changed, Why, Linked Issue (marked N/A internal), Visual Proof (N/A with reason), Testing, Performance, and Risk with a level and rollback plan. The Testing checklist boxes are unchecked, and the AI Disclosure and Review sections are missing or empty. The Linked Issue is N/A rather than a linked issue, which the template says should always exist for outside contributors. The author is internal, so this may be acceptable. The Performance section is complete.

Resolution

Optional cleanup: tick the testing checklist items that were done, confirm the Linked Issue exemption for an internal author, and fill in or remove the empty AI Disclosure and Review sections.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9a65f7d3-bde2-4eb8-ba3a-914354fdea0d
Commits

Reviewing files that changed from the base of the PR and between 7521a30 and 47b0ff4.

Files selected for processing: 6

  • cloud/apps/connector-wake/src/alerts-rules.ts
  • cloud/apps/connector-wake/src/index.ts
  • cloud/apps/connector-wake/src/jwt.ts
  • cloud/apps/connector-wake/src/metrics.ts
  • cloud/apps/connector-wake/test/alerts.test.ts
  • cloud/apps/connector-wake/test/auth.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@Jinwoo-H
Jinwoo-H force-pushed the jinwoo/wake-refuse-reason branch from 4b6072d to 47b0ff4 Compare November 24, 2026 23:39
@Jinwoo-H
Jinwoo-H changed the base branch from main to jinwoo/wake-alerts-retirement-waves November 24, 2026 23:39
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jinwoo-H
Jinwoo-H changed the base branch from jinwoo/wake-alerts-retirement-waves to main November 25, 2026 00:08
…efusals needs 5 refusals and 200 upgrades

- A refused wake token's refuse metric gets a sixth blob, detail: the jose check that failed (exp,
  nbf, iat, aud, iss, sub, signature, kid, alg), or claims, malformed, host, missing or other. Fixed
  values only: nothing read from the token. reason stays 'token', so existing queries and the
  alerts' refuse_401 column are unchanged. On 2026-11-24 two hosts (GRU, FRA) were refused
  repeatedly after a refresh and the dataset could not say why; exp or nbf would point at clock skew.
- auth-refusals (share of upgrades) now needs at least 5 refusals beyond the alerts' own probes and
  at least AUTH_MIN_UPGRADES upgrades (default 200, never below MIN_VOLUME); below that floor
  auth-refusals-low-volume needs the same 5. Before, 2 refusals in 36 upgrades paged at MIN_VOLUME
  20. Neither rule fires on 2026-11-24 production, before or after.
@Jinwoo-H
Jinwoo-H force-pushed the jinwoo/wake-refuse-reason branch from 47b0ff4 to 754bbf5 Compare November 25, 2026 00:08
@Jinwoo-H
Jinwoo-H merged commit 28b083c into main Nov 25, 2026
28 of 30 checks passed
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.

1 participant