Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Fit a webhook payload whose top-level fields alone exceed the cap (#707)
Omkar Chebale8c4b4485ba4b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a973b2ca..29d01357 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,14 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.## Unreleased+### A webhook with many long top-level fields no longer stops the server++A trigger's event is cut to 32 KiB before it is recorded, keeping each top-level text field up to+1000 characters and an excerpt of the rest. A flat payload whose fields alone came to more than+that, such as forty 1000-character fields, left the excerpt nothing to give up, and the loop+trimming it never ended. That loop runs on the server's only thread, so every request stopped being+answered. The kept fields now get at most half the space, and the rest is still in the excerpt.+### A malformed IP range in an egress rule is refused instead of widening the ruleAn egress `cidr` rule written `10.0.0.5/` was stored as `10.0.0.5/0`, which is every IPv4diff --git a/server/src/responsibilities/triggers.ts b/server/src/responsibilities/triggers.tsindex 833c251d..e95e2da7 100644--- a/server/src/responsibilities/triggers.ts+++ b/server/src/responsibilities/triggers.ts@@ -240,13 +240,21 @@ export function fitPayload(): Record<string, unknown> {const whole = JSON.stringify(payload);if (whole.length <= MAX_EVENT_PAYLOAD) return payload;+ // The scalars get half the cap. Uncapped, forty 1000-character fields filled it alone, the+ // excerpt below could not shrink past "", and the loop that trims it never ended.const scalars: Record<string, unknown> = {};+ let kept = 0;for (const [key, value] of Object.entries(payload))if (value === null ||["string", "number", "boolean"].includes(typeof value)- )- scalars[key] = typeof value === "string" ? value.slice(0, 1000) : value;+ ) {+ const scalar = typeof value === "string" ? value.slice(0, 1000) : value;+ const size = JSON.stringify({ [key]: scalar }).length;+ if (kept + size > MAX_EVENT_PAYLOAD / 2) continue;+ scalars[key] = scalar;+ kept += size;+ }const fitted: Record<string, unknown> = {truncated: true,...scalars,diff --git a/server/tests/responsibility-triggers.test.ts b/server/tests/responsibility-triggers.test.tsindex 6c4387c9..12a6f491 100644--- a/server/tests/responsibility-triggers.test.ts+++ b/server/tests/responsibility-triggers.test.ts@@ -150,6 +150,16 @@ describe("matching rule", () => {expect(fitted.action).toBe("created");expect(fitted.truncated).toBe(true);});+ test("a payload whose top-level scalars alone exceed the cap is still fitted", () => {+ // Forty 1000-character fields: before, this never returned.+ const flat = Object.fromEntries(+ Array.from({ length: 40 }, (_, i) => [`field${i}`, "y".repeat(1000)]),+ );+ const fitted = fitPayload(flat);+ expect(JSON.stringify(fitted).length).toBeLessThanOrEqual(32_768);+ expect(fitted.field0).toBe("y".repeat(1000));+ expect(fitted.truncated).toBe(true);+ });test("config validation refuses a phrase listener with no phrases", () => {expect(() =>parseTriggerConfig({ kind: "slack", teamId: "T123", mode: "phrase" }),