Skip to content

Commit c600ac6

Browse files
committed
fix: make /continue command work correctly
- Regenerate v2 SDK to include session.continue() method - Update TUI to call session.continue() instead of session.prompt() - Simplify server continue endpoint logic to avoid race conditions - Cancel existing session state before starting new loop to prevent double abort errors Closes sst#5150
1 parent b31cb9d commit c600ac6

File tree

5 files changed

+72
-255
lines changed

5 files changed

+72
-255
lines changed

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,17 +394,13 @@ export function Session() {
394394
keybind: "session_continue",
395395
category: "Session",
396396
onSelect: async (dialog) => {
397-
const status = sync.data.session_status[route.sessionID]
398-
if (status?.type !== "idle") await sdk.client.session.abort({ sessionID: route.sessionID }).catch(() => {})
399-
400-
const result = await sdk.client.session.prompt({
397+
const result = await sdk.client.session.continue({
401398
sessionID: route.sessionID,
402399
})
403400

404401
if (result.data) {
405402
toBottom()
406403
} else {
407-
// Show message that there's nothing to continue
408404
dialog.clear()
409405
}
410406
},

packages/opencode/src/server/server.ts

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,45 +1358,19 @@ export namespace Server {
13581358
async (c) => {
13591359
const sessionID = c.req.valid("param").sessionID
13601360

1361-
// Check if session has an unfinished assistant message
1361+
// Check if there's a user message to continue from
13621362
const msgs = await Session.messages({ sessionID })
1363-
let lastAssistant: MessageV2.Assistant | undefined
1364-
1365-
for (let i = msgs.length - 1; i >= 0; i--) {
1366-
const msg = msgs[i]
1367-
if (msg.info.role === "assistant") {
1368-
lastAssistant = msg.info as MessageV2.Assistant
1369-
break
1370-
}
1371-
}
1372-
1373-
// If no unfinished assistant message, return false
1374-
if (!lastAssistant || (lastAssistant.finish && !["tool-calls", "unknown"].includes(lastAssistant.finish))) {
1363+
const hasUserMessage = msgs.some((m) => m.info.role === "user")
1364+
if (!hasUserMessage) {
13751365
return c.json(false)
13761366
}
13771367

1378-
// Find the last user message to revert to
1379-
let lastUser: MessageV2.User | undefined
1380-
for (let i = msgs.length - 1; i >= 0; i--) {
1381-
const msg = msgs[i]
1382-
if (msg.info.role === "user") {
1383-
lastUser = msg.info as MessageV2.User
1384-
break
1385-
}
1386-
}
1387-
1388-
if (!lastUser) {
1389-
return c.json(false)
1390-
}
1368+
// Cancel any existing session state to ensure clean start
1369+
SessionPrompt.cancel(sessionID)
13911370

1392-
// Revert unfinished assistant message
1393-
await SessionRevert.revert({
1394-
sessionID,
1395-
messageID: lastUser.id,
1396-
})
1397-
1398-
// Start conversation loop to continue
1399-
await SessionPrompt.loop(sessionID)
1371+
// Start conversation loop - it will continue from where it left off
1372+
// The loop handles incomplete assistant messages automatically
1373+
SessionPrompt.loop(sessionID)
14001374

14011375
return c.json(true)
14021376
},

0 commit comments

Comments
 (0)