Skip to content

An open-source, faster Devin alternative

TypeScript

feat(agent-feedback): open a Linear issue for each new report

Devin AIf8c327c93330
diff --git a/cloudflare-workers/api-edge/migrations/0008_agent_feedback.sql b/cloudflare-workers/api-edge/migrations/0008_agent_feedback.sql
index b3d78774..4d46e484 100644
--- a/cloudflare-workers/api-edge/migrations/0008_agent_feedback.sql
+++ b/cloudflare-workers/api-edge/migrations/0008_agent_feedback.sql
@@ -30,6 +30,8 @@ CREATE TABLE agent_feedback (
observations INTEGER NOT NULL DEFAULT 1,
quality_score REAL,
duplicate_of TEXT,
+ tracker_issue_id TEXT, -- e.g. Linear identifier (ENG-123) when an issue was opened
+ tracker_issue_url TEXT,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
diff --git a/cloudflare-workers/api-edge/schema-snapshots/current_schema.sql b/cloudflare-workers/api-edge/schema-snapshots/current_schema.sql
index ba3558a2..6a709431 100644
--- a/cloudflare-workers/api-edge/schema-snapshots/current_schema.sql
+++ b/cloudflare-workers/api-edge/schema-snapshots/current_schema.sql
@@ -69,6 +69,8 @@ CREATE TABLE agent_feedback (
observations INTEGER NOT NULL DEFAULT 1,
quality_score REAL,
duplicate_of TEXT,
+ tracker_issue_id TEXT, -- e.g. Linear identifier (ENG-123) when an issue was opened
+ tracker_issue_url TEXT,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
diff --git a/cloudflare-workers/api-edge/src/agent_feedback.test.ts b/cloudflare-workers/api-edge/src/agent_feedback.test.ts
index 26437346..45313818 100644
--- a/cloudflare-workers/api-edge/src/agent_feedback.test.ts
+++ b/cloudflare-workers/api-edge/src/agent_feedback.test.ts
@@ -1,4 +1,4 @@
-import { beforeEach, describe, expect, it } from "vitest";
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
import {
AGENT_FEEDBACK_DISCOVERY_PATH,
handleAgentFeedback,
@@ -393,3 +393,82 @@ describe("triage", () => {
expect((await call(env, "POST", "/api/v1/categories", { name: "bug" }, auth)).status).toBe(400);
});
});
+
+describe("linear tracker hook", () => {
+ const realFetch = globalThis.fetch;
+ let calls: { url: string; init: RequestInit }[];
+ let reply: () => Response;
+
+ beforeEach(() => {
+ calls = [];
+ reply = () =>
+ new Response(JSON.stringify({ data: { issueCreate: { success: true, issue: { id: "uuid-1", identifier: "ENG-42", url: "https://linear.app/acme/issue/ENG-42" } } } }), {
+ status: 200,
+ });
+ globalThis.fetch = (async (url: RequestInfo | URL, init?: RequestInit) => {
+ calls.push({ url: String(url), init: init ?? {} });
+ return reply();
+ }) as typeof fetch;
+ });
+ afterEach(() => {
+ globalThis.fetch = realFetch;
+ });
+
+ it("does nothing when LINEAR_* is unset", async () => {
+ const res = await call(env, "POST", "/api/v1/feedback", validFeedback);
+ expect(res.status).toBe(201);
+ expect(calls).toHaveLength(0);
+ const { receipt } = await res.json() as { receipt: { feedback_id: string } };
+ const detail = await (await call(env, "GET", `/api/v1/feedback/${receipt.feedback_id}`)).json() as { data: Record<string, unknown> };
+ expect(detail.data.tracker).toBeNull();
+ });
+
+ it("opens a Linear issue for a new report and records it; duplicates don't re-file", async () => {
+ env.LINEAR_API_KEY = "lin_api_test";
+ env.LINEAR_TEAM_ID = "team-1";
+ env.LINEAR_PROJECT_ID = "proj-1";
+ const res = await call(env, "POST", "/api/v1/feedback", validFeedback);
+ expect(res.status).toBe(201);
+ expect(calls).toHaveLength(1);
+ expect(calls[0].url).toBe("https://api.linear.app/graphql");
+ expect((calls[0].init.headers as Record<string, string>).authorization).toBe("lin_api_test");
+ const body = JSON.parse(String(calls[0].init.body)) as { variables: { input: Record<string, unknown> } };
+ expect(body.variables.input.teamId).toBe("team-1");
+ expect(body.variables.input.projectId).toBe("proj-1");
+ expect(body.variables.input.priority).toBe(2);
+ expect(body.variables.input.title).toBe("[agent-feedback] create returns 500 when template missing");
+ expect(String(body.variables.input.description)).toContain("POST /api/sandboxes");
+ expect(String(body.variables.input.description)).toContain('{"status":500}');
+
+ const { receipt } = await res.json() as { receipt: { feedback_id: string } };
+ const detail = await (await call(env, "GET", `/api/v1/feedback/${receipt.feedback_id}`)).json() as { data: Record<string, unknown> };
+ expect(detail.data.tracker).toEqual({ provider: "linear", id: "ENG-42", url: "https://linear.app/acme/issue/ENG-42" });
+
+ const dup = await call(env, "POST", "/api/v1/feedback", validFeedback);
+ expect(((await dup.json()) as { receipt: { status: string } }).receipt.status).toBe("duplicate");
+ expect(calls).toHaveLength(1);
+ });
+
+ it("uses Bearer for OAuth tokens and hands the hook to ctx.waitUntil when given", async () => {
+ env.LINEAR_API_KEY = "oauth-token";
+ env.LINEAR_TEAM_ID = "team-1";
+ const pending: Promise<unknown>[] = [];
+ const req = new Request(HOST + "/api/v1/feedback", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(validFeedback) });
+ const res = await handleAgentFeedback(req, env, "/api/v1/feedback", { waitUntil: (p) => void pending.push(p) });
+ expect(res.status).toBe(201);
+ expect(pending).toHaveLength(1);
+ await Promise.all(pending);
+ expect((calls[0].init.headers as Record<string, string>).authorization).toBe("Bearer oauth-token");
+ });
+
+ it("swallows tracker failures so the agent still gets its receipt", async () => {
+ env.LINEAR_API_KEY = "lin_api_test";
+ env.LINEAR_TEAM_ID = "team-1";
+ reply = () => new Response(JSON.stringify({ errors: [{ message: "nope" }] }), { status: 400 });
+ const res = await call(env, "POST", "/api/v1/feedback", validFeedback);
+ expect(res.status).toBe(201);
+ const { receipt } = await res.json() as { receipt: { feedback_id: string } };
+ const detail = await (await call(env, "GET", `/api/v1/feedback/${receipt.feedback_id}`)).json() as { data: Record<string, unknown> };
+ expect(detail.data.tracker).toBeNull();
+ });
+});
diff --git a/cloudflare-workers/api-edge/src/agent_feedback.ts b/cloudflare-workers/api-edge/src/agent_feedback.ts
index de0c3a04..6f26e90d 100644
--- a/cloudflare-workers/api-edge/src/agent_feedback.ts
+++ b/cloudflare-workers/api-edge/src/agent_feedback.ts
@@ -29,10 +29,23 @@
// the submission to an agent identity whose reputation we track. An invalid
// signature is rejected — a present-but-wrong signature is a bug worth
// surfacing, not something to silently downgrade to anonymous.
+//
+// When LINEAR_API_KEY + LINEAR_TEAM_ID are set, every new (non-duplicate)
+// report also opens a Linear issue off the response path; the issue URL is
+// written back onto the row and surfaced as `tracker` on feedback reads.
export interface AgentFeedbackEnv {
OPENCOMPUTER_DB: D1Database;
AGENT_FEEDBACK_TRIAGE_TOKEN?: string;
+ LINEAR_API_KEY?: string;
+ LINEAR_TEAM_ID?: string;
+ LINEAR_PROJECT_ID?: string;
+}
+
+// Minimal slice of Cloudflare's ExecutionContext; optional so tests (and any
+// caller without one) run the tracker hook inline instead.
+export interface AgentFeedbackCtx {
+ waitUntil(promise: Promise<unknown>): void;
}
export const AGENT_FEEDBACK_ROUTE_PREFIX = "/api/v1/";
@@ -470,6 +483,8 @@ interface FeedbackRow {
observations: number;
quality_score: number | null;
duplicate_of: string | null;
+ tracker_issue_id: string | null;
+ tracker_issue_url: string | null;
created_at: number;
updated_at: number;
}
@@ -506,6 +521,7 @@ function feedbackSummary(row: FeedbackRow): Record<string, unknown> {
status: row.status,
quality_score: row.quality_score,
observations: row.observations,
+ tracker: row.tracker_issue_url ? { provider: "linear", id: row.tracker_issue_id, url: row.tracker_issue_url } : null,
created_at: iso(row.created_at),
updated_at: iso(row.updated_at),
};
@@ -568,7 +584,87 @@ async function readJSONBody(req: Request): Promise<{ text: string; body: unknown
}
}
-async function submitFeedback(req: Request, env: AgentFeedbackEnv, path: string): Promise<Response> {
+// ── issue tracker (Linear) ───────────────────────────────────────────────
+
+const LINEAR_GRAPHQL_URL = "https://api.linear.app/graphql";
+// Linear priority: 0 none, 1 urgent, 2 high, 3 normal, 4 low.
+const LINEAR_PRIORITY: Record<Severity, number> = { critical: 1, high: 2, medium: 3, low: 4 };
+
+function linearEnabled(env: AgentFeedbackEnv): boolean {
+ return !!(env.LINEAR_API_KEY && env.LINEAR_TEAM_ID);
+}
+
+function linearDescription(fb: FeedbackIn, feedbackID: string, host: string): string {
+ const lines: string[] = [];
+ if (fb.content.summary) lines.push(fb.content.summary, "");
+ if (fb.content.hypothesis) lines.push("**Hypothesis**", "", fb.content.hypothesis, "");
+ lines.push(
+ "| | |",
+ "|---|---|",
+ `| Surface | \`${fb.subject.surface}\`${fb.subject.kind ? ` (${fb.subject.kind})` : ""} |`,
+ `| Domain | ${fb.subject.domain} |`,
+ `| Category | ${fb.signal.category} |`,
+ `| Severity | ${fb.signal.severity} |`,
+ `| Reproducibility | ${fb.signal.reproducibility ?? "n/a"} |`,
+ `| Confidence | ${fb.signal.confidence} |`,
+ `| Reporter | ${fb.reporter.agent_vendor} / ${fb.reporter.agent_product}${fb.reporter.agent_version ? ` ${fb.reporter.agent_version}` : ""} |`,
+ `| Feedback | [${feedbackID}](https://${host}/api/v1/feedback/${feedbackID}) |`,
+ );
+ for (const e of fb.evidence) {
+ const body = e.redacted ? "_(redacted)_" : "```\n" + e.content.slice(0, 4000) + (e.content.length > 4000 ? "\n…" : "") + "\n```";
+ lines.push("", `**Evidence: ${e.type}**`, "", body);
+ }
+ lines.push("", "_Filed automatically via the feedback.now agent-feedback protocol._");
+ return lines.join("\n");
+}
+
+// Opens a Linear issue for a freshly stored report and records its URL on the
+// row. Never throws: a tracker outage must not fail or delay the agent's 201.
+export async function createLinearIssue(env: AgentFeedbackEnv, fb: FeedbackIn, feedbackID: string, host: string): Promise<void> {
+ if (!linearEnabled(env)) return;
+ try {
+ const key = env.LINEAR_API_KEY!;
+ const input: Record<string, unknown> = {
+ teamId: env.LINEAR_TEAM_ID,
+ title: `[agent-feedback] ${fb.content.title}`.slice(0, 255),
+ description: linearDescription(fb, feedbackID, host),
+ priority: LINEAR_PRIORITY[fb.signal.severity],
+ };
+ if (env.LINEAR_PROJECT_ID) input.projectId = env.LINEAR_PROJECT_ID;
+ const res = await fetch(LINEAR_GRAPHQL_URL, {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ // Personal API keys go bare; OAuth access tokens need the Bearer scheme.
+ authorization: key.startsWith("lin_api_") ? key : `Bearer ${key}`,
+ },
+ body: JSON.stringify({
+ query: "mutation($input: IssueCreateInput!) { issueCreate(input: $input) { success issue { id identifier url } } }",
+ variables: { input },
+ }),
+ });
+ if (!res.ok) {
+ console.warn(`agent_feedback: linear issueCreate HTTP ${res.status} for ${feedbackID}`);
+ return;
+ }
+ const out = (await res.json()) as {
+ data?: { issueCreate?: { success: boolean; issue?: { id: string; identifier: string; url: string } } };
+ errors?: { message: string }[];
+ };
+ const issue = out.data?.issueCreate?.issue;
+ if (!issue || !out.data?.issueCreate?.success) {
+ console.warn(`agent_feedback: linear issueCreate failed for ${feedbackID}: ${out.errors?.map((e) => e.message).join("; ") ?? "no issue"}`);
+ return;
+ }
+ await env.OPENCOMPUTER_DB.prepare("UPDATE agent_feedback SET tracker_issue_id = ?2, tracker_issue_url = ?3 WHERE id = ?1")
+ .bind(feedbackID, issue.identifier, issue.url)
+ .run();
+ } catch (err) {
+ console.warn(`agent_feedback: linear issueCreate threw for ${feedbackID}: ${String(err)}`);
+ }
+}
+
+async function submitFeedback(req: Request, env: AgentFeedbackEnv, path: string, ctx?: AgentFeedbackCtx): Promise<Response> {
const read = await readJSONBody(req);
if (read instanceof Response) return read;
const sig = await verifyAgentSignature(req, path, read.text);
@@ -655,6 +751,12 @@ async function submitFeedback(req: Request, env: AgentFeedbackEnv, path: string)
if (sig.agentKey) stmts.push(bumpAgent(db, sig.agentKey, fb.reporter.agent_vendor, fb.reporter.agent_product, ts));
await db.batch(stmts);
+ if (!existing && linearEnabled(env)) {
+ const hook = createLinearIssue(env, fb, feedbackID, new URL(req.url).host);
+ if (ctx) ctx.waitUntil(hook);
+ else await hook;
+ }
+
return json(
{
receipt: {
@@ -1020,7 +1122,7 @@ export function isAgentFeedbackPath(path: string): boolean {
return path === AGENT_FEEDBACK_DISCOVERY_PATH || path.startsWith(AGENT_FEEDBACK_ROUTE_PREFIX);
}
-export async function handleAgentFeedback(req: Request, env: AgentFeedbackEnv, path: string): Promise<Response> {
+export async function handleAgentFeedback(req: Request, env: AgentFeedbackEnv, path: string, ctx?: AgentFeedbackCtx): Promise<Response> {
const method = req.method.toUpperCase();
if (path === AGENT_FEEDBACK_DISCOVERY_PATH) {
@@ -1041,7 +1143,7 @@ export async function handleAgentFeedback(req: Request, env: AgentFeedbackEnv, p
return submitObservation(req, env, path);
}
if (path === "/api/v1/feedback") {
- if (method === "POST") return submitFeedback(req, env, path);
+ if (method === "POST") return submitFeedback(req, env, path, ctx);
if (method === "GET") return triageAuthorized(req, env) ? listFeedback(req, env) : errorJSON("unauthorized", "triage token required", 401);
return errorJSON("method_not_allowed", "GET or POST", 405);
}
diff --git a/cloudflare-workers/api-edge/src/index.ts b/cloudflare-workers/api-edge/src/index.ts
index b79e36f7..bd30e151 100644
--- a/cloudflare-workers/api-edge/src/index.ts
+++ b/cloudflare-workers/api-edge/src/index.ts
@@ -5027,7 +5027,7 @@ export default {
// /api/* API-key gate (agents submit anonymously) and the SPA asset
// fallthrough (which would otherwise answer /.well-known/* with index.html).
if (isAgentFeedbackPath(path)) {
- return handleAgentFeedback(req, env, path);
+ return handleAgentFeedback(req, env, path, ctx);
}
diff --git a/cloudflare-workers/api-edge/wrangler.prod.toml b/cloudflare-workers/api-edge/wrangler.prod.toml
index 230528bf..41951f28 100644
--- a/cloudflare-workers/api-edge/wrangler.prod.toml
+++ b/cloudflare-workers/api-edge/wrangler.prod.toml
@@ -137,6 +137,9 @@ deleted_classes = ["VmSession"]
# AGENT_FEEDBACK_TRIAGE_TOKEN — bearer token for the feedback.now triage
# routes (src/agent_feedback.ts); submission works
# without it
+# LINEAR_API_KEY / LINEAR_TEAM_ID (+ optional LINEAR_PROJECT_ID var) —
+# when set, each new agent-feedback report opens a
+# Linear issue. Off when unset.
# Optional vars: OPENROUTER_BASE_URL (default https://openrouter.ai/api/v1),
# OPENROUTER_MARKUP_BPS (env-default markup; per-org orgs.model_markup_bps wins).
diff --git a/cloudflare-workers/api-edge/wrangler.toml b/cloudflare-workers/api-edge/wrangler.toml
index d0850541..18637d1a 100644
--- a/cloudflare-workers/api-edge/wrangler.toml
+++ b/cloudflare-workers/api-edge/wrangler.toml
@@ -153,6 +153,9 @@ deleted_classes = ["VmSession"]
# AGENT_FEEDBACK_TRIAGE_TOKEN — bearer token for the feedback.now triage
# routes (src/agent_feedback.ts). Triage is disabled
# while unset; agent submission still works.
+# LINEAR_API_KEY / LINEAR_TEAM_ID (+ optional LINEAR_PROJECT_ID var) —
+# when set, each new agent-feedback report opens a
+# Linear issue. Off when unset.
# The VM-DO exec data plane (VM_SESSIONS DO) needs NO dedicated secret: the worker
# host authenticates its /internal/vms/:id/connect dial with a per-sandbox HMAC
# over the already-shared SESSION_JWT_SECRET (minted by the CP, re-derived here).
diff --git a/docs/api-reference/agent-feedback.mdx b/docs/api-reference/agent-feedback.mdx
index e890f3c2..d68f2ee6 100644
--- a/docs/api-reference/agent-feedback.mdx
+++ b/docs/api-reference/agent-feedback.mdx
@@ -95,6 +95,14 @@ curl -X POST https://app.opencomputer.dev/api/v1/observations \
`feedback_status` (`open`, `accepted`, `resolved`, `wontfix`, `spam`), `quality_score`, and
`duplicate_of` are filled in so an agent can learn whether its report was useful.
+## Issue tracking
+
+Each new (non-duplicate) report is filed as an issue in OpenComputer's issue tracker, with
+severity mapped to issue priority and the evidence included. `GET /api/v1/feedback/{id}` exposes
+the resulting link as `tracker: { "provider": "linear", "id": "ENG-123", "url": "..." }` (or
+`null` while none exists). Duplicate submissions don't open new issues; they add an observation to
+the original report.
+
## Signing (optional)
Anonymous submissions are accepted. Agents that want a persistent identity — and the reputation