Skip to content

Commit da7479e

Browse files
committed
fix(tui): handle --continue in directories with no prior sessions
- Extract CONTINUE_PLACEHOLDER_ID constant in context/route.tsx so the sentinel value is defined once and shared by both consumers - Guard session route fetch to skip eager session.get() while the route holds the placeholder, preventing invalid GET /session/dummy requests - Add no-match fallback in the continue effect: wait for sync complete before concluding no sessions exist, then navigate to home - Navigate home on fork failure instead of leaving user on placeholder - Flatten else branches to use early returns per style guide Closes anomalyco#23437
1 parent 33b2795 commit da7479e

3 files changed

Lines changed: 31 additions & 15 deletions

File tree

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Clipboard from "@tui/util/clipboard"
33
import * as Selection from "@tui/util/selection"
44
import * as Terminal from "@tui/util/terminal"
55
import { createCliRenderer, MouseButton, type CliRendererConfig } from "@opentui/core"
6-
import { RouteProvider, useRoute } from "@tui/context/route"
6+
import { CONTINUE_PLACEHOLDER_ID, RouteProvider, useRoute } from "@tui/context/route"
77
import {
88
Switch,
99
Match,
@@ -153,7 +153,7 @@ export function tui(input: {
153153
input.args.continue
154154
? {
155155
type: "session",
156-
sessionID: "dummy",
156+
sessionID: CONTINUE_PLACEHOLDER_ID,
157157
}
158158
: undefined
159159
}
@@ -358,20 +358,26 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
358358
const match = sync.data.session
359359
.toSorted((a, b) => b.time.updated - a.time.updated)
360360
.find((x) => x.parentID === undefined)?.id
361-
if (match) {
361+
if (!match) {
362+
// Only give up once the full session list has loaded
363+
if (sync.status !== "complete") return
362364
continued = true
363-
if (args.fork) {
364-
void sdk.client.session.fork({ sessionID: match }).then((result) => {
365-
if (result.data?.id) {
366-
route.navigate({ type: "session", sessionID: result.data.id })
367-
} else {
368-
toast.show({ message: "Failed to fork session", variant: "error" })
369-
}
370-
})
371-
} else {
372-
route.navigate({ type: "session", sessionID: match })
373-
}
365+
route.navigate({ type: "home" })
366+
return
367+
}
368+
continued = true
369+
if (args.fork) {
370+
void sdk.client.session.fork({ sessionID: match }).then((result) => {
371+
if (result.data?.id) {
372+
route.navigate({ type: "session", sessionID: result.data.id })
373+
return
374+
}
375+
toast.show({ message: "Failed to fork session", variant: "error" })
376+
route.navigate({ type: "home" })
377+
})
378+
return
374379
}
380+
route.navigate({ type: "session", sessionID: match })
375381
})
376382

377383
// Handle --session with --fork: wait for sync to be fully complete before forking

‎packages/opencode/src/cli/cmd/tui/context/route.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ export type PluginRoute = {
2121

2222
export type Route = HomeRoute | SessionRoute | PluginRoute
2323

24+
/**
25+
* Placeholder session ID used as the initial route when `--continue` is passed.
26+
* Prevents a visual flash to the home screen before the real session is resolved.
27+
* Must never be fetched from the server — consumers should guard against it.
28+
*/
29+
export const CONTINUE_PLACEHOLDER_ID = "dummy"
30+
2431
export const { use: useRoute, provider: RouteProvider } = createSimpleContext({
2532
name: "Route",
2633
init: (props: { initialRoute?: Route }) => {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from "solid-js"
1515
import { Dynamic } from "solid-js/web"
1616
import path from "path"
17-
import { useRoute, useRouteData } from "@tui/context/route"
17+
import { CONTINUE_PLACEHOLDER_ID, useRoute, useRouteData } from "@tui/context/route"
1818
import { useProject } from "@tui/context/project"
1919
import { useSync } from "@tui/context/sync"
2020
import { useEvent } from "@tui/context/event"
@@ -181,6 +181,9 @@ export function Session() {
181181
const sdk = useSDK()
182182

183183
createEffect(async () => {
184+
// Skip fetching while the route still holds the placeholder used by --continue.
185+
// The continue effect in App() will replace this route with a real session or home.
186+
if (route.sessionID === CONTINUE_PLACEHOLDER_ID) return
184187
const previousWorkspace = project.workspace.current()
185188
const result = await sdk.client.session.get({ sessionID: route.sessionID }, { throwOnError: true })
186189
if (!result.data) {

0 commit comments

Comments
 (0)