feat(DRC-2081): implement frontend idle detection mechanism
Implements a hybrid idle detection system to prevent unexpected server timeouts when users are actively using the application.
Backend changes:
- Add POST /api/keep-alive endpoint to reset idle timer
- Expose idle_timeout field in /api/instance-info response
- Add debug logging for keep-alive requests
Frontend changes:
- Add RecceInstanceInfo.idle_timeout field in TypeScript interface
- Create sendKeepAlive() API client with error handling
- Implement useIdleDetection hook with the following features:
- Monitors multiple activity types (focus, mousemove, keydown, scroll)
- Dynamic debounce interval: idle_timeout / 3 (clamped 30s-5min)
- Tab awareness using Page Visibility API (pauses when inactive)
- Lock mechanism prevents concurrent API calls
- Activity log throttling (max 1 log per second)
- Dev-only logging (disabled in production builds)
- Integrate IdleDetector component in app Providers
Key implementation details:
- Uses optimistic locking to prevent race conditions
- Updates lastActivityRef before API call to prevent duplicate sends
- Only activates when server has idle_timeout configured
- Automatically adapts debounce interval to server configuration
- Immediately sends keep-alive when tab becomes active after 5+ minutes
🤖 Generated with Claude Code
PR checklist
- [ ] Ensure you have added or ran the appropriate tests for your PR.
- [ ] DCO signed
What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
| Files with missing lines | Coverage Δ | |
|---|---|---|
| recce/server.py | 50.89% <100.00%> (+0.89%) |
:arrow_up: |
| tests/test_server.py | 100.00% <100.00%> (ø) |
... and 5 files with indirect coverage changes
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@iamcxa I've opened a new pull request, #971, to work on those changes. Once the pull request is ready, I'll request review from you.
@copilot open a new pull request to apply changes based on the comments in this thread
@iamcxa I've opened a new pull request, #972, to work on those changes. Once the pull request is ready, I'll request review from you.