fix(process): bound retained trace ordering state
Prove total orders with Kahn traversal and use ranks; stream forward and reverse reachability for general partial orders instead of retaining every closure. Aggregate unordered conflicts by declaration while preserving missing-pair counts and independent malformed-input diagnostics. Validation: 33 focused trace domain and CLI/MCP boundary tests passed. Six bounded Flameox executions preserved answer digests and cycle rejection; combined median peak RSS fell from 391.13 to 127.72 MiB. General partial-order traversal costs more CPU; the experiment records that tradeoff. Full suite and real-provider lanes were not run.
This commit is contained in:
@@ -95,8 +95,54 @@ describe("process trace specification", () => {
|
||||
});
|
||||
expect(result.language.kind).toBe("partial_order");
|
||||
});
|
||||
});
|
||||
|
||||
it("counts only undeclared pairs after transitive, not-before and unordered relations", () => {
|
||||
describe("process trace ordering validation", () => {
|
||||
it("uses a unique topological order for transitive declarations and conflicts", () => {
|
||||
const events = ["a", "b", "c"].map((id) => ({
|
||||
id,
|
||||
source: "lifecycle" as const,
|
||||
exact: { marker: id },
|
||||
cardinality: { kind: "optional" as const },
|
||||
}));
|
||||
const accepted = processTraceSpecificationSchema.safeParse({
|
||||
events,
|
||||
language: {
|
||||
kind: "partial_order",
|
||||
happens_before: [
|
||||
{ before: "a", after: "b" },
|
||||
{ before: "b", after: "c" },
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(accepted.success).toBe(true);
|
||||
|
||||
const rejected = processTraceSpecificationSchema.safeParse({
|
||||
events,
|
||||
language: {
|
||||
kind: "partial_order",
|
||||
happens_before: [
|
||||
{ before: "a", after: "b" },
|
||||
{ before: "b", after: "c" },
|
||||
],
|
||||
not_before: [{ event: "a", anchor: "c" }],
|
||||
unordered_groups: [{ events: ["a", "b", "c"] }],
|
||||
},
|
||||
});
|
||||
if (rejected.success) throw new Error("Expected ordered pair conflicts");
|
||||
expect(rejected.error.issues).toEqual([
|
||||
expect.objectContaining({
|
||||
path: ["language", "not_before", 0],
|
||||
message: "not-before constraint conflicts with happens-before order",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
path: ["language", "unordered_groups", 0],
|
||||
message: "ordered events cannot also be declared unordered",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("counts only undeclared pairs across transitive and disconnected relations", () => {
|
||||
const events = ["a", "b", "c", "d"].map((id) => ({
|
||||
id,
|
||||
source: "lifecycle" as const,
|
||||
@@ -150,7 +196,82 @@ describe("process trace specification", () => {
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("malformed process trace declarations", () => {
|
||||
it("preserves independent diagnostics when event ids are duplicated", () => {
|
||||
const result = processTraceSpecificationSchema.safeParse({
|
||||
events: [
|
||||
{
|
||||
id: "a",
|
||||
source: "lifecycle",
|
||||
exact: { fixture: "first" },
|
||||
cardinality: { kind: "optional" },
|
||||
},
|
||||
{
|
||||
id: "a",
|
||||
source: "lifecycle",
|
||||
exact: { fixture: "second" },
|
||||
cardinality: { kind: "optional" },
|
||||
},
|
||||
],
|
||||
language: {
|
||||
kind: "partial_order",
|
||||
unordered_groups: [{ events: ["a", "b"] }],
|
||||
},
|
||||
});
|
||||
expect(result.success).toBe(false);
|
||||
if (result.success) throw new Error("Expected a duplicate event id");
|
||||
expect(result.error.issues).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
path: ["events", 1, "id"],
|
||||
message: "event ids must be unique",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
path: ["language", "unordered_groups", 0, "events", 1],
|
||||
message: "unknown event id: b",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps reachability diagnostics for unknown referenced successors", () => {
|
||||
const result = processTraceSpecificationSchema.safeParse({
|
||||
events: ["a", "b"].map((id) => ({
|
||||
id,
|
||||
source: "lifecycle",
|
||||
exact: { fixture: id },
|
||||
cardinality: { kind: "optional" },
|
||||
})),
|
||||
language: {
|
||||
kind: "partial_order",
|
||||
happens_before: [{ before: "a", after: "missing" }],
|
||||
not_before: [{ event: "a", anchor: "missing" }],
|
||||
},
|
||||
});
|
||||
expect(result.success).toBe(false);
|
||||
if (result.success) throw new Error("Expected an unknown event reference");
|
||||
expect(result.error.issues).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
path: ["language", "happens_before", 0, "after"],
|
||||
message: "unknown event id: missing",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
path: ["language", "not_before", 0, "anchor"],
|
||||
message: "unknown event id: missing",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
path: ["language", "not_before", 0],
|
||||
message: "not-before constraint conflicts with happens-before order",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("finite trace specification validation", () => {
|
||||
it("rejects invalid ignores and unsatisfiable variants", () => {
|
||||
const base = specification();
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user