mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix(ocm): abort the feature probe with the caller signal and keep fusion request ids across reopened multi-run commands
This commit is contained in:
1 parent
c41149dc39
commit
390f95710c
4 files changed
+42
-11
No files matched your search
@@ -151,21 +151,30 @@ export class ManagerApi {
|
||||
...requestInit,
|
||||
headers: { ...baseHeaders, ...(requestInit.headers as Record<string, string> | undefined) },
|
||||
})
|
||||
if (!res.ok) throw await this.handleErrorResponse(res, operation, feature === true)
|
||||
if (!res.ok) throw await this.handleErrorResponse(res, operation, feature === true, requestInit.signal ?? undefined)
|
||||
return parse(await res.json())
|
||||
}
|
||||
|
||||
private async handleErrorResponse(res: Response, operation: string, feature: boolean): Promise<ManagerApiError> {
|
||||
private async handleErrorResponse(
|
||||
res: Response,
|
||||
operation: string,
|
||||
feature: boolean,
|
||||
signal?: AbortSignal,
|
||||
): Promise<ManagerApiError> {
|
||||
const error = await formatErrorResponse(res, operation)
|
||||
if (feature && error.status === 401) {
|
||||
return this.probeFeatureSupport(operation, error)
|
||||
return this.probeFeatureSupport(operation, error, signal)
|
||||
}
|
||||
return error
|
||||
}
|
||||
|
||||
private async probeFeatureSupport(operation: string, fallback: ManagerApiError): Promise<ManagerApiError> {
|
||||
private async probeFeatureSupport(
|
||||
operation: string,
|
||||
fallback: ManagerApiError,
|
||||
signal?: AbortSignal,
|
||||
): Promise<ManagerApiError> {
|
||||
try {
|
||||
const res = await fetch(`${this.baseUrl}/api/internal/opencode-workspaces`, { headers: this.headers() })
|
||||
const res = await fetch(`${this.baseUrl}/api/internal/opencode-workspaces`, { headers: this.headers(), signal })
|
||||
if (res.ok) {
|
||||
return new ManagerApiError(
|
||||
`${operation} failed: this OpenCode Manager is too old for ocm goals and multi-runs; upgrade the Manager.`,
|
||||
|
||||
@@ -258,9 +258,9 @@ function fusionRequestKey(runId: number, form: FusionFormInput): string {
|
||||
return JSON.stringify([runId, [...form.entryIds].sort((a, b) => a - b), form.model, form.baseRef.trim(), form.instructions.trim()])
|
||||
}
|
||||
|
||||
function createMultiRunActions(context: Context, api: ManagerApi, repoId: number): MultiRunActions {
|
||||
const pendingFusions = new Map<string, string>()
|
||||
const pendingFusions = new Map<string, string>()
|
||||
|
||||
function createMultiRunActions(context: Context, api: ManagerApi, repoId: number): MultiRunActions {
|
||||
const attempt = async <Value>(operation: () => Promise<Value>): Promise<ActionResult<Value>> => {
|
||||
try {
|
||||
return { ok: true, value: await operation() }
|
||||
|
||||
Reference in new issue
Block a user