Skip to content

#1002 Send iOS prompts directly in the foreground and offer Retry when stuck - #1003

Merged
ivanfenenko merged 1 commit into
mainfrom
fix/1002-ios-prompt-send-stall
Nov 9, 2026
Merged

ivanfenenko merged 1 commit into
mainfrom
fix/1002-ios-prompt-send-stall

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1002

On iOS, prompts went only through the background URLSession. Its system daemon can hold an upload without telling the app. When that happened, Send stayed disabled with no error, and the prompt could land minutes later, out of order. The server is ruled out; the investigation is in the issue.

Hardening

  • Direct first. While the app is active, a prompt goes over an in-process session. Only prompts do this; shell and command bodies keep the background path, because resending those would run them twice.
  • Handoff. When iOS is about to suspend the app with the send unanswered, the background session takes over. It also takes over when the direct attempt fails. Every attempt uploads the same body with the same message id. The first success wins, and the other attempt is cancelled.
  • Stall notice. After 20 s with no answer, the chat shows a "Still sending…" snackbar with Retry. Retry resends on a new connection pool, so a stuck connection isn't reused. The snackbar comes back every 20 s while the send is still stuck.
  • Old uploads. At launch, background prompt uploads the app no longer tracks are cancelled once they are older than 2 minutes. Each upload records its creation time in taskDescription.
  • Redirects. Redirects on both upload sessions now follow RedirectPolicy, like REST calls.

Diagnostics (all in the existing diagnostic log)

  • Per send: path, bytes, app state, Low Power Mode, network path (status, constrained = Low Data Mode, expensive, interface).
  • One line per attempt with its reason (send, retry, suspending, direct-failed).
  • A pending line every 10 s with task state and bytes sent/received.
  • URLSessionTaskMetrics per transaction: timings, protocol, reused connection, proxy, constrained/expensive/cellular. Remote addresses are not logged, and errors are logged as domain and code only, because their descriptions contain the server URL.
  • Leftover background tasks at launch, with age, state and what was done with each.
  • message.updated for user messages, which is the server's echo of a prompt. It was hidden before.

Evidence

Real app on an iOS 27.2 simulator against the scenario harness (opencode v2.2.6, scripted model). A scratch TCP proxy held the next /prompt connection.

Held /prompt, 20 s later After Retry Recording (3x)
Still sending snackbar with Retry Prompt delivered and answered Stall then retry

App log for the same run (session id from the harness):

prompt-send #1 start path=/api/session/ses_…/prompt bytes=97 directFirst=true app=active lowPower=false net=satisfied constrained=false expensive=false iface=wifi
prompt-send #1 attempt=1 via=direct reason=send
prompt-send #1 attempt=1 via=direct pending elapsedMs=10049 state=running sent=97/97 received=0 …
prompt-send #1 retry requested
prompt-send #1 attempt=2 via=direct reason=retry
prompt-send #1 attempt=1 via=direct ended after replacement error=NSURLErrorDomain:-999
prompt-send #1 attempt=2 via=direct metrics taskMs=30 … [t1 fetch=network status=200 proto=http/1.1 reused=false proxy=false … sent=97 received=210]
prompt-send #1 attempt=2 via=direct done elapsedMs=32797 status=200

Backgrounding with /prompt held:

prompt-send #2 attempt=1 via=direct pending elapsedMs=20369 state=running sent=99/99 received=0 app=background …
prompt-send #2 attempt=2 via=background reason=suspending
prompt-send #2 attempt=2 via=background done elapsedMs=29958 status=200

The server held one user message per send in both runs.

Checks

  • iOS and Android both covered, or the reason one is not. Android sends prompts in-process with a 60 s socket timeout, so a stuck send already ends in an error with the draft restored. No Android change.
  • Screenshots for UI changes (above)
  • Tests run: full iOS unit suite, 3,371 tests passed. New tests cover direct vs background routing, fallback on a failed direct attempt, HTTP errors not being resent, Retry replacing a held attempt, orphan age rules, the stall snackbar and Retry in the chat view model, and the user-message log line.

Risks / Follow-ups

  • Retry on v1 servers. v2 servers ignore a repeated prompt id (SessionInbox.reconcile). Not checked for v1. Retry resends only after the user taps it, and a handoff resends only an attempt that is cancelled or failed. The old background path already let the daemon resend on its own.
  • Background expiry not tested on a device. The suspending handoff waits for iOS to call the background-task expiration handler, about 30 s on the simulator. Not checked on a physical device or with Low Power Mode.
  • Root cause still open. What held the reporter's uploads is still unknown. The new log lines are meant to show it in the next report.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…n stuck

Prompts went only through the background URLSession, whose daemon can
hold an upload with no signal to the app. A foreground prompt now goes
over an in-process session first and hands off to the background
session when the app is about to be suspended or the direct attempt
fails. After 20 s without an answer the chat shows "Still sending…"
with Retry, which resends on a new connection with the same message id.
Leftover background uploads older than 2 minutes are cancelled at
launch.

The diagnostic log now records each attempt, a pending line every 10 s,
task metrics, app state, Low Power Mode, the network path, leftover
tasks, and the server's echo of user messages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@github-actions github-actions 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.

Automated review: no finding that 2+ of 3 passes agreed on.

4 finding(s) from a single pass, not posted
  • ios/OpenCode Mobile/OpenCode Mobile/UI/SessionChat/Region/SessionChatComposer.swift:1353 high: Stall timer calls MainActor state off the MainActor (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/Data/Remote/DurableJSONUploader.swift:377 high: Cross-origin redirect forwards prompt body to third party (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/Data/Remote/DurableJSONUploader.swift:149 medium: TOCTOU on app-active check picks the wrong transport (muse-spark-1.3-contributor)
  • ios/OpenCode Mobile/OpenCode Mobile/Data/Remote/DurableJSONUploader.swift:305 medium: Kept young orphans complete untracked and out of order (muse-spark-1.3-contributor)

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.112 · 1 pass(es) stopped early

@ivanfenenko
ivanfenenko merged commit 73f467e into main Nov 9, 2026
@ivanfenenko
ivanfenenko deleted the fix/1002-ios-prompt-send-stall branch November 9, 2026 14:11
ivanfenenko added a commit that referenced this pull request Nov 9, 2026
Keep both sides in Session Chat: the draft's Retry action (#1004) and the
"Still sending…" stall Retry from #1003 share the snackbar.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

iOS prompt sends stall silently in the background upload session

1 participant