GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: bound startup-path network waits for offline hosts · PJ-Zetier/opencode@aede901

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • core
      • src
        • config/plugin
          • instruction.ts
          • skill.ts
        • integration.ts
        • plugin/provider
          • opencode.ts
        • skill
          • discovery.ts
      • test
        • config
          • skill.test.ts
        • instruction-discovery.test.ts
        • npm.test.ts
        • plugin
          • provider-opencode.test.ts
        • skill-discovery.test.ts
    • tui/src
      • app.tsx
    • util/src
      • npm.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/src/config/plugin/instruction.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/config/plugin/instruction.ts
+17-3Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,15 @@ export const Plugin = define({
141141
// A failed fetch keeps the last good copy or skips the URL, so an unreachable URL
142142
// never makes the whole instruction set unavailable.
143143
const reconfigure = Effect.fn("ConfigInstructionPlugin.reconfigure")(
144-
function* () {
144+
function* (options?: { readonly fetch?: boolean }) {
145145
const entries = yield* config.entries()
146146
const sources = Array.from(
147147
new Set(entries.flatMap((entry) => (entry.type === "document" ? (entry.info.instructions ?? []) : []))),
148148
)
149+
if (options?.fetch === false) {
150+
configured.sources = sources
151+
return
152+
}
149153
const fetched = yield* Effect.forEach(
150154
sources.filter(isUrl),
151155
(url) =>
@@ -167,7 +171,7 @@ export const Plugin = define({
167171
fetched.filter((file) => file !== undefined).map((file) => [file.path, file] as const),
168172
)
169173
},
170-
(effect) => lock.withPermit(effect),
174+
(effect, ..._args: [options?: { readonly fetch?: boolean }]) => lock.withPermit(effect),
171175
)
172176

173177
const isolate = <A, E, R>(source: string, effect: Effect.Effect<A, E, R>) =>
@@ -214,7 +218,9 @@ export const Plugin = define({
214218
Stream.runForEach(() => reconfigure().pipe(Effect.andThen(refresh()), Effect.andThen(discovery.reload()))),
215219
Effect.forkScoped({ startImmediately: true }),
216220
)
217-
yield* reconfigure()
221+
// Configured local sources are explicit requests that resolve without the network, so the
222+
// first refresh must include them before activation reports ready.
223+
yield* reconfigure({ fetch: false })
218224
yield* refresh()
219225
yield* discovery.transform((editor) => {
220226
if (loaded.current.type === "unavailable") {
@@ -223,6 +229,14 @@ export const Plugin = define({
223229
}
224230
for (const file of loaded.current.files) editor.add(file)
225231
})
232+
// Configured sources may name remote URLs, whose fetch runs the way a config update does:
233+
// forked and publishing through reload, never gating activation on the network.
234+
if (configured.sources.some(isUrl))
235+
yield* reconfigure().pipe(
236+
Effect.andThen(refresh()),
237+
Effect.andThen(discovery.reload()),
238+
Effect.forkScoped({ startImmediately: true }),
239+
)
226240
}).pipe(
227241
Effect.catchCause((cause) =>
228242
Effect.logWarning("failed to activate instruction source", { cause }).pipe(
Collapse file

‎packages/core/src/config/plugin/skill.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/config/plugin/skill.ts
+12-7Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,34 +147,37 @@ export const Plugin = define({
147147
})
148148

149149
const refresh = Effect.fn("ConfigSkillPlugin.refresh")(
150-
function* (file?: string) {
150+
function* (input?: { readonly file?: string; readonly remote?: boolean }) {
151151
yield* FiberMap.clear(watches)
152152
const skills = new Map<Skill.ID, Skill.Info>()
153-
const current = sources()
153+
const current = input?.remote === false ? sources().filter((source) => source.type === "directory") : sources()
154154
for (const source of current) {
155155
for (const skill of yield* load(source)) skills.set(skill.id, skill)
156156
}
157157
loaded.skills = Array.from(skills.values())
158-
if (file) {
158+
if (input?.file) {
159159
yield* Effect.logInfo("skills rescanned", {
160-
file,
160+
file: input.file,
161161
sources: current.map(Skill.Source.key),
162162
skills: loaded.skills.map((skill) => skill.id),
163163
})
164164
}
165165
},
166-
(effect, ..._args: [file?: string]) => lock.withPermit(effect),
166+
(effect, ..._args: [input?: { readonly file?: string; readonly remote?: boolean }]) => lock.withPermit(effect),
167167
)
168168

169169
// Editor saves arrive as bursts of watcher events; settle before rescanning once. Subscribe
170170
// before debouncing so no update slips through while the debounce starts its pull.
171171
const updates = yield* PubSub.subscribe(changes)
172172
yield* Stream.fromSubscription(updates).pipe(
173173
Stream.debounce("100 millis"),
174-
Stream.runForEach((file) => refresh(file).pipe(Effect.andThen(ctx.skill.reload()))),
174+
Stream.runForEach((file) => refresh({ file }).pipe(Effect.andThen(ctx.skill.reload()))),
175175
Effect.forkScoped({ startImmediately: true }),
176176
)
177-
yield* refresh()
177+
// A URL source waits on the network, which must not count against the plugin setup bound.
178+
// Register locally available skills now; the first catalog pull runs the way a config update
179+
// does: forked and publishing through reload.
180+
yield* refresh({ remote: false })
178181
yield* ctx.skill.transform((editor) => {
179182
for (const skill of loaded.skills) editor.add(skill)
180183
})
@@ -189,5 +192,7 @@ export const Plugin = define({
189192
),
190193
Effect.forkScoped({ startImmediately: true }),
191194
)
195+
if (sources().some((source) => source.type === "url"))
196+
yield* refresh().pipe(Effect.andThen(ctx.skill.reload()), Effect.forkScoped({ startImmediately: true }))
192197
}),
193198
})
Collapse file

‎packages/core/src/integration.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/integration.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ const layer = Layer.effect(
735735
if (!implementation?.refresh) return credential.value
736736
const now = yield* Clock.currentTimeMillis
737737
if (credential.value.expires > now + Duration.toMillis(Duration.minutes(5))) return credential.value
738-
const value = yield* authorize(implementation.refresh(credential.value))
738+
const value = yield* authorize(implementation.refresh(credential.value).pipe(Effect.timeout("10 seconds")))
739739
yield* credentials.update(credential.id, { value })
740740
return value
741741
}),
Collapse file

‎packages/core/src/plugin/provider/opencode.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/plugin/provider/opencode.ts
+24-1Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ export const OpencodePlugin = define<
233233
} = { config: undefined, connection: undefined, organization: undefined, mcp: undefined }
234234
// Status last reported for the active connection, so inference failures can name the fix.
235235
let reported: IntegrationConnection.Status | undefined
236+
// Whether the last load fell back without a Console answer, so the boot re-check only chases
237+
// config the Console never delivered (a 404 is an answer: no managed config).
238+
let failed = false
236239
let explainers: Effect.Success<ReturnType<typeof ctx.session.hook>>[] = []
237240
// When the last Console config load started, so rejected inference can reuse a recent status.
238241
let checked = Number.NEGATIVE_INFINITY
@@ -261,9 +264,19 @@ export const OpencodePlugin = define<
261264
})),
262265
)
263266
}),
264-
Effect.tap(() => status(undefined)),
267+
// Generous enough for a cold TLS and auth round trip on a slow network: a spurious
268+
// timeout at boot starts the server without the organization policies this config carries.
269+
Effect.timeoutOrElse({
270+
duration: Duration.seconds(15),
271+
orElse: () => Effect.fail(new Error("OpenCode Console config request timed out")),
272+
}),
273+
Effect.tap(() => {
274+
failed = false
275+
return status(undefined)
276+
}),
265277
Effect.catch((cause) =>
266278
Effect.gen(function* () {
279+
failed = true
267280
// Only well-formed Console errors change the connection status; anything else may be transient.
268281
const next = connectionStatus(cause)
269282
if (next) yield* status(next)
@@ -608,6 +621,16 @@ export const OpencodePlugin = define<
608621
})
609622
yield* guard(snapshot)
610623

624+
// A connection whose config load failed runs without the organization policies the Console
625+
// may carry; re-check ahead of the periodic loop so a slow or briefly unreachable Console
626+
// converges to managed in seconds rather than a minute.
627+
if (failed)
628+
yield* check().pipe(
629+
Effect.delay(Duration.seconds(15)),
630+
Effect.repeat({ times: 2, until: () => !failed }),
631+
Effect.forkScoped,
632+
)
633+
611634
// Console config can change independently of local credential activity, so re-fetch
612635
// periodically and only rebuild the catalog and search providers when the snapshot differs.
613636
// Only while connected: a signed-out location runs no timer and no credential lookups.
Collapse file

‎packages/core/src/skill/discovery.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/skill/discovery.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ const layer = Layer.effect(
7373
schedule: Schedule.exponential(200).pipe(Schedule.jittered),
7474
}),
7575
HttpClient.filterStatusOk,
76+
// A source that accepts connections but never answers (hung DNS, black-holed network)
77+
// must not stall skill loading; the bound covers the retries above.
78+
HttpClient.transformResponse(Effect.timeout("10 seconds")),
7679
)
7780

7881
const download = Effect.fn("SkillDiscovery.download")(function* (url: string, destination: string) {
Collapse file

‎packages/core/test/config/skill.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/config/skill.test.ts
+33-3Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ const startEntries = Effect.fnUntraced(function* (
5353
claude: [],
5454
agents: [],
5555
},
56+
remote = false,
5657
) {
5758
const service = yield* Skill.Service
59+
const bus = yield* Bus.Service
5860
const pluginHost = host({
5961
skill: {
6062
list: () => Effect.die("unused skill.list"),
@@ -65,6 +67,13 @@ const startEntries = Effect.fnUntraced(function* (
6567
yield* ConfigCompatibilityPlugin.Plugin.effect(pluginHost).pipe(
6668
Effect.provide(Config.testLayer(entries, compatibility)),
6769
)
70+
// Activation registers the skill transform and publishes once; a configured URL source pulls
71+
// forked after activation and publishes once more through reload. Await both for remote tests
72+
// so they observe settled startup state.
73+
const settled = remote
74+
? yield* bus.subscribe(Skill.Event.Updated).pipe(Stream.take(2), Stream.runDrain, Effect.forkScoped)
75+
: undefined
76+
yield* Effect.yieldNow
6877
yield* ConfigSkillPlugin.Plugin.effect(
6978
pluginHost,
7079
).pipe(
@@ -73,10 +82,11 @@ const startEntries = Effect.fnUntraced(function* (
7382
Effect.provideService(Global.Service, Global.Service.of({ ...Global.make(), home })),
7483
Effect.provideService(Location.Service, Location.Service.of(location({ directory: AbsolutePath.make(directory) }))),
7584
)
85+
if (settled) yield* Fiber.join(settled).pipe(Effect.timeout("5 seconds"))
7686
return service
7787
})
7888

79-
const start = (skills: string[], directory: string, discovery = emptyDiscovery) =>
89+
const start = (skills: string[], directory: string, discovery = emptyDiscovery, remote = false) =>
8090
startEntries(
8191
[
8292
new Document({
@@ -87,6 +97,8 @@ const start = (skills: string[], directory: string, discovery = emptyDiscovery)
8797
directory,
8898
directory,
8999
discovery,
100+
undefined,
101+
remote,
90102
)
91103

92104
const discover = (directory: string, global: string) =>
@@ -237,7 +249,7 @@ describe("ConfigSkillPlugin.Plugin", () => {
237249
},
238250
})
239251

240-
const skill = yield* start([first, "https://example.test/skills/"], tmp.path, discovery)
252+
const skill = yield* start([first, "https://example.test/skills/"], tmp.path, discovery, true)
241253
expect((yield* skill.list()).map((item) => item.id).toSorted()).toEqual([
242254
Skill.ID.make("deploy"),
243255
Skill.ID.make("review"),
@@ -295,7 +307,25 @@ describe("ConfigSkillPlugin.Plugin", () => {
295307
const url = "https://unreachable.example.test/skills/"
296308
const discovery = SkillDiscovery.Service.of({ pull: () => Effect.die(`failed to pull ${url}`) })
297309

298-
const skill = yield* start([tmp.path, url], tmp.path, discovery)
310+
const skill = yield* start([tmp.path, url], tmp.path, discovery, true)
311+
expect((yield* skill.list()).find((item) => item.id === "review")?.description).toBe("Available")
312+
}),
313+
),
314+
),
315+
)
316+
317+
it.live("activates with directory skills while a URL source hangs", () =>
318+
Effect.acquireDisposable(Effect.promise(() => tmpdir())).pipe(
319+
Effect.flatMap((tmp) =>
320+
Effect.gen(function* () {
321+
yield* Effect.promise(async () => {
322+
await fs.mkdir(path.join(tmp.path, "review"), { recursive: true })
323+
await write(tmp.path, "review", "Available")
324+
})
325+
const discovery = SkillDiscovery.Service.of({ pull: () => Effect.never })
326+
327+
// The forked catalog pull never settles; activation must still return with local skills.
328+
const skill = yield* start([tmp.path, "https://hung.example.test/skills/"], tmp.path, discovery)
299329
expect((yield* skill.list()).find((item) => item.id === "review")?.description).toBe("Available")
300330
}),
301331
),
Collapse file

‎packages/core/test/instruction-discovery.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/instruction-discovery.test.ts
+15-2Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ const start = Effect.fnUntraced(function* (ctx = host()) {
7474
return yield* InstructionDiscovery.Service
7575
})
7676

77+
// Activation publishes once registering the discovery transform, and the forked URL fetch
78+
// publishes once more through reload; await both so tests observe settled remote state.
79+
const startRemote = Effect.fnUntraced(function* (ctx = host()) {
80+
const bus = yield* Bus.Service
81+
const settled = yield* bus
82+
.subscribe(InstructionDiscovery.Event.Updated)
83+
.pipe(Stream.take(2), Stream.runDrain, Effect.forkScoped)
84+
yield* Effect.yieldNow
85+
const discovery = yield* start(ctx)
86+
yield* Fiber.join(settled).pipe(Effect.timeout("5 seconds"))
87+
return discovery
88+
})
89+
7790
const configured = (instructions: string[]) => new Document({ type: "document", info: new Info({ instructions }) })
7891

7992
const readFailure = (tag: "NotFound" | "Unknown", code: string, file: string) =>
@@ -317,7 +330,7 @@ describe("ConfigInstructionPlugin.Plugin", () => {
317330
])
318331
})
319332

320-
const discovery = yield* start()
333+
const discovery = yield* startRemote()
321334
const initialized = yield* readInitial(yield* discovery.load())
322335
// The unreachable URL and missing file are skipped without making AGENTS.md unavailable.
323336
expect(initialized.text).toBe(
@@ -388,7 +401,7 @@ describe("ConfigInstructionPlugin.Plugin", () => {
388401
})
389402
const events = yield* PubSub.unbounded<ReturnType<typeof configUpdated>>()
390403
const config = yield* Config.Test
391-
const discovery = yield* start(host({ event: { subscribe: () => Stream.fromPubSub(events) } }))
404+
const discovery = yield* startRemote(host({ event: { subscribe: () => Stream.fromPubSub(events) } }))
392405
const initialized = yield* readInitial(yield* discovery.load())
393406
expect(initialized.text).toBe(
394407
[`Instructions from: ${first}\nfirst`, `Instructions from: ${remote}\nremote`].join("\n\n"),
Collapse file

‎packages/core/test/npm.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/npm.test.ts
+72-1Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "fs/promises"
22
import path from "path"
33
import { pathToFileURL } from "url"
44
import { describe, expect, test } from "bun:test"
5-
import { Effect } from "effect"
5+
import { Duration, Effect } from "effect"
66
import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder"
77
import { Global } from "@opencode/util/global"
88
import { Npm } from "@opencode/util/npm"
@@ -111,6 +111,30 @@ async function createRegistryFixture(directory: string) {
111111
}
112112
}
113113

114+
function createHungRegistry() {
115+
// Accepts requests and never answers, like a black-holed or firewalled registry.
116+
const server = Bun.serve({
117+
hostname: "127.0.0.1",
118+
port: 0,
119+
fetch: () => new Promise<Response>(() => {}),
120+
})
121+
return {
122+
url: server.url,
123+
async configure(cache: string, spec: string) {
124+
const root = path.join(cache, "npm", await Npm.cacheKey(spec))
125+
await fs.mkdir(root, { recursive: true })
126+
await Bun.write(
127+
path.join(root, ".npmrc"),
128+
`registry=${server.url}\n@fixture:registry=${server.url}\ncache=${path.join(cache, "npm-cache")}\nfetch-retries=0\n`,
129+
)
130+
return root
131+
},
132+
async [Symbol.asyncDispose]() {
133+
await server.stop(true)
134+
},
135+
}
136+
}
137+
114138
describe("Npm.sanitize", () => {
115139
test("keeps normal scoped package specs unchanged", () => {
116140
expect(Npm.sanitize("@opencode/acme")).toBe("@opencode/acme")
@@ -310,6 +334,29 @@ describe("Npm.add", () => {
310334
expect(result.current).toBeFalse()
311335
}, 30_000)
312336

337+
test("fails within the configured bound when the registry never responds", async () => {
338+
await using tmp = await tmpdir()
339+
await using registry = createHungRegistry()
340+
const cache = path.join(tmp.path, "cache")
341+
const spec = "@fixture/hung-plugin@latest"
342+
const root = await registry.configure(cache, spec)
343+
344+
const error = await Effect.gen(function* () {
345+
const npm = yield* Npm.Service
346+
return yield* npm.add(spec).pipe(Effect.flip)
347+
}).pipe(
348+
Effect.provideService(Npm.Timeouts, { install: Duration.millis(500), check: Duration.millis(500) }),
349+
Effect.scoped,
350+
Effect.provide(npmLayer(cache)),
351+
Effect.runPromise,
352+
)
353+
354+
expect(error).toBeInstanceOf(Npm.InstallFailedError)
355+
if (error instanceof Npm.InstallFailedError) expect(String(error.cause)).toContain("did not finish")
356+
// The timed-out install must leave no staging directory behind.
357+
expect((await fs.readdir(root)).filter((entry) => entry.startsWith(".staging-"))).toEqual([])
358+
})
359+
313360
// Symlink creation needs elevated privileges on Windows.
314361
test.skipIf(win)("records Git revisions when the cache directory is reached through a symlink", async () => {
315362
await using tmp = await tmpdir()
@@ -443,4 +490,28 @@ describe("Npm.check and Npm.update", () => {
443490

444491
expect(outdated).toBeFalse()
445492
})
493+
494+
test("fails checks within the configured bound when the registry never responds", async () => {
495+
await using tmp = await tmpdir()
496+
await using registry = createHungRegistry()
497+
const cache = path.join(tmp.path, "cache")
498+
const spec = "@fixture/hung-plugin@latest"
499+
const root = await registry.configure(cache, spec)
500+
const directory = path.join(root, "1000", "node_modules", "@fixture", "hung-plugin")
501+
await fs.mkdir(directory, { recursive: true })
502+
await writePackage(directory, { name: "@fixture/hung-plugin" })
503+
504+
const error = await Effect.gen(function* () {
505+
const npm = yield* Npm.Service
506+
return yield* npm.check(spec).pipe(Effect.flip)
507+
}).pipe(
508+
Effect.provideService(Npm.Timeouts, { install: Duration.millis(500), check: Duration.millis(500) }),
509+
Effect.scoped,
510+
Effect.provide(npmLayer(cache)),
511+
Effect.runPromise,
512+
)
513+
514+
expect(error).toBeInstanceOf(Npm.InstallFailedError)
515+
if (error instanceof Npm.InstallFailedError) expect(String(error.cause)).toContain("did not finish")
516+
})
446517
})

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.