Skip to content

Keep the app answering taps when the API stalls - #183

Draft
simonhamp wants to merge 3 commits into
mainfrom
fix/api-stall-freeze
Draft

simonhamp wants to merge 3 commits into
mainfrom
fix/api-stall-freeze

Conversation

@simonhamp

Copy link
Copy Markdown
Member

When the API takes a connection and never answers, the whole app stops answering taps until the API comes back. That's what you get from kill -STOP on the local API, and from a hung or overloaded server in real life.

What was wrong

The Log, Profile, Notifications, Remotes and conversation screens check for an incoming call every 3 seconds (WatchesForCalls::checkForCall(), #[Poll(3000)]). The check called Client::incomingCall() directly, so the request ran on the PHP thread that runs the screens' event loop. With a stalled API it waited out the whole 20 second timeout (Client::send(), Http::timeout(20)). By then the next check was due, so the loop was blocked nearly all the time and taps were handled one at a time in the gaps.

On iOS, sample during a stall shows the main thread idle and the PHP worker thread (php_worker_main → do_dispatch) in zif_curl_exec → curl_easy_perform → poll for the whole sample. On Android the app's log showed GET remotes/call from Log::checkForCall failing after 20006ms, back to back. Tapping New commit took 19 seconds on iOS and 22 on Android to open the composer.

What changed

  • The call check is signed on the UI thread, as the screens' refreshes are, and sent with FetchInBackground. Only one is out at a time, it gives up after 8 seconds instead of 20, and a failed check stays quiet. Client::sendSigned() and FetchInBackground take a timeout for this.
  • A commit whose request timed out came back as "could not connect to the server", with the draft reopened. The API did get that request and may still post it once it recovers, which it did in my test, so sending the draft again would post it twice. A timed-out request now gets the outbox's existing Outbox::NoAnswer message ("devnull didn't answer in time, so this commit may not have gone. Check before you send it again."), as a task that times out already does. A request that never connected still says it couldn't connect.
  • On Android a tab draws skeleton rows first and fills in what it kept when FirstFrame comes back from a background thread. There are four of those threads, and during a stall all of them wait on the API, so FirstFrame queued behind them and the tab sat on skeleton rows for its 10 second timeout. It now gives up after 2 seconds.

Related, not in this PR

mobile-air runs a background task whose watchdog has already fired if it was still waiting for a thread. During a stall that keeps the threads busy with work nobody is waiting for, and it can send a write the screen has already given back to you. I have a small patch for NativeComponent::handleAsyncCompletion() that drops the payload of a failed task so a late run does nothing. This PR doesn't depend on it.

Other requests still run on the UI thread when you tap something: some "load more" pages, Show more replies, follow, mute, block, pin, delete, report, @mention suggestions, and the call screen. During a stall each of those holds the app for up to 20 seconds after the tap. The app recovers afterwards, but they could move to the background the same way.

Testing

  • 1,901 tests pass, run serially. New ones in CallTest, OutboxTest, ClientCacheTest and LogsTest.
  • iOS (iPhone 18 Pro simulator, iOS 27.0) and Android (API 35 emulator) against a local dev-null.sh, stopped with kill -STOP mid-session and resumed with kill -CONT. Before: the composer took about 20 seconds to open and the tabs sat on skeleton rows. After: the composer opens at once, the commit shows as staged, tabs switch and fill in, and when the request times out the toast says the commit may not have gone and the draft comes back.

Screenshots

Light mode only: nothing about how the screens look changed, only whether they answer. The captions say what was tapped and when. The recordings show the whole run.

stall

iOS light iOS dark Android light Android dark
Before
After

Recordings: Android light, after, Android light, before, iOS light, after, iOS light, before

  • No visible change

🤖 Generated with Claude Code

simonhamp and others added 3 commits November 18, 2026 04:01
… app

The call check on the Log, Profile, Notifications, Remotes and
conversation screens polled GET remotes/call every 3 seconds on the UI
thread. When the server took the connection and never answered, each
check held the UI thread for the full 20 second timeout, and the next
check was already due when it gave up, so taps went unanswered until the
server came back.

The check is now signed on the UI thread and sent with FetchInBackground,
like the screens' refreshes. Only one is out at a time, it gives up after
8 seconds instead of 20, and a failed check stays quiet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A commit sent while the server was stalled timed out after 20 seconds and
came back as "could not connect to the server", with the draft reopened.
That's wrong: the request did reach the server, which may still post it,
so sending the draft again could post it twice.

FetchInBackground now says when a request timed out, as against one that
never connected, and the outbox treats a timeout the way it already
treats a task that gave up waiting: Outbox::NoAnswer, which asks you to
check before you send it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Android a tab draws skeleton rows first and fills in what it kept once
FirstFrame, an empty task, comes back from a background thread. There
are four of those threads. While the server takes requests and doesn't
answer, all four sit waiting on it, so FirstFrame queued behind them and
the tab showed skeleton rows until its 10 second watchdog fired, with the
kept rows ready the whole time.

FirstFrame now gives up after 2 seconds, and the tab fills in then.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant