Repository navigation
fix(ci): bound selected HttpApi cleanup waits and enable tracing #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5f05ad1
10d3c2a
7275190
5ae5963
d5c5fe2
cb107a4
8bdf976
c3455f0
b182d55
e76351e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { setTimeout as sleep } from "node:timers/promises" | ||
| import { Flag } from "@opencode-ai/core/flag/flag" | ||
| import { ConfigV1 } from "@opencode-ai/core/v1/config/config" | ||
| import { SessionV1 } from "@opencode-ai/core/v1/session" | ||
|
|
@@ -14,6 +15,38 @@ import type { ActiveScenario, Options, ProjectOptions, Result, Scenario, Scenari | |
| import { ProviderV2 } from "@opencode-ai/core/provider" | ||
| import { ModelV2 } from "@opencode-ai/core/model" | ||
|
|
||
| const CLEANUP_BOUND_MS = 60_000 | ||
|
|
||
| // Finalizers run uninterruptibly, so an Effect timeout cannot bound cleanup: | ||
| // race each async disposal against a plain timer instead. The timer is | ||
| // aborted as soon as the race settles, so a fast success logs nothing | ||
| // and leaves no timer pending. Wedges and disposal errors are logged and | ||
| // swallowed rather than propagated: these are best-effort resets of | ||
| // test-scoped state (scratch db/tmp per run) that must neither hang the run | ||
| // nor mask the scenario's own result - resetState runs under | ||
| // Effect.ensuring, and in this Effect version a failing finalizer replaces | ||
| // the scenario's original cause. | ||
| const bounded = (label: string, promise: Promise<unknown>): Promise<void> => { | ||
| const cancel = new AbortController() | ||
| const bound = sleep(CLEANUP_BOUND_MS, undefined, { signal: cancel.signal }) | ||
| .then(() => { | ||
| console.error(`[reset] ${label} did not finish within ${CLEANUP_BOUND_MS / 1000}s; continuing`) | ||
| }) | ||
| // The finally below aborts this timer once the race settles; the race | ||
| // already observes the resulting AbortError, and this catch swallows it | ||
| // explicitly so static review sees the rejection as handled. | ||
| .catch(() => {}) | ||
| return Promise.race([ | ||
| promise.then( | ||
| () => {}, | ||
| (error) => { | ||
| console.error(`[reset] ${label} failed; continuing`, error) | ||
| }, | ||
| ), | ||
| bound, | ||
| ]).finally(() => cancel.abort()) | ||
| } | ||
|
|
||
| export function runScenario(options: Options) { | ||
| return (scenario: Scenario) => { | ||
| if (scenario.kind === "todo") return Effect.succeed({ status: "skip", scenario } as Result) | ||
|
|
@@ -79,8 +112,14 @@ function withContext<A, E>( | |
| (ctx) => | ||
| Effect.gen(function* () { | ||
| yield* trace(options, scenario, `${label} tmpdir cleanup start`) | ||
| // Finalizers run uninterruptibly, so an Effect timeout could not bound | ||
| // this either: bounded() races the disposal against a plain timer. | ||
| // After a scenario timeout the run must move on even if cleanup is | ||
| // wedged. Effect.ignore still guards a synchronous throw from the | ||
| // asyncDispose call itself. | ||
| yield* Effect.promise(async () => { | ||
| await ctx.dir?.[Symbol.asyncDispose]() | ||
| const disposal = ctx.dir?.[Symbol.asyncDispose]() | ||
| if (disposal) await bounded(`${label} tmpdir disposal`, disposal) | ||
| }).pipe(Effect.ignore) | ||
| yield* trace(options, scenario, `${label} tmpdir cleanup done`) | ||
| }), | ||
|
|
@@ -270,8 +309,8 @@ const resetState = Effect.promise(async () => { | |
| const modules = await runtime() | ||
| Flag.OPENCODE_SERVER_PASSWORD = original.OPENCODE_SERVER_PASSWORD | ||
| Flag.OPENCODE_SERVER_USERNAME = original.OPENCODE_SERVER_USERNAME | ||
| await disposeApps() | ||
| await modules.disposeAllInstances() | ||
| await modules.resetDatabase() | ||
| await bounded("disposeApps", disposeApps()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: Sequential Three sequential Reply with |
||
| await bounded("disposeAllInstances", modules.disposeAllInstances()) | ||
| await bounded("resetDatabase", modules.resetDatabase()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION:
|
||
| await Bun.sleep(25) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Inconsistent error handling vs
boundedhelperThe comment claims "Same reasoning as bounded()" but the behavior differs: this tmpdir cleanup always resolves (both fulfillment and rejection of
disposalcallresolve()), whilebounded(line 297) rejects on disposal rejection. If disposal fails here, the error is silently swallowed; inresetStateit would propagate. Decide which behavior is intentional and align them, or update the comment.