fix: work in flight hangs after the app is suspended in the background

Open
#1,635 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
dart, flutter, ios
Domain
mobile

Research direction

Start with SSHKeepAlive.ping() in packages/dartssh2/lib/src/ssh_keepalive.dart: add a timeout and close the client on failure so later pings still run. Then bound the cancel paths — collectSshExecOutput in lib/core/utils/ssh_exec.dart (await commandDone) and _terminateAiCommandSession in lib/view/page/ssh/page/ask_ai.dart. In fl_pi_llm's runtime.dart add a stream stall watchdog and a resume check; wrap in-flight iOS runs in beginBackgroundTask. Done when a connection killed during suspension ends within the short wait instead of hanging.

Written by the indexing model from the issue text.

Description

bug

A run or connection that is in flight when the app is suspended in the background can hang after resume, and nothing ends it.

SSH
  • SSHKeepAlive (packages/dartssh2/lib/src/ssh_keepalive.dart): ping() has no timeout and a failure never closes the client. One unanswered ping stops every later keepalive, so a silently dead connection (NAT/server dropped it while suspended) is never detected.
  • Cancel paths wait on session.done with no limit: collectSshExecOutput (lib/core/utils/ssh_exec.dart, await commandDone) and _terminateAiCommandSession (lib/view/page/ssh/page/ask_ai.dart). On a dead connection neither the 5-minute tool timeout nor Stop ends an Agent tool call. Fall back to closing the channel/client after a short wait.
  • ServerNotifier keeps a client whose status read timed out and marks it connected; ensureShellClient/ensureExec reuse it. Nothing checks state.client on resume (terminal tabs reconnect, but they own separate clients).
Agent (fl_pi_llm)
  • LLM HTTP streams have no stall timeout (runtime.dart, default HttpClient, body read with no watchdog).
  • No lifecycle handling: a run suspended mid-request or mid-tool is not checked on resume.
iOS
  • No beginBackgroundTask around an in-flight transfer. UIBackgroundModes declares fetch with no handler (removed).
  • No beginBackgroundTask around an in-flight Agent run: needs fl_pi_llm to say whether any chat is running (InFlightWork TODO).

Related: a run cut off by the process being killed was left holding its session ("Lane "main" already has an active operation"); fixed in fl_pi_llm. Android Agent runs keep the foreground service up in a separate change.

Done in #1705 (lollipopkit/dartssh2#26). The rest is fl_pi_llm.

Dominant language
Dart
Stars
8.9k
Forks
573
Avg merge
2h 11m
Merged PRs (30d)
134

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lollipopkit/flutter_server_box

All issues in lollipopkit/flutter_server_box

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.