Skip to content

Commit 672ee28

Browse files
authored
fix(opencode): avoid org lookup during config startup (#22670)
1 parent e16589f commit 672ee28

2 files changed

Lines changed: 11 additions & 35 deletions

File tree

AGENTS.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,10 @@
1111
- Keep things in one function unless composable or reusable
1212
- Avoid `try`/`catch` where possible
1313
- Avoid using the `any` type
14-
- Prefer single word variable names where possible
1514
- Use Bun APIs when possible, like `Bun.file()`
1615
- Rely on type inference when possible; avoid explicit type annotations or interfaces unless necessary for exports or clarity
1716
- Prefer functional array methods (flatMap, filter, map) over for loops; use type guards on filter to maintain type inference downstream
1817

19-
### Naming
20-
21-
Prefer single word names for variables and functions. Only use multiple words if necessary.
22-
23-
### Naming Enforcement (Read This)
24-
25-
THIS RULE IS MANDATORY FOR AGENT WRITTEN CODE.
26-
27-
- Use single word names by default for new locals, params, and helper functions.
28-
- Multi-word names are allowed only when a single word would be unclear or ambiguous.
29-
- Do not introduce new camelCase compounds when a short single-word alternative is clear.
30-
- Before finishing edits, review touched lines and shorten newly introduced identifiers where possible.
31-
- Good short names to prefer: `pid`, `cfg`, `err`, `opts`, `dir`, `root`, `child`, `state`, `timeout`.
32-
- Examples to avoid unless truly required: `inputPID`, `existingClient`, `connectTimeout`, `workerPath`.
33-
34-
```ts
35-
// Good
36-
const foo = 1
37-
function journal(dir: string) {}
38-
39-
// Bad
40-
const fooBar = 1
41-
function prepareJournal(dir: string) {}
42-
```
43-
4418
Reduce total variable count by inlining when a value is only used once.
4519

4620
```ts

packages/opencode/src/config/config.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ export namespace Config {
12771277
return yield* cachedGlobal
12781278
})
12791279

1280-
const install = Effect.fnUntraced(function* (dir: string) {
1280+
const install = Effect.fn("Config.install")(function* (dir: string) {
12811281
const pkg = path.join(dir, "package.json")
12821282
const gitignore = path.join(dir, ".gitignore")
12831283
const plugin = path.join(dir, "node_modules", "@opencode-ai", "plugin", "package.json")
@@ -1345,7 +1345,7 @@ export namespace Config {
13451345
)
13461346
})
13471347

1348-
const loadInstanceState = Effect.fnUntraced(function* (ctx: InstanceContext) {
1348+
const loadInstanceState = Effect.fn("Config.loadInstanceState")(function* (ctx: InstanceContext) {
13491349
const auth = yield* authSvc.all().pipe(Effect.orDie)
13501350

13511351
let result: Info = {}
@@ -1468,24 +1468,25 @@ export namespace Config {
14681468
log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT")
14691469
}
14701470

1471-
const activeOrg = Option.getOrUndefined(
1472-
yield* accountSvc.activeOrg().pipe(Effect.catch(() => Effect.succeed(Option.none()))),
1471+
const activeAccount = Option.getOrUndefined(
1472+
yield* accountSvc.active().pipe(Effect.catch(() => Effect.succeed(Option.none()))),
14731473
)
1474-
if (activeOrg) {
1474+
if (activeAccount?.active_org_id) {
1475+
const accountID = activeAccount.id
1476+
const orgID = activeAccount.active_org_id
1477+
const url = activeAccount.url
14751478
yield* Effect.gen(function* () {
14761479
const [configOpt, tokenOpt] = yield* Effect.all(
1477-
[accountSvc.config(activeOrg.account.id, activeOrg.org.id), accountSvc.token(activeOrg.account.id)],
1480+
[accountSvc.config(accountID, orgID), accountSvc.token(accountID)],
14781481
{ concurrency: 2 },
14791482
)
14801483
if (Option.isSome(tokenOpt)) {
14811484
process.env["OPENCODE_CONSOLE_TOKEN"] = tokenOpt.value
14821485
yield* env.set("OPENCODE_CONSOLE_TOKEN", tokenOpt.value)
14831486
}
14841487

1485-
activeOrgName = activeOrg.org.name
1486-
14871488
if (Option.isSome(configOpt)) {
1488-
const source = `${activeOrg.account.url}/api/config`
1489+
const source = `${url}/api/config`
14891490
const next = yield* loadConfig(JSON.stringify(configOpt.value), {
14901491
dir: path.dirname(source),
14911492
source,
@@ -1496,6 +1497,7 @@ export namespace Config {
14961497
yield* merge(source, next, "global")
14971498
}
14981499
}).pipe(
1500+
Effect.withSpan("Config.loadActiveOrgConfig"),
14991501
Effect.catch((err) => {
15001502
log.debug("failed to fetch remote account config", {
15011503
error: err instanceof Error ? err.message : String(err),

0 commit comments

Comments
 (0)