Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(application): preserve a cancellation that races a completed provider run (#2710)
吴佳浩Alben855ed9689e97
diff --git a/src/application/ProviderOperationExecution.ts b/src/application/ProviderOperationExecution.tsindex bf4ad4b0e..966a43f29 100644--- a/src/application/ProviderOperationExecution.ts+++ b/src/application/ProviderOperationExecution.ts@@ -43,7 +43,7 @@ export const executeProviderOperation = async <provider: ProviderOperationPort<TRequest>,confidence: "observed" | "derived",): Promise<Result<Evidence, AnalysisError>> => {- if (options?.signal?.aborted === true)+ if (options?.signal?.aborted)return err(new AnalysisCancelledError(operation));const request = schema.safeParse({ operation, input });if (!request.success)@@ -51,8 +51,10 @@ export const executeProviderOperation = async <const executed = await provider.execute(request.data, options);if (!executed.ok) return executed;const execution = executed.value;- return ok(- createEvidence(execution.subject ?? undefined, execution.provider, {+ const evidence = createEvidence(+ execution.subject ?? undefined,+ execution.provider,+ {operation,parameters: jsonObjectSchema.parse(request.data.input),result: execution.result,@@ -60,6 +62,16 @@ export const executeProviderOperation = async <limitations: execution.limitations,locations: execution.locations,confidence,- }),+ },);+ // A provider that cannot observe the signal may finish its work after the+ // caller cancelled, so re-check rather than reporting a completed operation+ // the caller no longer wants. The observation it completed is still this+ // provider's Evidence, so the cancellation carries it as the partial+ // observation instead of discarding a finished result.+ if (options?.signal?.aborted)+ return err(+ new AnalysisCancelledError(operation, { partialObservation: evidence }),+ );+ return ok(evidence);};diff --git a/src/application/apktool/ApktoolResourceAnalysisService.test.ts b/src/application/apktool/ApktoolResourceAnalysisService.test.tsindex 6242bb54d..2220ce9e6 100644--- a/src/application/apktool/ApktoolResourceAnalysisService.test.ts+++ b/src/application/apktool/ApktoolResourceAnalysisService.test.ts@@ -83,3 +83,37 @@ it("preserves cancellation before execution", async () => {if (result.ok) return;expect(result.error).toBeInstanceOf(AnalysisCancelledError);});++it("preserves a cancellation that races a completed observation", async () => {+ const controller = new AbortController();+ const racingPort: ApktoolResourceAnalysisPort = {+ async inspectAvailability() {+ return { status: "available", code: null, reason: null, diagnostics: {} };+ },+ async close() {},+ async execute() {+ // The provider may finish its work before the abort is delivered, so a+ // successful result is not by itself proof the caller still wants it.+ controller.abort();+ return ok(execution);+ },+ };+ const result = await new ApktoolResourceAnalysisService(racingPort).execute(+ "decode_android_resources",+ { path: "/targets/app.apk", include_strings: true },+ { signal: controller.signal },+ );+ expect(result.ok).toBe(false);+ if (result.ok) return;+ expect(result.error).toBeInstanceOf(AnalysisCancelledError);+ // The observation the provider completed is retained on the cancellation, so+ // a session still records the Evidence instead of losing finished work.+ const retained = parseEvidence(result.error.partialObservation);+ expect(retained.operation).toBe("decode_android_resources");+ expect(retained.provider).toEqual(identity);+ expect(retained.parameters).toEqual({+ path: "/targets/app.apk",+ include_strings: true,+ });+ expect(retained.confidence).toBe("observed");+});