Skip to content

Commit 46aefe3

Browse files
authored
fix(app): hide zero session cost for OpenCode Go (#63744)
1 parent a660c18 commit 46aefe3

3 files changed

Lines changed: 58 additions & 12 deletions

File tree

‎packages/app/e2e/regression/review.spec.ts‎

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ test("context closes the side region only when its button opened it", async ({ p
459459
await expect(panel.locator("#session-side-panel-review-tab")).toHaveAttribute("aria-selected", "true")
460460
})
461461

462-
test("context hides free-model cost but keeps paid-model zero cost", async ({ page }) => {
462+
test("context hides zero cost for Go and free models but keeps paid-model cost", async ({ page }) => {
463463
const cases = [
464464
{ id: "ses_context_free", title: "Free model", model: "free", cost: 0, usage: false, text: "0" },
465465
{ id: "ses_context_paid", title: "Paid model", model: "paid", cost: 0, usage: false, text: "0·$0.00" },
@@ -468,24 +468,48 @@ test("context hides free-model cost but keeps paid-model zero cost", async ({ pa
468468
{ id: "ses_context_mixed", title: "Previously paid", model: "free", cost: 1.25, usage: true, text: "2k·$1.25" },
469469
{ id: "ses_context_unknown", title: "Unknown pricing", model: "missing", cost: 0, usage: false, text: "0·$0.00" },
470470
{ id: "ses_context_output", title: "Output pricing", model: "output", cost: 0, usage: false, text: "0·$0.00" },
471+
{
472+
id: "ses_context_go",
473+
title: "Covered by Go",
474+
providerID: "opencode-go",
475+
model: "paid",
476+
cost: 0,
477+
usage: true,
478+
text: "2k",
479+
},
480+
{
481+
id: "ses_context_go_spend",
482+
title: "Go with charges",
483+
providerID: "opencode-go",
484+
model: "paid",
485+
cost: 0.38,
486+
usage: true,
487+
text: "2k·$0.38",
488+
},
471489
// The root's model is free, but its subagent spent on a paid model: the family total shows.
472490
{ id: "ses_context_family", title: "Paid subagent", model: "free", cost: 0, usage: true, text: "2k·$1.25" },
473491
// A completed compaction resets the context until the next reply reports usage, as in the TUI.
474492
{ id: "ses_context_compacted", title: "Compacted", model: "paid", cost: 1.25, usage: true, text: "0·$1.25" },
475493
]
476494

495+
const catalog = provider(
496+
{ id: "free", name: "Free", cost: { input: 0, output: 0 } },
497+
{ id: "paid", name: "Paid", cost: { input: 1, output: 3 } },
498+
{ id: "output", name: "Output", cost: { input: 0, output: 1 } },
499+
)
500+
477501
await openSession(page, {
478502
name: "ContextPricing",
479-
provider: provider(
480-
{ id: "free", name: "Free", cost: { input: 0, output: 0 } },
481-
{ id: "paid", name: "Paid", cost: { input: 1, output: 3 } },
482-
{ id: "output", name: "Output", cost: { input: 0, output: 1 } },
483-
),
503+
provider: {
504+
...catalog,
505+
all: [...catalog.all, { ...catalog.all[0], id: "opencode-go", name: "OpenCode Go" }],
506+
connected: [...catalog.connected, "opencode-go"],
507+
},
484508
sessions: [
485509
...cases.map((item) => ({
486510
id: item.id,
487511
title: item.title,
488-
model: { id: item.model, providerID: "opencode" },
512+
model: { id: item.model, providerID: item.providerID ?? "opencode" },
489513
cost: item.cost,
490514
})),
491515
{
@@ -504,7 +528,7 @@ test("context hides free-model cost but keeps paid-model zero cost", async ({ pa
504528
id: `msg_${item.id}`,
505529
type: "assistant",
506530
agent: "build",
507-
model: { id: item.model, providerID: "opencode" },
531+
model: { id: item.model, providerID: item.providerID ?? "opencode" },
508532
tokens: { input: 1500, output: 500, reasoning: 0, cache: { read: 0, write: 0 } },
509533
content: [{ type: "text", text: "Done." }],
510534
time: { created: 1, completed: 2 },
@@ -533,6 +557,15 @@ test("context hides free-model cost but keeps paid-model zero cost", async ({ pa
533557
await page.locator("[data-titlebar-tab-slot]", { hasText: item.title }).click()
534558
await expectSessionTitle(page, item.title)
535559
await expect(button).toHaveText(item.text)
560+
561+
if (item.providerID === "opencode-go") {
562+
await button.click()
563+
const panel = page.locator('[data-slot="session-usage-content"]')
564+
565+
await expect(panel.getByText("OpenCode Go", { exact: true })).toBeVisible()
566+
await expect(panel.getByText("Total Cost", { exact: true })).toBeVisible({ visible: item.cost > 0 })
567+
await button.click()
568+
}
536569
}
537570
})
538571

‎packages/gui-plugins/src/context/indicator.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ export function SessionContextUsage(props: {
7575

7676
const cost = createMemo(() => usd().format(spent()))
7777

78-
// Spend anywhere in the family keeps the cost visible, even when this session's model is free.
7978
const showCost = createMemo(() => {
8079
if (spent() > 0) return true
8180
const ref = info()?.model ?? messages().findLast((item) => item.type === "assistant")?.model
81+
82+
if (ref?.providerID === "opencode-go") return false
8283
const model = ref ? catalogModel(props.session, ref)?.model : undefined
8384

8485
if (!model) return true

‎packages/gui-plugins/src/context/tab.tsx‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,18 @@ export default function SessionContextTab(props: { session: MountedSession }) {
143143

144144
const formatter = createMemo(() => createSessionContextFormatter(i18n.locale()))
145145

146-
// A root session's cost includes its subagent sessions, as in the TUI.
147-
const cost = createMemo(() => usd().format(props.session.id ? data().session.cost(props.session.id) : 0))
146+
const cost = createMemo(() => {
147+
if (!props.session.id) return
148+
const spent = data().session.cost(props.session.id)
149+
150+
if (spent === 0) {
151+
const ref = info()?.model ?? messages().findLast((item) => item.type === "assistant")?.model
152+
153+
if (ref?.providerID === "opencode-go") return
154+
}
155+
156+
return usd().format(spent)
157+
})
148158

149159
const counts = createMemo(() => {
150160
const all = messages()
@@ -396,7 +406,9 @@ export default function SessionContextTab(props: { session: MountedSession }) {
396406
>
397407
<div data-slot="session-usage-content" class="px-4 pt-4 pb-6 flex flex-col gap-6 md:px-6 md:pb-10 md:gap-10">
398408
<div class="grid grid-cols-1 @[32rem]:grid-cols-2 gap-4">
399-
<For each={stats}>{(stat) => <Stat label={ctx.t(stat.label)} value={stat.value()} />}</For>
409+
<For each={stats}>
410+
{(stat) => <Show when={stat.value()}>{(value) => <Stat label={ctx.t(stat.label)} value={value()} />}</Show>}
411+
</For>
400412
</div>
401413

402414
<Show when={systemPrompt()}>

0 commit comments

Comments
 (0)