Skip to content

fix(parser): end sessions at screen-off instead of dropping long ones - #336

Open
0xbrayo wants to merge 2 commits into
ActivityWatch:masterfrom
0xbrayo:fix/session-long-durations
Open

0xbrayo wants to merge 2 commits into
ActivityWatch:masterfrom
0xbrayo:fix/session-long-durations

Conversation

@0xbrayo

@0xbrayo 0xbrayo commented Oct 8, 2026

Copy link
Copy Markdown
Member

Part of #333.

SessionParser dropped any session at or above MAX_REASONABLE_SESSION_DURATION (4 hours). Genuine long sessions, such as navigation, video or a reading app, disappeared from the timeline entirely. The cap was a guard against a session staying open because its ACTIVITY_PAUSED never arrived, but turning the screen off is a much tighter and more accurate bound.

Change

  • The parser now also reads SCREEN_NON_INTERACTIVE and DEVICE_SHUTDOWN, and either one ends the open session. Nothing is in the foreground once the screen is off, whether or not the app's PAUSE was recorded.
  • The sanity cap is raised to 24 hours. It now only guards against a corrupt event stream.
  • The foreground state machine moves into a pure parseForegroundSessions(events, appName) so it can be unit-tested without a Context; SessionParser delegates to it. Behaviour is otherwise unchanged.

Testing

  • New ForegroundSessionsTest: a 5-hour session is kept, and screen-off ends a session whose PAUSE never arrives. I confirmed both fail with the old 4h cap and no screen-off handling.
  • ./gradlew :mobile:testStandardDebugUnitTest passes.

@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain.

Summary

SessionParser now ends sessions at screen-off or shutdown and raises the duration limit from four to 24 hours.

  • App sessions end at screen-off and can last up to 24 hours.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read usage event] --> B{Event type}
  B -->|App resumes| C[Keep same app open or switch apps]
  B -->|Current app pauses| D[Close open session]
  B -->|Screen off or shutdown| D
  B -->|Another app pauses| E[Ignore event]
  C --> F[Continue reading]
  D --> F
  E --> F
  F --> G{Open session at end?}
  G -->|Yes, and end supplied| H[Close at supplied end]
  G -->|Otherwise| I[Return sessions]
  H --> I
Loading

Reviews (3) · Last reviewed commit: "test(parser): cover the foreground rules..." · Reviewed by Greptile

@0xbrayo

0xbrayo commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

🤖 Claude, on behalf of @0xbrayo

@greptile review

SessionParser discarded any session of 4 hours or more, losing genuine
long sessions (navigation, video, reading). The cap guarded against a
missing PAUSE keeping a session open overnight; close the open session
on SCREEN_NON_INTERACTIVE and DEVICE_SHUTDOWN instead, and keep only a
24h sanity bound. The state machine moves to a pure function so it can
be unit-tested.
…ssions

Same-app re-resume keeps the original start, another app's resume ends
the session without a pause, a stale pause from another app is ignored,
and the trailing open session is not emitted.
@0xbrayo
0xbrayo force-pushed the fix/session-long-durations branch from 4bac96d to c1ea654 Compare October 11, 2026 13:13
@0xbrayo

0xbrayo commented Oct 11, 2026

Copy link
Copy Markdown
Member Author

🤖 Claude, on behalf of @0xbrayo

@greptile review

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