Skip to content

fix(heartbeat): rotate to fresh session on autocompact thrash (#29)#202

Open
om952 wants to merge 2 commits into
OpenScanAI:masterfrom
om952:fix/issue-29-autocompact-thrash
Open

fix(heartbeat): rotate to fresh session on autocompact thrash (#29)#202
om952 wants to merge 2 commits into
OpenScanAI:masterfrom
om952:fix/issue-29-autocompact-thrash

Conversation

@om952

@om952 om952 commented Jul 2, 2026

Copy link
Copy Markdown

Ports upstream PR paperclipai#6736 behavior: when a heartbeat run fails because the adapter session is autocompact-thrashing, force a session rotation instead of resuming the poisoned session.

Changes:

  • Keep the autocompact-thrash guard in evaluateSessionCompaction (detects resultStopReason === "autocompact_thrash" and legacy error strings).
  • Move evaluateSessionCompactionFromRuns to module top-level as a clean export.
  • Remove unrelated maxConsecutiveAdapterFailed / countConsecutiveAdapterFailedRuns session-compaction code.
  • Add regression coverage in heartbeat-process-recovery.test.ts that seeds a known task session, simulates the thrash failure, and proves the recovery run receives a fresh session and no second wasted compaction attempt is recorded.

Verification:

  • npx vitest run server/src/__tests__/heartbeat-process-recovery.test.ts — 46/46 pass
  • npx vitest run server/src/__tests__/heartbeat-workspace-session.test.ts — 38/38 pass
  • npx vitest run server/src/services/heartbeat-stop-metadata.test.ts — 8/8 pass
  • pnpm build — passes
  • pnpm -r typecheck — clean except pre-existing unrelated plugin-host-services.ts error

Closes #29

om952 added 2 commits June 26, 2026 17:39
…sh stop reason + session rotation guard

Tracks upstream paperclipai#6736.

Changes:
- Add `autocompact_thrash` as a first-class HeartbeatRunStopReason
- Export `isAutocompactThrashError()` to detect thrash error strings
- Update `inferHeartbeatRunStopReason()` to classify thrash before adapter_failed catch-all
- Restructure `evaluateSessionCompaction()` to always fetch >=1 prior run, then force
  session rotation when the most-recent run was a thrash failure (covers both new
  typed stopReason and legacy error string detection)
- Fix `finalizeAgentStatus()` to accept subprocess exit code; transition agent
  from error -> idle when subprocess exits 0 even if run was pre-terminated as failed
- Filter mentioned skill IDs through `isUuidLike()` to avoid slug-mention false positives
- Unit tests for thrash detection classifier and process-recovery exit-code-0 override

Closes OpenScanAI#29
…anAI#29)

Ports upstream PR paperclipai#6736 behavior: when a heartbeat run fails because the
adapter session is autocompact-thrashing, force a session rotation instead of
resuming the poisoned session. Detects both the typed `resultStopReason` and
legacy error-string markers.

- Move `evaluateSessionCompactionFromRuns` to module top-level so it can be
  exported cleanly and unit-tested.
- Remove unrelated `maxConsecutiveAdapterFailed` session-compaction branch.
- Add regression coverage in `heartbeat-process-recovery.test.ts` that seeds a
  known task session, simulates the thrash failure, and proves the recovery run
  receives a fresh session and does not retry the poisoned one.

Closes OpenScanAI#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.

feat(heartbeat): port upstream PR #6736 — autocompact_thrash stop reason + session rotation guard

1 participant