-
Notifications
You must be signed in to change notification settings - Fork 751
fix(sdk): preserve canceled scan state #735
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
base: main
Are you sure you want to change the base?
Changes from all commits
53a8c9f
67afadc
3394120
13ca814
6eb5e4d
ad93cd5
647d726
3854a75
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 |
|---|---|---|
|
|
@@ -1835,17 +1835,26 @@ export class CodexSecurity { | |
| reason: safeErrorMessage(failure), | ||
| }).catch(() => undefined); | ||
| } | ||
| const canceled = | ||
| signal.aborted && | ||
| (options.signal?.aborted === true || | ||
| this.#abortController.signal.aborted) && | ||
| isCancellationDerivedFailure(failure, signal); | ||
| try { | ||
| await workbench({ ...activeScan.options, signal: undefined }, [ | ||
| "fail-scan", | ||
| canceled ? "cancel-scan" : "fail-scan", | ||
|
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.
When AGENTS.md reference: sdk/typescript/AGENTS.md:L23-L23 Useful? React with 👍 / 👎.
Contributor
Author
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. Addressed in commit |
||
| "--scan-id", | ||
| activeScan.id, | ||
| // Scan history can be shared; never persist credential-bearing failures. | ||
| "--message", | ||
| safeErrorMessage(failure).slice(0, 2400), | ||
| ...(snapshot?.cost | ||
| ? ["--cost-json", JSON.stringify(snapshot.cost)] | ||
| : []), | ||
| ...(canceled | ||
| ? [] | ||
| : [ | ||
| // Scan history can be shared; never persist credential-bearing failures. | ||
| "--message", | ||
| safeErrorMessage(failure).slice(0, 2400), | ||
| ...(snapshot?.cost | ||
| ? ["--cost-json", JSON.stringify(snapshot.cost)] | ||
| : []), | ||
| ]), | ||
| ]); | ||
| } catch {} | ||
| } | ||
|
|
@@ -2698,12 +2707,18 @@ export class CodexSecurity { | |
| return result; | ||
| } catch (error) { | ||
| if (activeScan !== undefined) { | ||
| const canceled = | ||
| signal.aborted && | ||
| (options.signal?.aborted === true || | ||
| this.#abortController.signal.aborted) && | ||
| isCancellationDerivedFailure(error, signal); | ||
| await workbench({ ...activeScan.options, signal: undefined }, [ | ||
| "fail-scan", | ||
| canceled ? "cancel-scan" : "fail-scan", | ||
| "--scan-id", | ||
| activeScan.id, | ||
| "--message", | ||
| safeErrorMessage(error).slice(0, 2400), | ||
| ...(canceled | ||
| ? [] | ||
| : ["--message", safeErrorMessage(error).slice(0, 2400)]), | ||
| ]).catch(() => undefined); | ||
| } | ||
| if (this.#closed) this.#requireOpen(); | ||
|
|
@@ -4137,6 +4152,31 @@ function throwIfAborted(signal?: AbortSignal, scanDir = ""): void { | |
| throw new ScanInterruptedError(message, scanDir, { cause: signal.reason }); | ||
| } | ||
|
|
||
| function isCancellationDerivedFailure( | ||
| failure: unknown, | ||
| signal: AbortSignal, | ||
| ): boolean { | ||
| let current = failure; | ||
| const seen = new Set<ScanInterruptedError>(); | ||
| while (current instanceof ScanInterruptedError) { | ||
| if (current instanceof ScanCostLimitExceededError) return false; | ||
| if (current.cause === undefined) return true; | ||
| if (seen.has(current)) return false; | ||
| seen.add(current); | ||
| current = current.cause; | ||
| } | ||
| if ( | ||
| current instanceof CodexSecurityError && | ||
| current.message === "CodexSecurity is closed." | ||
| ) { | ||
| return true; | ||
| } | ||
| return ( | ||
| current === signal.reason || | ||
| (isRecord(current) && current["name"] === "AbortError") | ||
| ); | ||
| } | ||
|
|
||
| function bundledCodexSdkEnvironment( | ||
| command: string, | ||
| environment: Record<string, string>, | ||
|
|
||
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.
When
close()aborts an already registered scan just as an awaited operation completes normally, the subsequentcheckOpen()throwsCodexSecurity is closed.beforethrowIfAborted()can produce a cancellation-derived error. That ordinary error fails this predicate, so the scan is still persisted throughfail-scaneven though client closure caused it to stop. Classify this closed-client path as cancellation while continuing to preserve any earlier internal failure.AGENTS.md reference: sdk/typescript/AGENTS.md:L23-L25
Useful? React with 👍 / 👎.