Repository navigation
fix(v2): stabilize stall counter and retry ladder - #51
Conversation
- Treat synthetic interruption recovery as non-user input; keep userCancelled latched. - Tolerate OWN_PROMPT_TIME_MS clock skew in selfInjectFresh. - Do not reset workRetries on execution.started fallback; reset only on confirmed genuine user message. - Cancel queued recovery on user stop (recoverTimer, pendingRecoveryArmed, recoverGeneration).
|
I don't see any tests |
Just to give context on how I've been validating changes: I run a daily audit job (around 8 AM) that reviews session counters from the last 24 hours and flags variances. I use those reports to identify and fix issues, testing against my live session. I've been running these checks against both our branches since changes in one area can impact counters elsewhere. For visibility during debugging, I had added a debug log intended to be disabled by default, but I understand you removed it from your build—that's your call. Separately, I noticed the bot created a draft PR earlier than expected. The PR is marked as "Work in Progress" and not ready for review. Could you confirm the preferred workflow here—should I close auto-submitted drafts when I spot them, or is there another process you'd prefer? I wasn't sure of the standard procedure, so wanted to ask rather than guess. |
Why
The v2 stall counters (
attempt N/M (retry #K)) could move even when the user never saw the nudge, or reset for the wrong reason. That produced duplicate/phantom counts, mid-episode drops, clock-skew false resets, and a queued recovery that could fire after a user stop.Changes
isSyntheticInterrupt()identifies that message;noteInboundUserMessagekeepsuserCancelledlatched and refreshes its timestamp, instead of clearing counters/state as a real user turn.selfInjectFreshaccepts up toOWN_PROMPT_TIME_MSskew betweenlastInjectAtandlastGenuineUserAt(lastInjectAt + OWN_PROMPT_TIME_MS >= w.lastGenuineUserAt), so clock skew does not start a false new episode.workRetriesacrossexecution.startedfallback. The fallback still resets progress flags such aslifetimeContinues/emptyIdleNudged, but it leavesworkRetries(retry #K) unchanged. Only a confirmed real user message resetsworkRetries. This stops mid-episode drops whenownRungis misclassified.recoverTimer, clearpendingRecoveryArmed, and bumprecoverGeneration. A pre-armed recovery cannot fire after the stop.Summary (flow)
Evidence
Before: Session history and
audit-countersshowed counter breaks inside one stall episode:retry #1 -> #1(timestamp/skew path), mid-episode drops such asretry #4 -> #2andretry #2 -> #1with no real user message between them, and first-visible nudges reading ahead when a declined or suppressed nudge still moved the count. Sources:permanent_files/findings/auto_resume_counters_fix_findings.md,permanent_files/findings/auto_resume_counters_findings.md,memory/gotchas-autoresume.md.After: On branch
fix/v2-stall-counter-delivery-gates(from upstreammaster2cea813, commit8fd3404),bun run buildsucceeded.bun test src/v2/index.attempt-reset.test.ts— 17 pass. Related suites pass:index.own-prompt-reload,index.user-rearm,index.duplicate-prod,index.ladder-delivery-gate(11 pass across 4 files).Before: A queued or delayed recovery could fire after an explicit user stop and re-arm a cancelled session.
After: The stop path clears
recoverTimer, clearspendingRecoveryArmed, and bumpsrecoverGeneration, so a pre-armed recovery does not fire after stop.Merge Danger
Door: two-way
The change is confined to v2 stall/counter/recovery state transitions. It can be reverted by restoring the prior v2 logic and redeploying the plugin bundle.
Blast Radius: stalled-session recovery UX
Potential effects: visible
attempt N/M (retry #K)progression in stalled sessions, whether a nudge is delivered after a user stop, and how synthetic interruption-recovery messages interact with cancellation state. No storage schema change. Historical session logs remain unchanged; the fix applies to future nudges.