bafe000Open thread| … | … | @@ -159,6 +162,28 @@ export function isAutoSettlementCandidate( | |
| 181 | + | const completedAtMs = toMillis(thread.latestRunCompletedAt); | |
| 182 | + | return completedAtMs === null || completedAtMs < requestedAtMs; | |
| 183 | + | } | |
| 184 | + | return nowMs - heldWorkEndedAtMs < AGENT_WAKE_GRACE_MS; | |
🟠 High orchestration-v2/ThreadSettlementService.ts:180
When a wake was queued before the sweep observes the background work ending, awaitingAgentWake treats that still-outstanding wake as absent after the grace period, allowing settlement to cancel it and lose the continuation. Because heldWorkEndedAtMs is the sweep observation time, the request timestamp can be earlier; check whether the latest request is incomplete regardless of that timestamp, while retaining the grace period when no request is outstanding.
| 1 | if (requestedAtMs !== null) { |
| 2 | const completedAtMs = toMillis(thread.latestRunCompletedAt); |
| 3 | if (completedAtMs === null || completedAtMs < requestedAtMs) return true; |
| 4 | if (requestedAtMs >= heldWorkEndedAtMs) return false; |
| 5 | } |
| 6 | return nowMs - heldWorkEndedAtMs < AGENT_WAKE_GRACE_MS; |
🤖 Copy this AI Prompt to have your agent fix this:
| 1 | In file @apps/server/src/orchestration-v2/ThreadSettlementService.ts around lines 180-184: |
| 2 | |
| 3 | When a wake was queued before the sweep observes the background work ending, `awaitingAgentWake` treats that still-outstanding wake as absent after the grace period, allowing settlement to cancel it and lose the continuation. Because `heldWorkEndedAtMs` is the sweep observation time, the request timestamp can be earlier; check whether the latest request is incomplete regardless of that timestamp, while retaining the grace period when no request is outstanding. |
Fixed in bbd1115. awaitingAgentWake now holds while the latest run is outstanding, whatever its timestamp, and keeps the grace only when no run is outstanding. Added a test for a wake run requested just before the sweep saw the work end, still queued past the grace; it fails on the previous logic.
Sorry, I'm unable to act on this request because you do not have permissions within this repository.