feat(gastown): add proactive idle-container stop in TownDO alarm#3113
Merged
kilo-code-bot[bot] merged 3 commits intogastown-stagingfrom May 7, 2026
Merged
feat(gastown): add proactive idle-container stop in TownDO alarm#3113kilo-code-bot[bot] merged 3 commits intogastown-stagingfrom
kilo-code-bot[bot] merged 3 commits intogastown-stagingfrom
Conversation
added 2 commits
May 7, 2026 16:07
When a town has no active work and the mayor has been idle for >5min, the alarm handler now calls container.stop() to force a graceful SIGTERM drain instead of waiting for Cloudflare's port-idle timer (which gets reset by PTY WebSocket keep-alives). This targets the root cause of 300+ active containers for ~100 active users. - Add stopContainerIfIdle() with dependency-injected logic in town/container-idle-stop.ts for testability - Wire into alarm handler just before the re-arm block - Emit container.idle_stop event with reason for observability - 2min throttle prevents thrash; failed stops are retried next tick - 13 unit tests covering all branches
Replace mayor.last_activity_at! with null-safe checks using mayor.last_activity_at != null guards, consistent with coding style that forbids ! non-null assertions.
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Reviewed by gpt-5.5-2026-04-23 · 318,978 tokens |
The state guard only checked for 'running', but containers can also report 'healthy' as an active state (consistent with gastown.worker.ts). Added 'healthy' to the guard and a corresponding test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add proactive idle-container stop to the TownDO alarm handler. When a town has no active work and the mayor has been idle for >5 minutes, the alarm now calls
container.stop()to force a graceful SIGTERM drain instead of waiting for Cloudflare's port-idle timer (which gets reset by PTY WebSocket keep-alives from dashboard terminals). This targets the root cause of 300+ active containers for ~100 active users.stopContainerIfIdle()method with dependency-injected logic intown/container-idle-stop.tsfor testabilitycontainer.idle_stopevent with reason (no_active_work/mayor_idle_Xm) for observabilityVerification
stopContainerIfIdle()after the idle thresholdVisual Changes
N/A
Reviewer Notes
container-idle-stop.ts) with injected dependencies, making it fully testable without DO infrastructuregetState()is used (control-plane RPC) instead offetch()orwarmUp()to avoid waking a sleeping container!non-null assertion onmayor.last_activity_atwas removed in favor of!= nullguards, consistent with the project coding style