Add /idle endpoint for hosting platform idle tracking#13146
Add /idle endpoint for hosting platform idle tracking#13146mslynch wants to merge 2 commits intoposit-dev:mainfrom
Conversation
Adds a /idle HTTP endpoint on the Positron server/REH build that hosting platforms (e.g. Posit Cloud) can query to determine how long the user has been idle. The response includes seconds_idle, last_activity_epoch_ms, and connected_clients. Activity signals originate from the existing IUserActivityService in the browser (DOM events: keydown, mousedown, touchstart). A new browser-side workbench contribution forwards activity timestamps to the server via a dedicated IPC channel. A new node-side service aggregates timestamps across connected clients (taking the most recent) and exposes the resulting idle info via the HTTP endpoint. Includes unit tests for the service and IPC channel pair. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the per-client Map<string, number> with a single monotonic lastActivityEpochMs. Drop the connectedClients field from the response, the clientId parameter from reportActivity, and the removeClient method. Rationale: the core signal (max activity timestamp across all clients) is naturally preserved by monotonic updates. Per-client tracking added complexity without meaningful benefit for Posit Cloud's use case. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
FYI we'll need to treat this like a community-contributed PR and apply the changes in a new, non-fork PR because of the problems outlined in #6628. |
|
This checks user activity but not kernel activity; i.e. if you start a long-running computation and close the browser tab, your session will quickly begin reporting as |
Yes - we're planning on calling the Kallichore API as well for that. |
|
Opened #13169 as a non-fork PR for repo secret purposes. I'll close this one out! |
Summary
Adds a
/idleHTTP endpoint on the Positron server/REH build that Posit Cloud can query to determine how long the user has been idle.Architecture
The existing
IUserActivityServicekeeps track of DOM events (e.g.keydown,mousedown,touchstart. A new browser-side workbench contribution,PositronIdleReporterContribution, registers a callback to watch activity changes, upon which it forwards timestamps to a new IPC channel every 30s. A new service,PositronIdleTrackingService, keeps the most recent timestamp monotonically and exposes the result via the HTTP endpoint.Response format
Behavior notes
Since timestamps are sent every 30 seconds, the idle time may be reported up to 30s even while Positron is in use.
Opening a tab counts as activity for ~60-70s.
IUserActivityServiceinitializesisActive = trueon construction, treating the act of opening the window as an implicit activity signal (see the service's own comment). The bundledDomActivityTrackerthen verifies continued activity via DOM events: after 2 poll intervals (~60s) with nokeydown/mousedown/touchstart, plus a 10s debounce, it flips toisActive = false.In practice: if a user opens a tab and walks away without interacting,
seconds_idlewill report0for approximately 60-70 seconds before it begins to climb. This is expected and acceptable for session-management use cases where idle timeouts are on the order of minutes or hours, but it's worth noting for any consumer that expects sub-minute precision.Release Notes
New Features
Bug Fixes
QA Notes
@:sessions
This feature only activates in the server/REH build and requires Linux (license manager is Linux-only).
Automated tests
```bash
./scripts/test.sh --run src/vs/platform/positronIdleTracking/test/node/positronIdleTrackingService.test.ts
./scripts/test.sh --run src/vs/platform/positronIdleTracking/test/common/positronIdleTrackingIpc.test.ts
```
Manual verification (Linux only)
```bash
npm run build-start && npm run build-check
./scripts/code-server.sh --connection-token test-token --license-key-file /path/to/license.lic
```
```bash
curl -s "http://localhost:/idle?tkn=test-token" | jq .
```
🤖 Generated with Claude Code