Skip to content

An open-source, faster Devin alternative

TypeScript

fix(agent-worker): make runtime errors durably observable

Igor Zalutski195e041138e9
diff --git a/cloudflare-workers/log-tail/src/index.test.ts b/cloudflare-workers/log-tail/src/index.test.ts
new file mode 100644
index 00000000..c5a6ed67
--- /dev/null
+++ b/cloudflare-workers/log-tail/src/index.test.ts
@@ -0,0 +1,66 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import worker from "./index.ts";
+
+const env = {
+ AXIOM_HOST: "https://axiom.test",
+ AXIOM_DATASET: "edge",
+ AXIOM_TOKEN: "test-token",
+};
+
+test("records a silent HTTP 5xx even when the invocation outcome is ok", async () => {
+ const originalFetch = globalThis.fetch;
+ let records: Array<Record<string, unknown>> = [];
+ globalThis.fetch = (async (_input: RequestInfo | URL, init?: RequestInit) => {
+ records = JSON.parse(String(init?.body));
+ return new Response(null, { status: 200 });
+ }) as typeof fetch;
+
+ try {
+ await worker.tail([{
+ scriptName: "agt_test",
+ outcome: "ok",
+ eventTimestamp: Date.parse("2026-07-13T20:00:00Z"),
+ event: {
+ request: { method: "POST", url: "https://dispatch.test/agents/example/session" },
+ response: { status: 500 },
+ },
+ logs: [],
+ exceptions: [],
+ }], env, {} as ExecutionContext);
+ } finally {
+ globalThis.fetch = originalFetch;
+ }
+
+ assert.equal(records.length, 1);
+ assert.equal(records[0]?.level, "ERROR");
+ assert.equal(records[0]?.msg, "worker request returned HTTP 500");
+ assert.equal(records[0]?.service, "agt_test");
+ assert.equal(records[0]?.response_status, 500);
+});
+
+test("fails the collector invocation when the durable sink rejects a batch", async () => {
+ const originalFetch = globalThis.fetch;
+ const originalConsoleError = console.error;
+ globalThis.fetch = (async () => new Response(
+ JSON.stringify({ code: 403, message: "not allowed to ingest into dataset" }),
+ { status: 403 },
+ )) as typeof fetch;
+ console.error = () => {};
+
+ try {
+ await assert.rejects(
+ worker.tail([{
+ scriptName: "agt_test",
+ outcome: "exception",
+ eventTimestamp: Date.parse("2026-07-13T20:00:00Z"),
+ logs: [],
+ exceptions: [],
+ }], env, {} as ExecutionContext),
+ /axiom ingest failed status=403/,
+ );
+ } finally {
+ globalThis.fetch = originalFetch;
+ console.error = originalConsoleError;
+ }
+});
diff --git a/cloudflare-workers/log-tail/src/index.ts b/cloudflare-workers/log-tail/src/index.ts
index 6b1e1681..5ff30edf 100644
--- a/cloudflare-workers/log-tail/src/index.ts
+++ b/cloudflare-workers/log-tail/src/index.ts
@@ -104,15 +104,20 @@ export default {
});
}
- // Synthetic record when a request ended in exception/exceededCpu/etc
- // but had no console output — gives us a row to count "failed
- // requests by script" in Axiom without joining streams.
- if (item.outcome !== "ok" && item.logs.length === 0 && item.exceptions.length === 0) {
+ // Synthetic record when a request failed without logging. A Worker can
+ // catch an exception and return 5xx while Cloudflare still reports the
+ // invocation outcome as "ok", so response status is part of the failure
+ // contract too. This keeps silent server errors searchable in Axiom.
+ const responseStatus = item.event?.response?.status;
+ const serverError = typeof responseStatus === "number" && responseStatus >= 500;
+ if ((item.outcome !== "ok" || serverError) && item.logs.length === 0 && item.exceptions.length === 0) {
records.push({
_time: new Date(item.eventTimestamp ?? Date.now()).toISOString(),
time: new Date(item.eventTimestamp ?? Date.now()).toISOString(),
level: "ERROR",
- msg: `worker request ended with outcome=${item.outcome}`,
+ msg: serverError
+ ? `worker request returned HTTP ${responseStatus}`
+ : `worker request ended with outcome=${item.outcome}`,
...baseEnvelope,
});
}
@@ -131,7 +136,12 @@ export default {
});
if (!resp.ok) {
const body = await resp.text().catch(() => "");
- console.error(`axiom ingest failed status=${resp.status} body=${body.slice(0, 200)}`);
+ const message = `axiom ingest failed status=${resp.status} body=${body.slice(0, 200)}`;
+ console.error(message);
+ // The collector has Cloudflare Workers Logs enabled as an independent
+ // fallback. Throwing makes a broken durable sink an observable failed
+ // invocation instead of an apparently healthy, lossy success.
+ throw new Error(message);
}
},
};
diff --git a/cloudflare-workers/log-tail/wrangler.prod.toml b/cloudflare-workers/log-tail/wrangler.prod.toml
index f89c09a0..b133c5fb 100644
--- a/cloudflare-workers/log-tail/wrangler.prod.toml
+++ b/cloudflare-workers/log-tail/wrangler.prod.toml
@@ -1,6 +1,6 @@
# log-tail Worker — PROD on Mo's CF account.
# Tail consumer for opencomputer-edge-prod + opencomputer-events-ingest-prod.
-# Forwards console output + exceptions to Axiom dataset cf-prod.
+# Forwards console output + exceptions to Axiom dataset oc-platform-edge.
# Deploy: `wrangler deploy -c wrangler.prod.toml`
name = "opencomputer-log-tail-prod"
@@ -9,8 +9,18 @@ compatibility_date = "2024-12-01"
account_id = "b8f23cb87a7a6c64040d3134643da448"
workers_dev = false
+# Independent fallback for failures in the Axiom sink itself. Tenant/dispatch
+# logs go to Axiom; collector invocation failures remain searchable in the
+# Cloudflare Observability dashboard even when Axiom is unavailable.
+[observability]
+enabled = true
+
+ [observability.logs]
+ invocation_logs = true
+ head_sampling_rate = 1
+
# Secrets (set via `wrangler secret put --config wrangler.prod.toml`):
-# AXIOM_TOKEN — xaat-... ingest token for the cf-prod dataset
+# AXIOM_TOKEN — ingest-capable token scoped to the oc-platform-edge dataset
[vars]
AXIOM_HOST = "https://api.axiom.co"
AXIOM_DATASET = "oc-platform-edge"