DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(turnrewind): release the undo reservation when target selection throws
yingtianlancc177acce1e2
diff --git a/packages/dsh-tauri-turnrewind-ts/src/host/service/undo.ts b/packages/dsh-tauri-turnrewind-ts/src/host/service/undo.tsindex d56c884a..159437d7 100644--- a/packages/dsh-tauri-turnrewind-ts/src/host/service/undo.ts+++ b/packages/dsh-tauri-turnrewind-ts/src/host/service/undo.ts@@ -652,47 +652,58 @@ export async function applyUndo(}runtime.undoing = false}- if (parsed.confirm) {- const claim = claimPendingPlan(runtime.db, parsed.turnId!, invocation.agent.session.id)- if (!claim.ok)- return { kind: 'error', text: claim.error }- pendingPlanClaimed = true- // Reserve the workspace before the first await so another confirm route- // cannot start a concurrent restore during snapshot validation.- runtime.undoing = true- planRow = claim.row- const pendingTurnId = claim.row.turn_id- target = getTurn(runtime.db, pendingTurnId)- if (!target || !await turnRefsExist(runtime.store, target)) {- abortPendingPlanClaim()- return { kind: 'error', text: 'The pending plan\'s snapshot data no longer exists. Run /undo again to preview a fresh plan.' }+ // Target selection runs BEFORE the execution try/finally below, so a thrown+ // probe (SQLite IOERR/BUSY while reading the ledger) must release the+ // reservation and any claimed plan explicitly. A stranded runtime.undoing+ // would silently refuse every later undo AND make new turns skip their+ // baseline (TURNREWIND_WORKSPACE_BUSY) until the host restarts.+ try {+ if (parsed.confirm) {+ const claim = claimPendingPlan(runtime.db, parsed.turnId!, invocation.agent.session.id)+ if (!claim.ok)+ return { kind: 'error', text: claim.error }+ pendingPlanClaimed = true+ // Reserve the workspace before the first await so another confirm route+ // cannot start a concurrent restore during snapshot validation.+ runtime.undoing = true+ planRow = claim.row+ const pendingTurnId = claim.row.turn_id+ target = getTurn(runtime.db, pendingTurnId)+ if (!target || !await turnRefsExist(runtime.store, target)) {+ abortPendingPlanClaim()+ return { kind: 'error', text: 'The pending plan\'s snapshot data no longer exists. Run /undo again to preview a fresh plan.' }+ }}- }- else if (parsed.turnId) {- // Reserve before the first await so a concurrent direct-execute cannot- // build a plan against disk state this invocation is about to change.- runtime.undoing = true- target = getTurn(runtime.db, parsed.turnId)- if (target && !await turnRefsExist(runtime.store, target)) {- runtime.undoing = false- return {- kind: 'error',- text: `The snapshot data for turn ${parsed.turnId} no longer exists (the snapshot repository was previously wiped); its changes can no longer be undone.`,+ else if (parsed.turnId) {+ // Reserve before the first await so a concurrent direct-execute cannot+ // build a plan against disk state this invocation is about to change.+ runtime.undoing = true+ target = getTurn(runtime.db, parsed.turnId)+ if (target && !await turnRefsExist(runtime.store, target)) {+ runtime.undoing = false+ return {+ kind: 'error',+ text: `The snapshot data for turn ${parsed.turnId} no longer exists (the snapshot repository was previously wiped); its changes can no longer be undone.`,+ }}}- }- else {- runtime.undoing = true- // Walk newest-first and skip turns whose snapshot refs died with a wiped- // snapshot repository, marking them so later /undo runs never re-check.- for (const candidate of listReversibleTurns(runtime.db, invocation.agent.session.id, workspaceKey)) {- if (await turnRefsExist(runtime.store, candidate)) {- target = candidate- break+ else {+ runtime.undoing = true+ // Walk newest-first and skip turns whose snapshot refs died with a wiped+ // snapshot repository, marking them so later /undo runs never re-check.+ for (const candidate of listReversibleTurns(runtime.db, invocation.agent.session.id, workspaceKey)) {+ if (await turnRefsExist(runtime.store, candidate)) {+ target = candidate+ break+ }+ markTurnSnapshotMissing(runtime.db, candidate.turn_id)}- markTurnSnapshotMissing(runtime.db, candidate.turn_id)}}+ catch (error) {+ abortPendingPlanClaim()+ throw error+ }if (!target) {runtime.undoing = falseconst latest = getLatestTurnSummary(runtime.db, invocation.agent.session.id, workspaceKey)diff --git a/packages/dsh-tauri-turnrewind-ts/test/lifecycle.test.js b/packages/dsh-tauri-turnrewind-ts/test/lifecycle.test.jsindex b532c638..6376706c 100644--- a/packages/dsh-tauri-turnrewind-ts/test/lifecycle.test.js+++ b/packages/dsh-tauri-turnrewind-ts/test/lifecycle.test.js@@ -191,6 +191,22 @@ it('waits for a claimed turn baseline before allowing the next step', async () =assert.equal(continued, true)})+it('releases the workspace reservation when target selection throws', async () => {+ const { root, db, runtime, active, invocation } = await setupTurn()+ // Closing the ledger makes target selection throw (a stand-in for a real+ // SQLITE_BUSY/IOERR). The reservation is taken before that first probe, so a+ // throw must release it: a stranded runtime.undoing silently refuses every+ // later undo and makes new turns skip their baseline until the host restarts.+ db.close()+ try {+ await assert.rejects(() => applyUndo(runtime, active, invocation('')))+ assert.equal(runtime.undoing, false)+ }+ finally {+ await rm(root, { recursive: true, force: true })+ }+})+it('unblocks an aborted pre-step without cancelling baseline bookkeeping', async () => {let releaseconst baseline = new Promise((resolvePromise) => {