fix: downgrade transient railway token-refresh failures from ERROR to WARN and continue with valid token #SUPERLOG
Summary
When Railway's OAuth token endpoint returns a transient server_error, the worker was logging it as ERROR (triggering an incident) and skipping the entire installation for the current pass — even though the access token is still valid for up to 5 more minutes.
Root cause
The token-refresh block fires when the token has less than TOKEN_REFRESH_MARGIN_MS (5 minutes) remaining. At that point accessToken already holds the valid stored token. On a transient Railway server error the old code returned early, abandoning the still-valid token for the whole pass. Concretely: error: "server_error" is RFC 6749's transient-server-error code — analogous to the status_500 / status_503 values that railway grant refresh failed and railway inventory read failed already handle as WARN with graceful fallback.
Remediation
- On a failed refresh, check whether the stored token has already expired:
- Not yet expired → log WARN ("continuing with current token"), fall through using
installation.accessToken; next pass will retry the refresh. - Already expired → log WARN ("token expired — skipping"), return as before; downstream Railway calls would fail anyway.
- Not yet expired → log WARN ("continuing with current token"), fall through using
- Move the
accessToken = refreshed.accessToken/saveTokens(...)lines into anelsebranch so they only execute on a successful refresh. - Added two new tests in
puller.test.tscovering both branches; all 8 tests pass.
Incident: yeasty-skunk — ERROR: railway token refresh failed
Was this PR helpful? Leave feedback — goes straight to the Superlog team.
Summary by cubic
Downgraded transient Railway token refresh failures to WARN and continue using the current valid token, avoiding false incidents and skipped pulls. If the token is already expired, we still skip but log WARN.
- Bug Fixes
- On refresh
server_errorwith a not-yet-expired token, log WARN and proceed withinstallation.accessToken. - If the token is expired, log WARN and skip; no ERROR logs.
- Only update
accessToken/refreshTokenon successful refresh. - Added tests covering both paths in
apps/worker/src/railway/puller.test.ts.
- On refresh