fix(ralph-loop): revalidate ownership and harden commit/session-creation failures
Three correctness fixes on top of the dispatch-before-commit invariant: - ralph-loop-event-handler.ts: after idleSettleMs, also require state ownership and non-verification-pending to match the event source before dispatching. Applied to both the session.idle and session.error retry paths. - verification-failure-handler.ts: if incrementIteration fails after a successful continuation injection, clear the loop state and emit a warning toast instead of returning success. - session-reset-strategy.ts: catch thrown session.create errors so they route through the typed session_creation_rejected path instead of surfacing as an unhandled rejection.
This commit is contained in:
@@ -278,6 +278,17 @@ export function createRalphLoopEventHandler(
|
||||
if (!stateAfterSettle || !stateAfterSettle.active) {
|
||||
return
|
||||
}
|
||||
if (stateAfterSettle.session_id !== undefined && stateAfterSettle.session_id !== sessionID) {
|
||||
log(`[${HOOK_NAME}] Skipped: state rebound during settle window`, {
|
||||
sessionID,
|
||||
currentOwner: stateAfterSettle.session_id,
|
||||
})
|
||||
return
|
||||
}
|
||||
if (stateAfterSettle.verification_pending) {
|
||||
log(`[${HOOK_NAME}] Skipped: state entered verification_pending during settle window`, { sessionID })
|
||||
return
|
||||
}
|
||||
|
||||
const nextIteration = stateAfterSettle.iteration + 1
|
||||
const previewState: RalphLoopState = { ...stateAfterSettle, iteration: nextIteration }
|
||||
@@ -401,6 +412,17 @@ export function createRalphLoopEventHandler(
|
||||
if (!stateAfterSettle || !stateAfterSettle.active) {
|
||||
return
|
||||
}
|
||||
if (stateAfterSettle.session_id !== undefined && stateAfterSettle.session_id !== sessionID) {
|
||||
log(`[${HOOK_NAME}] Skipped: state rebound during settle window`, {
|
||||
sessionID,
|
||||
currentOwner: stateAfterSettle.session_id,
|
||||
})
|
||||
return
|
||||
}
|
||||
if (stateAfterSettle.verification_pending) {
|
||||
log(`[${HOOK_NAME}] Skipped: state entered verification_pending during settle window`, { sessionID })
|
||||
return
|
||||
}
|
||||
|
||||
const nextIteration = stateAfterSettle.iteration + 1
|
||||
const previewState: RalphLoopState = { ...stateAfterSettle, iteration: nextIteration }
|
||||
|
||||
Reference in New Issue
Block a user