Skip to content

CloudAgent - Fix idle cleanup skipping sessions with no executions#3185

Open
eshurakov wants to merge 1 commit into
mainfrom
eshurakov/cloud-agent-idle-cleanup-no-execution-fallback
Open

CloudAgent - Fix idle cleanup skipping sessions with no executions#3185
eshurakov wants to merge 1 commit into
mainfrom
eshurakov/cloud-agent-idle-cleanup-no-execution-fallback

Conversation

@eshurakov
Copy link
Copy Markdown
Contributor

@eshurakov eshurakov commented May 11, 2026

Summary

Fix a regression from #3176 where cleanupIdleKiloServer returned early for sessions with zero executions, leaving their containers running indefinitely. When no executions exist, the method now falls back to metadata.preparedAt (set when the session is prepared and the container starts) to compute idle time. If neither executions nor preparedAt exist, it returns early — those sessions genuinely have nothing to clean up.

This caused both "Session has not been initiated yet" errors (containers alive but preparation never completed) and containers hanging around without being killed (the reaper alarm skipped them every cycle).

Verification

Confirmed via Axiom logs that the success rate for prepareSession collapsed from ~80% to ~12% starting at 15:30 UTC today, exactly when #3176 was deployed.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 11, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

Two commits reviewed. Both are correct.

Commit 1 (41a7a2b): Moved getMetadata() earlier and added metadata.preparedAt fallback when no executions exist — correctly fixes the regression from #3176.

Commit 2 (155288c): Adds ?? metadata.timestamp as a second fallback after preparedAt. Since timestamp is the "last save timestamp" (number, always set) on every metadata write — including registerSession — this ensures sessions that were registered but never fully prepared (no preparedAt) are still reaped after the idle timeout rather than hanging forever. The if (!lastActivity) return guard below is now effectively dead in the no-executions path but remains as a correct safety net.

Files Reviewed (1 file)
  • services/cloud-agent-next/src/persistence/CloudAgentSession.ts

Reviewed by claude-sonnet-4.6 · 300,040 tokens

Copy link
Copy Markdown
Contributor

@evanjacobson evanjacobson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. DM'd a comment that it would be nice to have a regression test alongside this change to avoid this in the future

@eshurakov eshurakov force-pushed the eshurakov/cloud-agent-idle-cleanup-no-execution-fallback branch from 41a7a2b to 155288c Compare May 11, 2026 19:29
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.

2 participants