Skip to content

SDK-562 Fix offline queue replaying expired JWT - #1085

Merged
sumeruchat merged 2 commits into
masterfrom
fix/SDK-562-offline-queue-stale-jwt
Jul 24, 2026
Merged

SDK-562 Fix offline queue replaying expired JWT#1085
sumeruchat merged 2 commits into
masterfrom
fix/SDK-562-offline-queue-stale-jwt

Conversation

@sumeruchat

@sumeruchat sumeruchat commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

What

Requests persisted to the offline queue froze the JWT at enqueue time and replayed it on every retry. A task queued while the token was expired kept failing with a 401 even after a successful refresh, survived app restarts, and paused the JWT tasks queued behind it. Reported by Wolt (SDK-562).

Changes

  • IterableAPICallTaskProcessor overwrites the decoded task's auth token with the current AuthManager token before building the request, matching the online path which reads the token at send time
  • IterableTaskRunner and the dependency container thread the existing AuthManager instance into the processor (optional parameter, nil default, so other constructions are unchanged)
  • A nil live token keeps the persisted one, and the persisted task format is unchanged, so tasks already stuck on devices heal on their next run after a refresh
  • Tests reproduce the poisoned-task loop end to end: 401 with the expired token, refresh, retry goes out with the fresh token, queue drains. Re-stamp semantics across a process restart and a multi-task drain variant are also covered

Impact

  • Breaking changes: None
  • Dependencies: None
  • Performance: One getAuthToken() read per offline task execution

Testing

How to test:

  1. ./agent_build.sh
  2. xcodebuild test -scheme swift-sdk -destination 'platform=iOS Simulator,name=iPhone 17 Pro' -only-testing:offline-events-tests (96 tests, 0 failures; full unit-tests also green, 644 tests)
  3. Key tests: TaskRunnerTests.testJWTAuthFailureRetriesWithRefreshedToken asserts the wire sees Bearer expired-token then Bearer fresh-token; TaskProcessorTests.testUsesCurrentAuthTokenWhenProcessingPersistedTask pins re-stamp across a restart
  4. Red-test proof: with the re-stamp reverted, the loop test fails with headers [expired, expired], confirming it pins the reported bug

Offline-queued requests persisted the JWT inside the task at enqueue
time and replayed it on every retry. A task queued while the token was
expired kept failing with a 401 after refresh, survived app restarts,
and paused the JWT tasks behind it. The task processor now overwrites
the persisted token with the current one from AuthManager before
building the request, matching online behavior and healing tasks
already stuck in the queue. A nil live token keeps the persisted one.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sumeruchat
sumeruchat requested a review from a team as a code owner July 20, 2026 18:16
@sumeruchat sumeruchat self-assigned this Jul 20, 2026
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.32%. Comparing base (9a0eb2d) to head (480d95a).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1085      +/-   ##
==========================================
- Coverage   72.34%   72.32%   -0.02%     
==========================================
  Files         114      114              
  Lines        9585     9594       +9     
==========================================
+ Hits         6934     6939       +5     
- Misses       2651     2655       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joaodordio joaodordio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sumeruchat
sumeruchat merged commit dd6e178 into master Jul 24, 2026
15 checks passed
@sumeruchat
sumeruchat deleted the fix/SDK-562-offline-queue-stale-jwt branch July 24, 2026 14:00
sumeruchat added a commit that referenced this pull request Jul 24, 2026
…onsume-inbox-notification

* origin/master:
  SDK-562 Fix offline queue replaying expired JWT (#1085)
  SDK-569 Parse itbl delivered as a JSON string (iOS-via-FCM) (#1086)

# Conflicts:
#	CHANGELOG.md
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