Skip to content

feat(agent): send what is buffered when an app leaves the screen - #92

Merged
youndie merged 1 commit into
mainfrom
feat/flush-when-backgrounded
Oct 6, 2026
Merged

youndie merged 1 commit into
mainfrom
feat/flush-when-backgrounded

Conversation

@youndie

@youndie youndie commented Oct 6, 2026

Copy link
Copy Markdown
Owner

M-146 (research-clients K5), with one correction to K5.

A server is told it is going away and stop() delivers the last records. An app is backgrounded and then suspended or killed without another word, losing up to one flush interval — the records closest to the person leaving.

  • TracyDelivery.flushWhenBackgrounded(): AutoCloseable hooks the platform's own signal to requestFlush(): Android ON_STOP of the whole process (androidx.lifecycle:lifecycle-process), iOS UIApplicationDidEnterBackgroundNotification, browser visibilitychange to hidden and pagehide, desktop JVM a shutdown hook calling stop(). Linux/macOS native are servers here and do nothing — kore orders their shutdown.
  • Correction to K5: navigator.sendBeacon cannot carry headers and the key travels in X-Tracy-Key. Instead every browser send is fetch with keepalive (Ktor 3.6 fetchOptions), and the batch is capped at 60 KiB on wasm because the keepalive quota is 64 KiB.
  • Browser test: with a one-hour flush interval, a pagehide event delivers the batch within seconds (MockEngine). Checked the other way round: without the hook it times out.
  • Local: :agent:wasmJsBrowserTest, :agent:jvmTest green; Android and iOS compile. Not run on a device: the Android and iOS hooks only compile here; that check belongs to M-148.
  • README: how an app wires it, and that an app's maxBatchBytes must stay under the server's 64 KiB client ceiling.

A server is told it is going away and stop() delivers the last records; an app
is backgrounded and then suspended or killed without a word, losing up to a
flush interval of the records closest to the person leaving. The platform's own
signal now asks for a flush, and in the browser every send is keepalive with
the batch capped below that quota: sendBeacon cannot carry the key header.

Refs: M-146
@youndie
youndie merged commit 4bfb423 into main Oct 6, 2026
1 check passed
@youndie
youndie deleted the feat/flush-when-backgrounded branch October 6, 2026 23:01
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