Skip to content

fix(v2): stabilize stall counter and retry ladder - #51

Merged
Mte90 merged 2 commits into
Mte90:masterfrom
famewolf:fix/v2-stall-counter-delivery-gates
Nov 10, 2026
Merged

Mte90 merged 2 commits into
Mte90:masterfrom
famewolf:fix/v2-stall-counter-delivery-gates

Conversation

@famewolf

@famewolf famewolf commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

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

  • Commit visible counters on delivery, not detection. The ladder rung and retry/work count move only when a nudge is delivered. A declined, busy/live, duplicate-suppressed, or skewed nudge no longer burns a rung or advances the visible retry count.
  • Treat synthetic interruption recovery as non-user input. isSyntheticInterrupt() identifies that message; noteInboundUserMessage keeps userCancelled latched and refreshes its timestamp, instead of clearing counters/state as a real user turn.
  • Tolerate inject/user clock skew. selfInjectFresh accepts up to OWN_PROMPT_TIME_MS skew between lastInjectAt and lastGenuineUserAt (lastInjectAt + OWN_PROMPT_TIME_MS >= w.lastGenuineUserAt), so clock skew does not start a false new episode.
  • Keep workRetries across execution.started fallback. The fallback still resets progress flags such as lifetimeContinues/emptyIdleNudged, but it leaves workRetries (retry #K) unchanged. Only a confirmed real user message resets workRetries. This stops mid-episode drops when ownRung is misclassified.
  • Cancel queued recovery on user stop. On user stop, clear recoverTimer, clear pendingRecoveryArmed, and bump recoverGeneration. A pre-armed recovery cannot fire after the stop.

Summary (flow)

stall episode (v2 auto-resume)
  detect stall
  ├─ before: record rung / seed retry at DETECTION
  │    ├─ nudge declined (busy/live, duplicate-suppressed, skew path)
  │    │    └─ rung or retry consumed anyway -> phantom 2/3, first visible retry #2
  │    └─ execution.started fallback misclassifies own rung
  │         └─ workRetries reset -> mid-episode drops (#4 -> #2, #2 -> #1)
  └─ after: commit visible counters only when the nudge is DELIVERED
       ├─ selfInjectFresh tolerates OWN_PROMPT_TIME_MS clock skew
       ├─ synthetic interruption recovery keeps userCancelled latched (timestamp refresh)
       ├─ execution.started fallback resets progress flags, NOT workRetries
       └─ user stop clears recoverTimer / pendingRecoveryArmed / bumps recoverGeneration
            -> pre-armed recovery cannot fire after stop
 detect -> inject
-  recordContinue()/resumeAttempts++ at detection
-  seed/count retry even when nudge not shown
-  execution.started fallback: workRetries = 0
-  user stop leaves queued recovery armed
+  rung/retry committed on delivered nudge only
+  isSyntheticInterrupt() keeps cancellation latched on recovery message
+  selfInjectFresh: lastInjectAt + OWN_PROMPT_TIME_MS >= lastGenuineUserAt
+  execution.started fallback: reset lifetimeContinues/emptyIdleNudged, keep workRetries
+  user stop: clear recoverTimer, clear pendingRecoveryArmed, recoverGeneration++

Evidence

  • Before: Session history and audit-counters showed counter breaks inside one stall episode: retry #1 -> #1 (timestamp/skew path), mid-episode drops such as retry #4 -> #2 and retry #2 -> #1 with 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 upstream master 2cea813, commit 8fd3404), bun run build succeeded. 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, clears pendingRecoveryArmed, and bumps recoverGeneration, 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.

- 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).
@Mte90

Mte90 commented Nov 9, 2026

Copy link
Copy Markdown
Owner

I don't see any tests

@famewolf

famewolf commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

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.

@famewolf
famewolf marked this pull request as ready for review November 9, 2026 22:08
@Mte90
Mte90 merged commit 658bba5 into Mte90:master Nov 10, 2026
1 check passed
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