[build-tools] Add max_idle_minutes to agent-device remote session step#3781
[build-tools] Add max_idle_minutes to agent-device remote session step#3781szdziedzic wants to merge 1 commit into
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Subscribed to pull request
Generated by CodeMention |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3781 +/- ##
==========================================
- Coverage 57.16% 57.12% -0.04%
==========================================
Files 905 905
Lines 39284 39322 +38
Branches 8227 8236 +9
==========================================
+ Hits 22454 22459 +5
- Misses 15358 15388 +30
- Partials 1472 1475 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| // - return true so the daemon's own token check stays the source of | ||
| // truth for authorization, |
There was a problem hiding this comment.
i don't see token being validated around https://github.com/callstackincubator/agent-device/blob/5b63b9b427b218f685bb01812a0d04bcbb5514f3/src/daemon/http-server.ts#L569
| // When a max-idle window is set, install an auth hook that stamps the | ||
| // current time into IDLE_STATE_PATH on every authenticated daemon | ||
| // request. The watchdog below polls that file to detect inactivity. | ||
| const idleEnv: Record<string, string> = {}; |
There was a problem hiding this comment.
idleEnv is a bit of a weird name
cf313cf to
042d61f
Compare
|
❌ It looks like a changelog entry is missing for this PR. Add it manually to CHANGELOG.md. |

Why
The
eas/start_agent_device_remote_sessionstep keeps the turtle job alive indefinitely (new Promise<never>(() => {})) untilstopDeviceRunSessioncancels it. If a client connects, disappears, and never sendsstopDeviceRunSession, the worker burns until the orchestrator'smax_run_time_secondsceiling fires. We want a tighter, activity-aware ceiling so abandoned sessions release their worker quickly.How
Adds an optional
max_idle_minutesbuild function input. When set, the step:${tmpdir}/agent-device-idle-hook.mjsthat stampsDate.now()into${tmpdir}/agent-device-last-activityon every authenticated daemon request, then returnstrueso the daemon's own token check remains the source of truth for authorization.AGENT_DEVICE_HTTP_AUTH_HOOKpointing at that module. This is a documented extension point on agent-device's HTTP server (src/daemon/http-server.tsloadHttpAuthHook); it fires for/rpc,/upload, and/artifacts/*— every meaningful client call — while skipping/health, so cloudflared/health probes don't reset the timer.waitForIdleTimeoutAsync) against the existingawait new Promise<never>(() => {}). The watchdog polls the state file every 30s; ifDate.now() - lastActivityAt >= maxIdleMinutes * 60_000, it throwsSystemError. That fails the step and cascades to the device run session via the existing turtle-job-status trigger.When
max_idle_minutesis absent or non-positive, the step behaves exactly as before (no hook installed, no watchdog, infinite wait).The state file is pre-seeded with the current time before the daemon starts so the first poll has a baseline; malformed/missing state is treated as fresh activity rather than firing a false-positive timeout.
The complementary www-side change that plumbs this from the GraphQL
createDeviceRunSessionmutation lives in a follow-up PR; until that ships, no caller passes the new input so the step is a no-op for everyone.Test Plan
yarn typecheck(build-tools): cleanyarn linton the changed file: 0 errorsyarn fmt:check: cleanyarn jest-unit(build-tools): 522/522 pass