Repository navigation
Bound overlapping agent hibernation evaluations - #9113
Conversation
📝 WalkthroughWalkthroughAgent hibernation evaluation now uses a main-actor state machine that prevents overlapping runs, coordinates shared index refreshes, supports cancellation, and routes timer ticks through the new scheduling path. Tests cover serialized execution, stale completions, refresh coalescing, and project integration. ChangesAgent hibernation scheduling
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant MainTimer
participant AgentHibernationController
participant SharedLiveAgentIndex
MainTimer->>AgentHibernationController: scheduleEvaluation(now)
AgentHibernationController->>SharedLiveAgentIndex: indexRefreshingNow()
SharedLiveAgentIndex-->>AgentHibernationController: return refreshed index
AgentHibernationController->>AgentHibernationController: evaluate(index, settings, now)
Possibly related PRs
🚥 Pre-merge checks | ✅ 24 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (24 passed)
✨ Finishing Touches 💡 1⚔️ Resolve merge conflicts 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
44278fc to
7ac890f
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Sources/App/AgentHibernationController`+EvaluationScheduling.swift:
- Around line 9-12: Remove the production-only evaluationTask accessor from the
AgentHibernationController evaluation scheduling implementation. Update
cancelEvaluation() to destructure evaluationPhase directly, and revise
AgentHibernationEvaluationSchedulingTests to await the operation-owned
completion signal instead of accessing the removed property.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 24a38471-fd9d-456f-969d-ae850a64a0d7
📒 Files selected for processing (5)
Sources/App/AgentHibernationController+EvaluationScheduling.swiftSources/App/AgentHibernationController.swiftSources/SharedLiveAgentIndex.swiftcmux.xcodeproj/project.pbxprojcmuxTests/AgentHibernationEvaluationSchedulingTests.swift
abdfe05 to
a30df84
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Sources/App/AgentHibernationController+EvaluationScheduling.swift (1)
9-22: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winVerify the duplicate
AgentHibernationTrackingGate.isEnabled()check is intentional.The gate is checked identically before and after
await SharedLiveAgentIndex.shared.indexRefreshingNow()(Lines 12 and 15). If this is meant to re-validate state after the await (since tracking could be disabled while the refresh was in flight), a brief comment would help; if it's a leftover duplicate, the second check should be removed.💡 Suggested clarification
func scheduleEvaluation(now: Date) { startEvaluationIfIdle { [weak self] in guard let self, AgentHibernationTrackingGate.isEnabled(), let index = await SharedLiveAgentIndex.shared.indexRefreshingNow(), !Task.isCancelled, + // Re-check: tracking may have been disabled while awaiting the refresh. AgentHibernationTrackingGate.isEnabled() else { return }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Sources/App/AgentHibernationController`+EvaluationScheduling.swift around lines 9 - 22, Clarify the intent of the duplicate AgentHibernationTrackingGate.isEnabled() checks in scheduleEvaluation: retain the post-await check with a brief comment if it revalidates state after indexRefreshingNow(), or remove it if redundant.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@Sources/App/AgentHibernationController`+EvaluationScheduling.swift:
- Around line 9-22: Clarify the intent of the duplicate
AgentHibernationTrackingGate.isEnabled() checks in scheduleEvaluation: retain
the post-await check with a brief comment if it revalidates state after
indexRefreshingNow(), or remove it if redundant.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: b23f5aa1-7013-4114-a0a9-c1b07468a16f
📒 Files selected for processing (2)
Sources/App/AgentHibernationController+EvaluationScheduling.swiftcmuxTests/AgentHibernationEvaluationSchedulingTests.swift
|
Addressed in 7962a19: the post- |
Summary
Reproduction
From #8740:
Verification
The original history-dependent 1–2 day failure has no stack trace and cannot be honestly reproduced within this PR session. Verification therefore targets the concrete unbounded-overlap mechanism plus live over-cap behavior; this residual uncertainty will remain explicit.
Closes #8740
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Bound agent hibernation evaluations to run one at a time and moved the periodic timer to the main actor to stop overlapping work and CPU spikes, addressing #8740. Cancels in-flight work on lifecycle changes, re-checks the tracking gate after async index refresh, and ignores late completions; the shared live-agent index now owns and coalesces refreshes.
startEvaluationIfIdle/finishEvaluation.scheduleEvaluation(now:);SharedLiveAgentIndex.indexRefreshingNow()returns a fresh index and coalesces callers; re-check the hibernation gate after suspension.Written for commit 7962a19. Summary will update on new commits.
Summary by CodeRabbit