Skip to content

Commit 3ba597f

Browse files
authored
fix: link new Console workspaces to their Go page and show monthly Go resets (#61244)
1 parent 1bf08ae commit 3ba597f

6 files changed

Lines changed: 42 additions & 11 deletions

File tree

‎packages/app/src/session/usage-exceeded-dialogs.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, test } from "bun:test"
22
import { Schema } from "effect"
3-
import { GoUpsellState } from "./usage-exceeded-dialogs"
3+
import { formatLimitReset, GoUpsellState } from "./usage-exceeded-dialogs"
44
import { Persistence } from "@/runtime/persistence/schema"
55

66
const decode = Schema.decodeUnknownSync(
@@ -31,3 +31,11 @@ describe("usage exceeded preferences", () => {
3131
})
3232
})
3333
})
34+
35+
describe("formatLimitReset", () => {
36+
test("shows a monthly Go limit's reset weeks out", () => {
37+
const created = Date.now()
38+
expect(formatLimitReset("en-US", created, 25 * 86_400_000)).toBeDefined()
39+
expect(formatLimitReset("en-US", created, 60 * 86_400_000)).toBeUndefined()
40+
})
41+
})

‎packages/app/src/session/usage-exceeded-dialogs.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const GO_UPSELL_WINDOW = 86_400_000 // 24 hrs
1818

1919
const GO_URL = "https://opencode.ai/go"
2020

21-
const MAX_RETRY_AFTER_MS = 7 * 86_400_000
21+
const MAX_RETRY_AFTER_MS = 45 * 86_400_000
2222

2323
const CHATGPT_USAGE_LIMIT_WINDOW = 86_400_000 // 24 hrs
2424

‎packages/session-ui/src/timeline/projection.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ export namespace Timeline {
657657
}
658658
}
659659

660-
const MAX_RETRY_AFTER_MS = 7 * 86_400_000
660+
const MAX_RETRY_AFTER_MS = 45 * 86_400_000
661661

662662
function usageLimit(
663663
message: Pick<SessionMessageAssistant, "error"> & { time: { created: number; completed?: number } },

‎packages/session-ui/src/timeline/rows-current.test.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ describe("current session timeline rows", () => {
11811181
{ name: "opted in", grouped: true, groups: [["context", "read", "grep", "agent_1", "agent_2", "glob", "read_2"]] },
11821182
])("gives each subagent its own row unless subagent grouping is enabled ($name)", (input) => {
11831183
const compact = timelinePresets.find((preset) => preset.id === "compact")!.value
1184+
11841185
const rows = Timeline.constructSessionMessageRows(
11851186
storyDocument([
11861187
storyTool("read", "read", "completed", { path: "src/a.ts" }),
@@ -1638,7 +1639,10 @@ describe("current session timeline rows", () => {
16381639

16391640
const go = [
16401641
user,
1641-
{ ...assistant, error: { type: "provider.go-limit", message: "Go usage limit reached.", retryAfterMs: 120_000 } },
1642+
{
1643+
...assistant,
1644+
error: { type: "provider.go-limit", message: "Go usage limit reached.", retryAfterMs: 25 * 86_400_000 },
1645+
},
16421646
] satisfies SessionMessageInfo[]
16431647

16441648
expect(Timeline.constructSessionMessageRows(step, true, { type: "idle" }).rows.at(-1)).toEqual(
@@ -1671,7 +1675,7 @@ describe("current session timeline rows", () => {
16711675
userMessageID: "msg_user",
16721676
text: "Go usage limit reached.",
16731677
kind: "go-limit",
1674-
resetAt: 121_000,
1678+
resetAt: 1_000 + 25 * 86_400_000,
16751679
}),
16761680
)
16771681
expect(Timeline.constructSessionMessageRows(quota, true, { type: "idle" }).rows.at(-1)).toEqual(
@@ -1681,8 +1685,11 @@ describe("current session timeline rows", () => {
16811685

16821686
test("marks a Console budget refusal with the reset its envelope names", () => {
16831687
const user = { id: "msg_user", type: "user", text: "prompt", time: { created: 1 } } satisfies SessionMessageInfo
1684-
const refused = (type: string, body?: string) =>
1685-
Timeline.constructSessionMessageRows(
1688+
1689+
const refused = (type: string, body?: string) => {
1690+
const error = { type, message: "Budget reached.", status: 429 }
1691+
1692+
return Timeline.constructSessionMessageRows(
16861693
[
16871694
user,
16881695
{
@@ -1692,13 +1699,14 @@ describe("current session timeline rows", () => {
16921699
model: { id: "claude-opus-5", providerID: "opencode" },
16931700
content: [],
16941701
finish: "error",
1695-
error: { type, message: "Budget reached.", status: 429, ...(body ? { response: { body } } : {}) },
1702+
error: body ? { ...error, response: { body } } : error,
16961703
time: { created: 2, completed: 3 },
16971704
},
16981705
],
16991706
true,
17001707
{ type: "idle" },
17011708
).rows.at(-1)
1709+
}
17021710

17031711
// Anthropic and OpenAI clients get Console's own envelope; Google clients get the reset in ErrorInfo's metadata.
17041712
expect(

‎packages/tui/src/util/usage-limits.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ export function refusalReset(error: { readonly response?: { readonly body: strin
9797
return Number.isNaN(at) ? undefined : at
9898
}
9999

100-
/** When a refused request may retry, from its `retry-after` counted from `base`; nothing past a week, as a bad header. */
100+
/** When a refused request may retry, from its `retry-after` counted from `base`; nothing past 45 days, as a bad header. */
101101
export function retryReset(error: { readonly retryAfterMs?: number } | undefined, base: number) {
102102
const delay = error?.retryAfterMs
103-
if (delay === undefined || !Number.isFinite(delay) || delay < 0 || delay > 7 * 86_400_000) return undefined
103+
if (delay === undefined || !Number.isFinite(delay) || delay < 0 || delay > 45 * 86_400_000) return undefined
104104
const at = base + delay
105105
return Number.isNaN(new Date(at).getTime()) ? undefined : at
106106
}
@@ -112,7 +112,7 @@ export function goLimitName(error: { readonly response?: { readonly body: string
112112

113113
/** The OpenCode Console Go page for the workspace a Go usage limit names, where it can turn on Extra Usage. */
114114
export function goLimitLink(error: { readonly response?: { readonly body: string } } | undefined) {
115-
const workspace = /"workspace"\s*:\s*"(wrk_\w+)"/.exec(error?.response?.body ?? "")?.[1]
115+
const workspace = /"workspace"\s*:\s*"((?:org|wrk)_[\w-]+)"/.exec(error?.response?.body ?? "")?.[1]
116116
return workspace ? `https://opencode.ai/console/${workspace}/go` : "https://opencode.ai/console"
117117
}
118118

‎packages/tui/test/util/usage-limits.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import type { UsageLimitsBudget, UsageLimitsInfo } from "@opencode/client"
33
import {
44
formatDollars,
55
formatReset,
6+
goLimitLink,
67
limitScope,
78
modelUsage,
89
refusalReset,
10+
retryReset,
911
usageLevel,
1012
} from "../../src/util/usage-limits"
1113

@@ -136,4 +138,17 @@ describe("util.usage-limits", () => {
136138
).toBe(RESET)
137139
expect(refusalReset({ response: { body: "{}" } })).toBeUndefined()
138140
})
141+
142+
test("a Go limit links to its workspace's Go page for new and migrated workspaces", () => {
143+
const body = (workspace: string) => ({ response: { body: JSON.stringify({ metadata: { workspace } }) } })
144+
expect(goLimitLink(body("org_01JXYZ7Q2M"))).toBe("https://opencode.ai/console/org_01JXYZ7Q2M/go")
145+
expect(goLimitLink(body("wrk_legacy"))).toBe("https://opencode.ai/console/wrk_legacy/go")
146+
expect(goLimitLink(body("acct_other"))).toBe("https://opencode.ai/console")
147+
expect(goLimitLink({ response: { body: "{}" } })).toBe("https://opencode.ai/console")
148+
})
149+
150+
test("a monthly Go limit keeps its reset weeks out", () => {
151+
expect(retryReset({ retryAfterMs: 25 * 86_400_000 }, RESET)).toBe(RESET + 25 * 86_400_000)
152+
expect(retryReset({ retryAfterMs: 60 * 86_400_000 }, RESET)).toBeUndefined()
153+
})
139154
})

0 commit comments

Comments
 (0)