Skip to content

Commit 34eb03f

Browse files
fix: prioritize session list loading when resuming with -c (anomalyco#5816)
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
1 parent 2f6d15a commit 34eb03f

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ function App() {
229229

230230
let continued = false
231231
createEffect(() => {
232-
if (continued || sync.status !== "complete" || !args.continue) return
232+
// When using -c, session list is loaded in blocking phase, so we can navigate at "partial"
233+
if (continued || sync.status === "loading" || !args.continue) return
233234
const match = sync.data.session
234235
.toSorted((a, b) => b.time.updated - a.time.updated)
235236
.find((x) => x.parentID === undefined)?.id

packages/opencode/src/cli/cmd/tui/context/sync.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Binary } from "@opencode-ai/util/binary"
2222
import { createSimpleContext } from "./helper"
2323
import type { Snapshot } from "@/snapshot"
2424
import { useExit } from "./exit"
25+
import { useArgs } from "./args"
2526
import { batch, onMount } from "solid-js"
2627
import { Log } from "@/util/log"
2728
import type { Path } from "@opencode-ai/sdk"
@@ -254,10 +255,18 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
254255
})
255256

256257
const exit = useExit()
258+
const args = useArgs()
257259

258260
async function bootstrap() {
259-
// blocking
260-
await Promise.all([
261+
const sessionListPromise = sdk.client.session.list().then((x) =>
262+
setStore(
263+
"session",
264+
(x.data ?? []).toSorted((a, b) => a.id.localeCompare(b.id)),
265+
),
266+
)
267+
268+
// blocking - include session.list when continuing a session
269+
const blockingRequests: Promise<unknown>[] = [
261270
sdk.client.config.providers({}, { throwOnError: true }).then((x) => {
262271
batch(() => {
263272
setStore("provider", x.data!.providers)
@@ -271,17 +280,15 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
271280
}),
272281
sdk.client.app.agents({}, { throwOnError: true }).then((x) => setStore("agent", x.data ?? [])),
273282
sdk.client.config.get({}, { throwOnError: true }).then((x) => setStore("config", x.data!)),
274-
])
283+
...(args.continue ? [sessionListPromise] : []),
284+
]
285+
286+
await Promise.all(blockingRequests)
275287
.then(() => {
276288
if (store.status !== "complete") setStore("status", "partial")
277289
// non-blocking
278290
Promise.all([
279-
sdk.client.session.list().then((x) =>
280-
setStore(
281-
"session",
282-
(x.data ?? []).toSorted((a, b) => a.id.localeCompare(b.id)),
283-
),
284-
),
291+
...(args.continue ? [] : [sessionListPromise]),
285292
sdk.client.command.list().then((x) => setStore("command", x.data ?? [])),
286293
sdk.client.lsp.status().then((x) => setStore("lsp", x.data!)),
287294
sdk.client.mcp.status().then((x) => setStore("mcp", x.data!)),

0 commit comments

Comments
 (0)