docs/connection-stability.md
Connection stability and discovery limits
Separate connection loss from work failure
A provider retry notice or a well-formed service RPC error is not a connection failure. The client must keep the established connection while reporting the operation's status. Disconnect details distinguish SSH/network loss, a closed EzAgent forwarding stream, application/protocol failure, and forced local Android shutdown. An SSH-connected observation is a snapshot, not proof that the network or the whole remote daemon is healthy.
The client never automatically replays prompts or other actions on reconnect. The explicit Reconnect action follows the normal saved-endpoint connection flow, including fresh credentials/unlock where required. Reports contain fixed safe categories and allowlisted protocol diagnostics, never raw peer/system errors or credentials. Disconnect reports are memory-only and are cleared by a new attempt or an explicit disconnect. Bounded command/attention incident history has a separate notification and resolution lifetime; it is not current transport health.
Service-channel recovery is not SSH reauthentication
A fatal JSONL/forwarding-channel failure can retire the service generation and reopen the same authorized AF_UNIX target on the still-authenticated SSH session. The new client must complete hello/start before any Session capability is published. New-generation owners reload authoritative history, settings and sidebar data, while late callbacks and pending operations from the old generation remain fenced. Drafts, attachment ownership and selection remain local; no prompt, macro or mutation is copied or replayed.
Automatic service repair has one attempt per authenticated SSH connection, bounded by a 15-second deadline covering channel open and handshake. Another failure, or failed/timed-out repair, disconnects the endpoint and releases SSH instead of leaving an idle Connecting state. This includes stopping the service for an upgrade: if the immediate repair runs while its socket is absent, use Reconnect after the new service starts. There is no periodic retry or silent SSH reauthentication.
Reload service connection remains an explicit channel-only attempt while the existing SSH owner is healthy and no competing connect/disconnect/repair owns it. Its confirmation warns that pending results may become unconfirmed; failure also disconnects. Closing a retired channel adapter cannot close the SSH session handed to its successor; explicit Disconnect still owns and closes the current SSH lifetime, including a blocked candidate handshake.
A well-formed operation/read rejection does not trigger channel repair. Bounded read refresh and failed/incomplete discovery remain separate from transport health. Successful channel recovery is not evidence that an uncertain operation was accepted or rejected; its historical evidence and affected-operation safety restriction must remain distinct from current connection health. If SSH itself is lost, the normal explicit connection flow requires fresh mode-appropriate unlock/password and host trust. No unlocked credentials are cached for silent SSH reconnect.
Required Android foreground lifetime
Connections fail closed if the required foreground service cannot start or publish its ongoing notification. Failure shutdown enters a terminal guard before notifying connection owners: registry notifications are synchronous, so stopping endpoints first could re-enter a failing notification publication indefinitely. Unexpected service destruction also closes active endpoints with a typed local Android cause, rather than disguising it as a user disconnect or a remote daemon failure. This cannot guarantee a final report after OS process death.
Discovery liveness and stale metadata
Inbox leaves are required data; root-to-directory grouping is optional presentation enrichment. A pending roots lookup must not block leaf publication or later leaf refreshes. Without mapping, rows use an unknown-directory heading. Navigation still resolves and validates the exact target's persisted directory; it never treats grouping, an Intent path, or a saved default as target authority. Late enrichment cannot relabel a different generation/scope/request's leaves.
Snapshot retirement is not RPC settlement. Required leaf discovery retains one flight per connection generation and exact workspace scope across hide/show, detach/reattach, tab/filter changes and scope round trips. Later demand coalesces behind that flight rather than consuming another process-wide request reservation. The supplementary scoped startup-restore read has its own flight guard and cannot block the required Inbox snapshot. Terminal success or failure releases only its own guard even when its presentation is obsolete or hidden; obsolete results do not install leaves, grouping, errors or startup selection. Visible queued demand can then admit a fresh read. Connection retirement clears the generation's guards while the transport releases its retired requests. No elapsed timeout is used.
A failed monitor refresh, including rejection of a snapshot above the monitoring count limit, marks counts unavailable and suppresses clock-only projection of the retained stale snapshot. A successful refresh restores current counts. The connection remains usable on operation-level discovery failures. Refresh failures do not create an immediate self-retry loop.
Large inventories: mitigated, not fully bounded
The JSONL reader retains a 48 MiB per-frame limit. An incoming frame above that bound is still a terminal protocol failure on its owning JSONL connection. The current service list operations return an entire result in one frame; they have no pagination, byte budget, truncation indicator, or lightweight root map. Client-side future error handling happens after framing and cannot contain that failure. Raising/removing the frame limit or blindly discarding an oversized line would not provide a safe resource contract.
Android reduces avoidable exposure:
- Alert monitoring requests leaf metadata only, not every root's configuration merely to warm notification navigation.
- Single-session directory resolution uses the existing exact-leaf
leaf_stats.root_cwdinstead of downloading unrelated roots and configurations. - Optional sidebar roots discovery is single-flight, independently of leaf refresh liveness; it does not fan out one stats request per listed leaf.
- Failed metadata refreshes are visibly unavailable rather than silently current.
Residual risk: global leaf discovery and optional root inventories are still unpaginated and share the primary stream. A sufficiently large valid reply can still disconnect that client. These reductions are not a claim that the complete oversized-discovery failure path is fixed, or that it caused a particular incident. Leaf stats itself is not a formally byte-bounded directory-only operation.
A full solution needs byte-bounded service pages with explicit continuation, completion, and oversized-record semantics, plus a lightweight directory projection. Android-only failure containment could instead isolate inventory traffic on a separately owned forwarding channel/JSONL client bound to the same SSH generation. That requires independent channel lifetime and bounded retry/work ownership; it must not close the parent SSH session on discovery-only failure. Neither mechanism is implemented here. New protocol options must not be sent on the assumption that an existing service honors them.