Repository navigation
Conversation
Shared singleton that tracks consecutive 401/Unauthorized errors across all polling operations. Backoff intervals: 5s, 15s, 30s, 60s cap. Resets on any successful auth call. Fixes #5784 (friction #10: error log spam) Co-Authored-By: Claude Opus 4.6 <[email protected]>
Skip poll when in backoff period, report 401 as auth failure, report success on clean fetch. Reduces Unauthorized log spam from every 15s to exponentially-backed-off intervals. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Skip refresh when in backoff period, track 401 failures and successes. Prevents repeated Unauthorized errors every 30s. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Skip task refresh when in backoff period, track auth failures and successes on the shared backoff tracker. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Skip memory refresh when in backoff period, track auth failures and successes on the shared backoff tracker. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Skip Crisp message poll when in backoff period, track auth failures and successes on the shared backoff tracker. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Greptile SummaryThis PR introduces Key concerns:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant P1 as ChatProvider (15s)
participant P2 as AppState (30s)
participant P3 as TasksStore (30s)
participant P4 as MemoriesPage (30s)
participant P5 as CrispManager (120s)
participant T as AuthBackoffTracker
participant API as API Server
Note over P1,P5: Normal polling — consecutiveFailures = 0
P1->>T: shouldSkipRequest() → false
P1->>API: GET /messages → 200 OK
P1->>T: reportSuccess()
Note over P1,P5: Auth fails — all pollers in-flight simultaneously
P1->>T: shouldSkipRequest() → false
P2->>T: shouldSkipRequest() → false
P3->>T: shouldSkipRequest() → false
P1->>API: GET /messages → 401
P2->>API: GET /conversations → 401
P3->>API: GET /tasks → 401
P1->>T: reportAuthFailure() → failures=1, backoff=5s
P2->>T: reportAuthFailure() → failures=2, backoff=15s
P3->>T: reportAuthFailure() → failures=3, backoff=30s
Note over T: ⚠️ Jumps to 30s instead of intended 5s
Note over P1,P5: Backoff active — pollers skipped
P1->>T: shouldSkipRequest() → true (skip)
P2->>T: shouldSkipRequest() → true (skip)
P4->>T: shouldSkipRequest() → true (skip)
Note over P1,P5: Backoff expires — user signs back in
P1->>T: shouldSkipRequest() → false
P1->>API: GET /messages → 200 OK
P1->>T: reportSuccess() → failures=0 (reset)
Note over P1,P5: All pollers resume normally
|
| func reportAuthFailure() { | ||
| consecutiveFailures += 1 | ||
| lastFailureTime = Date() | ||
| if consecutiveFailures == 1 { | ||
| log("AuthBackoff: first auth failure, backing off") | ||
| } |
There was a problem hiding this comment.
Concurrent pollers inflate failure count on first error
When all pollers are at consecutiveFailures == 0, they all call shouldSkipRequest() and all receive false, so every in-flight poll will proceed to the API simultaneously. If they all receive a 401 (e.g., on app startup with an expired token), each one calls reportAuthFailure() serially on the main actor. Five pollers will increment the counter from 0 → 5 in a single failure event, so index = min(4, 3) = 3 and the backoff jumps directly to 60 s, bypassing the intended 5 s → 15 s → 30 s → 60 s escalation.
A simple guard — only increment on the first such report per backoff cycle — would preserve the intended escalation:
func reportAuthFailure() {
// If we're already in a backoff window, don't reset the clock or bump the counter again —
// other pollers that slipped through before the window was established shouldn't re-trigger.
if shouldSkipRequest() {
return
}
consecutiveFailures += 1
lastFailureTime = Date()
if consecutiveFailures == 1 {
log("AuthBackoff: first auth failure, backing off")
} else {
log("AuthBackoff: failure #\(consecutiveFailures), backing off \(backoffIntervals[min(consecutiveFailures - 1, backoffIntervals.count - 1)])s")
}
}This way the counter only increments when a new API call escapes the backoff window and fails, which matches the documented 5 s → 15 s → 30 s → 60 s progression.
| func reportAuthFailure() { | ||
| consecutiveFailures += 1 | ||
| lastFailureTime = Date() | ||
| if consecutiveFailures == 1 { | ||
| log("AuthBackoff: first auth failure, backing off") | ||
| } | ||
| } |
There was a problem hiding this comment.
Backoff escalation transitions are not logged
Only the first failure (consecutiveFailures == 1) produces a log message. When the counter advances through the backoff ladder (5 s → 15 s → 30 s → 60 s), none of those transitions are surfaced. During local debugging it can be hard to tell which backoff tier is active without adding a breakpoint.
Consider logging each new tier:
func reportAuthFailure() {
consecutiveFailures += 1
lastFailureTime = Date()
let backoff = backoffIntervals[min(consecutiveFailures - 1, backoffIntervals.count - 1)]
log("AuthBackoff: failure #\(consecutiveFailures), next retry in \(backoff)s")
}|
Hey @beastoin 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! 💜 |
Summary
AuthBackoffTracker— a shared singleton with exponential backoff (5s → 15s → 30s → 60s cap) that tracks consecutive 401/Unauthorized errorsFixes #5784 (friction #10)
How it works
When any poller gets a 401,
AuthBackoffTracker.shared.reportAuthFailure()is called. All subsequent pollers checkshouldSkipRequest()at entry — if we're in a backoff window, they return early without hitting the API. On any successful API call,reportSuccess()resets the counter. This means one 401 immediately suppresses all polling, and recovery is instant on the first successful call.Test plan
by AI for @beastoin
🤖 Generated with Claude Code