( reauthState: OAuthReauthRequiredState, row: ConnectionRow, )
| 1067 | * that somehow lacks one) gets an expired verdict synthesized from the |
| 1068 | * recorded rejection, unpersisted. */ |
| 1069 | const deadGrantVerdict = ( |
| 1070 | reauthState: OAuthReauthRequiredState, |
| 1071 | row: ConnectionRow, |
| 1072 | ): HealthCheckResult => { |
| 1073 | // The mechanism recorded WITH the dead grant; older records carry none and |
| 1074 | // read as a refresh rejection, which is what recording a dead grant meant |
| 1075 | // before the mechanism was stored. |
| 1076 | const recorded = recordedDeadGrantReason(reauthState) ?? "credential_refresh_rejected"; |
| 1077 | const cached = Option.getOrNull(decodeLastHealth(row.last_health)); |
| 1078 | // Backfill the mechanism onto verdicts persisted before `reason` existed |
| 1079 | // (or by writers that omit it) — otherwise every pre-existing dead grant |
| 1080 | // would present reasonless spans indefinitely. |
| 1081 | if (cached !== null && cached.status === "expired") { |
| 1082 | return cached.reason !== undefined ? cached : { ...cached, reason: recorded }; |
| 1083 | } |
| 1084 | return { |
| 1085 | status: "expired", |
| 1086 | checkedAt: reauthState.oauthReauthRequiredAt, |
| 1087 | detail: |
| 1088 | reauthState.oauthReauthRequiredDetail ?? |
| 1089 | "The authorization server rejected this connection's refresh token (invalid_grant). Reconnect to continue.", |
| 1090 | reason: recorded, |
| 1091 | }; |
| 1092 | }; |
| 1093 | |
| 1094 | /** The health a connection row presents on every API read. Derived, never |
| 1095 | * written back: while `provider_state` records a dead grant, the row |
no test coverage detected