Skip to content

An open-source, faster Devin alternative

TypeScript

Webhooks: collector scrubs the credential from free text too; terminal exposed; docs state the acceptance boundary

Igor Zalutski7b574d45cce0
diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.ts
index 6ea58696..5f398608 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.ts
@@ -506,6 +506,8 @@ function publicWebhookRequest(value: unknown): Record<string, unknown> {
deploymentId: request.deploymentId,
sessionId: request.sessionId,
outcome: request.outcome,
+ ...(typeof request.attempt === "number" ? { attempt: request.attempt } : {}),
+ ...(request.terminal === true ? { terminal: true } : {}),
...(request.error
? { error: "The webhook request could not start a session." }
: {}),
@@ -1350,7 +1352,8 @@ export async function handleManagedAgentChannelConnection(
// A webhook may read its delivery identity from any request header the
// sender chose at configuration time, so the sender's headers pass through
// except credentials, transport headers, and anything the backend trusts
-// from this edge.
+// from this edge. The backend rejects identity sources naming these headers
+// (`bluecode/src/edge/webhook-input.ts`); change both together.
const WEBHOOK_HEADERS_NOT_FORWARDED = new Set([
"authorization",
"cookie",
diff --git a/cloudflare-workers/log-tail/src/index.test.ts b/cloudflare-workers/log-tail/src/index.test.ts
index b8b00783..30c3fc7e 100644
--- a/cloudflare-workers/log-tail/src/index.test.ts
+++ b/cloudflare-workers/log-tail/src/index.test.ts
@@ -94,12 +94,31 @@ test("redacts the webhook credential segment from request URLs", async () => {
},
logs: [],
exceptions: [],
+ }, {
+ scriptName: "managed-agents",
+ outcome: "ok",
+ eventTimestamp: Date.parse("2026-09-08T20:00:03Z"),
+ event: {
+ request: { method: "POST", url: "https://managedagents.example/v1/other" },
+ response: { status: 500 },
+ },
+ // A console message that quoted the path, as an unredacted emitter would.
+ logs: [{
+ level: "error",
+ timestamp: Date.parse("2026-09-08T20:00:03Z"),
+ message: [`{"event":"edge.request_failed","path":"/v1/agent-webhooks/wh_0123456789abcdef0123456789abcdef/${token}"}`],
+ }],
+ exceptions: [],
}], env, {} as ExecutionContext);
} finally {
globalThis.fetch = originalFetch;
}
- assert.equal(records.length, 3);
+ assert.equal(records.length, 4);
+ assert.equal(
+ records[3]?.msg,
+ `{"event":"edge.request_failed","path":"/v1/agent-webhooks/wh_0123456789abcdef0123456789abcdef/redacted"}`,
+ );
assert.equal(
records[2]?.request_url,
"https://app.opencomputer.dev/api/agent-webhooks/wh_0123456789abcdef0123456789abcdef/redacted",
diff --git a/cloudflare-workers/log-tail/src/index.ts b/cloudflare-workers/log-tail/src/index.ts
index 595f502a..3f6907a9 100644
--- a/cloudflare-workers/log-tail/src/index.ts
+++ b/cloudflare-workers/log-tail/src/index.ts
@@ -44,9 +44,11 @@ interface TraceItem {
}
function fmtMessage(parts: unknown[]): string {
- return parts
- .map((p) => (typeof p === "string" ? p : safeStringify(p)))
- .join(" ");
+ return redactWebhookTokens(
+ parts
+ .map((p) => (typeof p === "string" ? p : safeStringify(p)))
+ .join(" "),
+ );
}
function safeStringify(v: unknown): string {
@@ -58,6 +60,13 @@ function safeStringify(v: unknown): string {
// `/api/agent-webhooks/<id>/<token>`, backend `/v1/agent-webhooks/<id>/<token>`).
// Everything after the id is redacted, whatever suffix a malformed request adds.
const WEBHOOK_TOKEN_PATH = /^(\/(?:api|v1)\/agent-webhooks\/[^/]+)\/.*$/;
+// The same credential position anywhere in free text (a console message or
+// an exception that quoted the path). Defense in depth: emitters redact too.
+const WEBHOOK_TOKEN_IN_TEXT = /(\/(?:api|v1)\/agent-webhooks\/wh_[a-f0-9]{32})\/[^\s"'\\]+/g;
+
+function redactWebhookTokens(text: string): string {
+ return text.replace(WEBHOOK_TOKEN_IN_TEXT, "$1/redacted");
+}
// Request query strings can carry browser client tokens (`?token=...`), and
// webhook paths carry the webhook credential. Keep the route useful for
@@ -121,7 +130,7 @@ export default {
_time: new Date(ex.timestamp).toISOString(),
time: new Date(ex.timestamp).toISOString(),
level: "ERROR",
- msg: `${ex.name}: ${ex.message}`,
+ msg: redactWebhookTokens(`${ex.name}: ${ex.message}`),
stack: ex.stack,
...baseEnvelope,
});
diff --git a/docs/agents/webhooks.mdx b/docs/agents/webhooks.mdx
index e81d5d57..c22fe3d8 100644
--- a/docs/agents/webhooks.mdx
+++ b/docs/agents/webhooks.mdx
@@ -65,11 +65,14 @@ credential.
The response is HTTP 202 with the request, session ID, and dashboard session
URL. It is sent as soon as the delivery is stored; the session starts
afterwards, so acknowledgement does not wait for a runtime.
-The request's `outcome` is `pending` in the response and becomes `accepted`
-once the session is running, or `failed` after five start attempts over
-about thirteen minutes. Read outcomes from the request ledger with your API
-key; the session id there is authoritative, since a retried start can use a
-different session than the one first announced:
+The request's `outcome` is `pending` in the response. It becomes `accepted`
+once the session holds the turn, which is the point of no return: from
+there the session runs it, even if the runtime has to be started again.
+It becomes `failed` after five start attempts over about thirteen minutes,
+or at once when the platform can tell that no retry would help; such a
+request carries `terminal: true`. Read outcomes from the request ledger
+with your API key; the session id there is authoritative, since a retried
+start can use a different session than the one first announced:
```bash
curl 'https://app.opencomputer.dev/api/managed-agents/projects/<project-id>/webhooks/<webhook-id>/requests?environment=production' \
@@ -97,8 +100,18 @@ id in the body. Without a source, every delivery that sets no
Retrying with the same `Idempotency-Key` and a different body is a 409. A
retry under a configured source returns the original request even if the
provider reserialized the body. If the original request had failed to
-start, the retry starts it again. A body larger than 256 KiB once wrapped
-as agent input is rejected with 400 before acknowledgement.
+start after its attempts, the retry starts it again; if it failed with
+`terminal: true`, the retry returns that failure unchanged. To recover a
+terminal failure, resend the saved payload with a fresh `Idempotency-Key`,
+which overrides the configured source and starts a new request. A body
+larger than 256 KiB once wrapped as agent input is rejected with 400
+before acknowledgement.
+
+A header source cannot name a header the platform sets or strips before
+the backend reads it: `Authorization`, `Cookie`, `Idempotency-Key`,
+`X-Request-Id`, `X-Api-Key`, transport headers, and anything starting with
+`x-oc-`, `cf-`, `x-forwarded-`, or `x-real-`. Creating a webhook with one
+of these is rejected.
## Read webhook input