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(process): reject finite trace variants that only reorder unordered members (#6006)
Kaoru08224423b6fff21f
diff --git a/src/domain/process/processTraceSpecification.test.ts b/src/domain/process/processTraceSpecification.test.tsindex ab649d2aa..edb152079 100644--- a/src/domain/process/processTraceSpecification.test.ts+++ b/src/domain/process/processTraceSpecification.test.ts@@ -305,4 +305,50 @@ describe("finite trace specification validation", () => {}).success,).toBe(false);});++ it("rejects variants that accept the same traces as an earlier variant", () => {+ const base = specification();+ const result = processTraceSpecificationSchema.safeParse({+ events: [+ { ...base.events[0], cardinality: { kind: "exact", count: 2 } },+ base.events[1],+ ],+ language: {+ kind: "finite_traces",+ variants: [+ {+ id: "repeated",+ trace: [{ unordered: ["ready", "ready"] }, "worker"],+ },+ { id: "sequence", trace: ["ready", "ready", "worker"] },+ {+ id: "leading",+ trace: [{ unordered: ["ready", "worker"] }, "ready"],+ },+ {+ id: "trailing",+ trace: ["ready", { unordered: ["worker", "ready"] }],+ },+ {+ id: "merged",+ trace: [{ unordered: ["worker", "ready", "ready"] }],+ },+ {+ id: "swapped",+ trace: ["ready", { unordered: ["ready", "worker"] }],+ },+ ],+ },+ });+ expect(result.success).toBe(false);+ if (result.success) throw new Error("Expected duplicate finite traces");+ expect(+ result.error.issues.map(({ path, message }) => ({ path, message })),+ ).toEqual(+ [1, 5].map((index) => ({+ path: ["language", "variants", index, "trace"],+ message: "finite trace variants must not duplicate a trace",+ })),+ );+ });});diff --git a/src/domain/process/processTraceSpecification.ts b/src/domain/process/processTraceSpecification.tsindex 4e28774e0..dd40d6108 100644--- a/src/domain/process/processTraceSpecification.ts+++ b/src/domain/process/processTraceSpecification.ts@@ -552,6 +552,22 @@ const countVariantEvents = (return counts;};+/**+ * Keys a finite trace by the observations it accepts. Matching treats each+ * unordered token as a multiset, so its member order is not significant and a+ * token that repeats one event accepts only that event's sequence.+ */+const finiteTraceKey = (+ trace: readonly (string | { readonly unordered: readonly string[] })[],+): string =>+ canonicalTraceJson(+ trace.flatMap((token): (string | readonly string[])[] => {+ if (typeof token === "string") return [token];+ const members = [...token.unordered].sort();+ return members[0] === members.at(-1) ? members : [members];+ }),+ );+const validateFiniteTraces = (specification: ProcessTraceSpecification,context: z.RefinementCtx,@@ -572,14 +588,14 @@ const validateFiniteTraces = (path: [...variantPath, "id"],});variantIds.add(variant.id);- const canonicalTrace = canonicalTraceJson(variant.trace);- if (variantTraces.has(canonicalTrace))+ const traceKey = finiteTraceKey(variant.trace);+ if (variantTraces.has(traceKey))context.addIssue({code: "custom",message: "finite trace variants must not duplicate a trace",path: [...variantPath, "trace"],});- variantTraces.add(canonicalTrace);+ variantTraces.add(traceKey);for (const [tokenIndex, token] of variant.trace.entries()) {const values = typeof token === "string" ? [token] : token.unordered;for (const [eventIndex, id] of values.entries())diff --git a/tests/boundary/mcp/processTraceAdaptersParity.test.ts b/tests/boundary/mcp/processTraceAdaptersParity.test.tsindex d8c9b6173..0fa2f948d 100644--- a/tests/boundary/mcp/processTraceAdaptersParity.test.ts+++ b/tests/boundary/mcp/processTraceAdaptersParity.test.ts@@ -155,4 +155,58 @@ describe("declared trace adapter parity", () => {expect(text.match(/first undeclared pair/g)).toHaveLength(1);await client.ping();});++ it("rejects a variant that only reorders unordered members through CLI and MCP", async () => {+ const left = captureEvidence("left");+ const right = captureEvidence("right");+ const reorderedSpecification = {+ ...traceSpecification,+ language: {+ kind: "finite_traces",+ variants: [+ {+ id: "forward",+ trace: ["before", { unordered: ["exit", "settlement"] }, "after"],+ },+ {+ id: "reverse",+ trace: ["before", { unordered: ["settlement", "exit"] }, "after"],+ },+ ],+ },+ };+ const root = await createTestTempDirectory("rea-trace-duplicates-");+ temporaryRoots.push(root);+ const leftPath = join(root, "left.json");+ const rightPath = join(root, "right.json");+ const specificationPath = join(root, "trace.json");+ await Promise.all([+ writeFile(leftPath, JSON.stringify(left)),+ writeFile(rightPath, JSON.stringify(right)),+ writeFile(specificationPath, JSON.stringify(reorderedSpecification)),+ ]);+ const message = "finite trace variants must not duplicate a trace";+ expect(+ await compareProcessEvidenceFiles(leftPath, rightPath, specificationPath),+ ).toMatchObject({+ category: "invalid_input",+ details: {+ issues: [+ { path: ["trace_spec", "language", "variants", 1, "trace"], message },+ ],+ },+ });+ const client = await comparisonClient(left, right);+ const response = await client.callTool({+ name: "compare_process_captures",+ arguments: { left, right, trace_spec: reorderedSpecification },+ });+ expect(response.isError).toBe(true);+ expect(+ response.content+ .filter((block) => block.type === "text")+ .map((block) => block.text)+ .join("\n"),+ ).toContain(message);+ });});