Skip to content

#701 Drop the stale REST pool when live updates stall - #703

Merged
ivanfenenko merged 1 commit into
mainfrom
fix/701-drop-stale-rest-pool
Oct 17, 2026
Merged

ivanfenenko merged 1 commit into
mainfrom
fix/701-drop-stale-rest-pool

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • When an SSE connect budget is exceeded, drop the process-lifetime REST connection pool and let the existing retry dial a fresh one. A restart was doing this; the in-app retry was not.
  • iOS replaces OpenCodeURLSessions.rest and REST clients read that pool at request time. An injected test session stays fixed.
  • Android wires the existing budget onEvict hook to OpencodeHttpClient.rebuild().

Checks

  • iOS: xcodebuild test OpenCodeURLSessionsTests + EventsAPIClientTests on iPhone 17 simulator. TEST SUCCEEDED (15 tests, 0 failures).
  • Android: ./gradlew :app:testDebugUnitTest --tests dev.opencode.mobile.data.remote.EventsApiTest. BUILD SUCCESSFUL.

Issue

Risks / Follow-ups

  • Replacing the REST pool cancels in-flight REST requests. That is intentional: those sockets are on the same stale pool.
  • Ordinary SSE transport errors, such as a brief -1005 after backgrounding, still leave the pool alone.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith with what you need.


Note

Medium Risk
Replacing the REST pool cancels in-flight REST requests by design; scope is limited to SSE connect-budget failures, not ordinary transport errors.

Overview
When live updates stall because an SSE connect budget fires (hung handshake), the app now drops the process-wide REST pool so the next retry uses fresh sockets—matching what a full restart already did.

On iOS, OpenCodeURLSessions gains replaceRest() (swap + cancel the old pool). REST API clients no longer capture a fixed URLSession; they resolve the live pool at request time via restResolver, while injected test sessions stay pinned. EventsAPIClient takes onConnectBudgetExceeded and DI wires it to replaceRest().

On Android, sessionEventsApi connects the existing SSE onEvict hook to OpencodeHttpClient.rebuild(), with DI and a unit test asserting a single rebuild on budget exceed.

Tests cover pool replacement behavior and that the budget callback fires once without affecting injected SSE sessions.

Reviewed by Cursor Bugbot for commit 7898d00. Bugbot is set up for automated code reviews on this repo. Configure here.

@ivanfenenko
ivanfenenko marked this pull request as ready for review October 16, 2026 20:43
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7898d00. Configure here.

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.

Reconnect without restarting when live updates stall

1 participant