Skip to content

[SDK-715] Inject retry dependencies into the request layer - #1113

Open
franco-zalamena-iterable wants to merge 8 commits into
feature/SDK-715-a-remote-configfrom
feature/SDK-715-b-retry-injection
Open

franco-zalamena-iterable wants to merge 8 commits into
feature/SDK-715-a-remote-configfrom
feature/SDK-715-b-retry-injection

Conversation

@franco-zalamena-iterable

@franco-zalamena-iterable franco-zalamena-iterable commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

📝 Summary

Pins the current online retry schedule with tests and injects the retry policy, remote config holder and clock into the request layer. No behaviour change.

🎟️ Jira Ticket: SDK-715

Epic: SDK-454

Stack, in order: #1111 (SDK-714), #1112, #1113, #1114, #1115. This is #1113.

📖 Description

This PR prepares the request layer for the retry policy without changing what it does.

New tests pin the legacy online retry behaviour, so the next PRs can't change it by accident. They cover the 5xx retry schedule for 500, 503 and 599 and where it stops after six retries, code 0 and client errors not being retried, and the JWT failure handling of stored and inline requests with autoRetry on and off. With autoRetry on, they also check that a JWT 401 on an offline request schedules the auth refresh. Another test checks that the offline processor and task runner use the same IterableRemoteRetryConfig holder as IterableApi, and that the offline processor gets the app's network retry policy. The 5xx schedule table replaces two existing tests that each checked one retry, and the stored request checks extend the existing IterableTaskRunnerTest cases.

The retry policy provider and the IterableRemoteRetryConfig holder are now passed through the constructors of IterableApiClient, OnlineRequestProcessor, OfflineRequestProcessor and IterableTaskRunner. IterableRequestDispatcher gets an injectable clock that defaults to SystemClock.elapsedRealtime.

It also has two refactors the ticket doesn't need, with no behaviour change. The JWT error codes and their matcher moved from IterableRequestTask to IterableNetworkRetryClassifier, so there is no two-way dependency between them. The existing autoRetry reads in IterableRequestTask, IterableTaskRunner and OfflineRequestProcessor now come from the injected holder instead of the IterableApi singleton, so the JWT auto retry and the new retry policy read the same flag from one place. That left the package-private IterableApi.isAutoRetryOnJwtFailure() unused, so it's removed.

The policy provider and the clock are stored but not read yet, they are used in #1115. The retry decision and delay in IterableRequestTask are the same as on the base branch.

🧪 How to test?

./gradlew :iterableapi:testDebugUnitTest gives 842 tests, 21 skipped and 0 failures. Checkstyle, lint and the androidTest compile are green.

🧾 Changelog

No customer facing changes

🤖 Generated with Claude Code

@rtlsilva rtlsilva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving, with minor comments pertaining to cases where the following PRs (#1114 and #1115) wouldn't catch the change they're meant to guard against. Everything else still seems to behave as on the base branch.

Comment on lines +319 to +322
assertNotNull(server.takeRequest(1, TimeUnit.SECONDS));
assertNull("The kept task is replayed later, so an inline re-send would duplicate it",
server.takeRequest(500, TimeUnit.MILLISECONDS));
verify(mockTaskStorage, never()).deleteTask(any(String.class));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With autoRetry on, the behaviour that matters is that the SDK keeps the task and schedules a JWT_401 auth refresh (IterableRequestTask.java:308-312), so the task can replay once a fresh token exists. This test checks that the task is kept and not resent, but not that the refresh is scheduled.

ImmediateRefreshAuthManager returns early when successCallback == null (:19-21), and that's exactly the call this path makes. So deleting the scheduleAuthTokenRefresh(…, JWT_401, null) call keeps this test green, and in production the stored task would stay paused with nothing to resume it.

The same applies to OfflineRequestProcessorTest's autoRetry-on case (:138).

Suggest having the test double record the refresh (see the suggestion on ImmediateRefreshAuthManager), and asserting it here:

assertEquals(Collections.singletonList(IterableAuthRefreshReason.JWT_401), authManager.refreshReasons);

where authManager is the ImmediateRefreshAuthManager instance set at :303-304. Ideally the test then also checks that the stored task is replayed with the fresh token once the refresh succeeds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The replay with the fresh token is already covered by testAutoRetryEnabled_ProcessingResumesOnAuthTokenReady and testAutoRetryEnabled_UsesCurrentLiveAuthToken, so i only added the refresh assert here. This test is now part of testAutoRetryEnabled_JwtFailure_TaskRetainedInDBAndNotResentInline.

Server errors follow the existing 0, 0, 0, 6s, 8s, 10s schedule, and code
0 and client errors are not retried.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Passes the network retry policy provider and the remote autoRetry holder
through constructors, adds a clock to the request dispatcher and moves the
JWT error code check into the classifier. Stored tasks and requests sent
after a failed task insert read autoRetry from the holder they carry
instead of the IterableApi singleton. No behaviour change: nothing reads
the policy yet, and the pins cover the JWT 401 path of stored and
directly sent offline requests with autoRetry on and off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xx codes

The new stop test uses a literal 6, so a change to MAX_RETRY_COUNT fails
it. The schedule test now runs for 500, 503 and 599.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…request

ImmediateRefreshAuthManager now records each refresh reason before it
returns on a null callback. The autoRetry-on runner test and the
failed-insert processor test assert a single JWT_401 refresh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… runner

A real IterableApi with offline processing on hands its holder to the
offline processor and its task runner. Passing a new holder anywhere on
that path now fails the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…isting ones

The legacy schedule table now covers the first retry and the existing
backoff, so those two master tests are gone. The retry limit test uses
the literal 6 instead of a copy of it. The two new task runner JWT
tests are folded into the master tests with the same setup, and the
500 ms waits for a request that must not come are now request count
checks, since those dispatchers run inline.

The hand-off test is renamed and says why it exists. Test-only change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Requests and the task runner read autoRetry from the shared remote retry
config now, so nothing calls this method anymore. It is package-private,
so this is not a customer facing change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… policy

The hand-off test now also checks the network retry policy on the
offline processor. Passing the default policy there left the whole
suite green before. Test-only change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@franco-zalamena-iterable
franco-zalamena-iterable force-pushed the feature/SDK-715-b-retry-injection branch from 62cf375 to 91aa3fd Compare November 27, 2026 21:48
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