An open-source, faster Devin alternative
TypeScript
api-edge: forward linearConnections; question_stale message; question passthrough tests (work 037, S4)
Igor Zalutskia4235c0b7e86
diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.tsindex 285522eb..4aa4a6ea 100644--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts@@ -3107,6 +3107,9 @@ describe("managed agents proxy", () => {},},],+ linearConnections: [+ { id: "linear", provider: { kind: "linear-agent" } },+ ],memory: [{id: "requirements",@@ -3170,6 +3173,9 @@ describe("managed agents proxy", () => {},},],+ linearConnections: [+ { id: "linear", provider: { kind: "linear-agent" } },+ ],memory: [{id: "requirements",@@ -4084,6 +4090,255 @@ describe("managed agents proxy", () => {});});+ describe("questions", () => {+ const env = {+ OC_MANAGED_AGENTS_SECRET: "test-secret",+ MANAGED_AGENTS_API_URL: "https://managedagents.test",+ };+ const caller = { orgID: "org_test", userID: "user_test" };+ const question = {+ id: "q_turn-1_call-1",+ text: "Ship the small fix or the refactor? Messages typed meanwhile are held.",+ options: [+ { label: "Small fix", value: "small" },+ { label: "Refactor", value: "refactor" },+ ],+ askedAt: "2026-10-02T10:00:00.000Z",+ };++ it("forwards answers on a turn unchanged and maps question_stale to 409", async () => {+ const body = {+ input: "Small fix",+ idempotencyKey: "answer-1",+ answers: question.id,+ };+ const fetchSpy = vi.fn(async () =>+ Response.json(+ { turnId: "turn-2", status: "queued", duplicate: false },+ { status: 202 },+ ),+ );+ vi.stubGlobal("fetch", fetchSpy);+ const response = await proxyManagedAgents(+ new Request(+ "https://app.opencomputer.dev/api/managed-agents/sessions/session-1/turns",+ {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: JSON.stringify(body),+ },+ ),+ env,+ caller,+ "/api/managed-agents",+ );+ expect(response.status).toBe(202);+ const [target, init] = fetchSpy.mock.calls[0] as unknown as [+ URL,+ RequestInit,+ ];+ expect(String(target)).toBe(+ "https://managedagents.test/v1/sessions/session-1/turns",+ );+ expect(await new Response(init.body).text()).toBe(JSON.stringify(body));++ vi.stubGlobal(+ "fetch",+ vi.fn(async () =>+ Response.json(+ {+ error: {+ code: "question_stale",+ message: "question q_old is not the open question",+ accountId: "acct_private",+ },+ },+ { status: 409 },+ ),+ ),+ );+ const stale = await proxyManagedAgents(+ new Request(+ "https://app.opencomputer.dev/api/managed-agents/sessions/session-1/turns",+ {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ ...body, answers: "q_old" }),+ },+ ),+ env,+ caller,+ "/api/managed-agents",+ );+ expect(stale.status).toBe(409);+ expect(await stale.json()).toEqual({+ error: {+ code: "question_stale",+ message:+ "That question is no longer open. Read the session's current question and answer that one.",+ },+ });+ });++ it("passes the open question and a turn's outcome through the session snapshot", async () => {+ vi.stubGlobal(+ "fetch",+ vi.fn(async () =>+ Response.json({+ id: "session-1",+ status: "idle",+ accountId: "acct_private",+ question,+ turns: [+ {+ id: "turn-1",+ input: "Fix the flaky test.",+ mode: "queue",+ status: "completed",+ outcome: "question",+ runtimeId: "runtime_private",+ createdAt: "2026-10-02T09:59:00.000Z",+ updatedAt: "2026-10-02T10:00:00.000Z",+ },+ ],+ createdAt: "2026-10-02T09:59:00.000Z",+ updatedAt: "2026-10-02T10:00:00.000Z",+ }),+ ),+ );+ const response = await proxyManagedAgents(+ new Request(+ "https://app.opencomputer.dev/api/managed-agents/sessions/session-1",+ ),+ env,+ caller,+ "/api/managed-agents",+ );+ expect(response.status).toBe(200);+ expect(await response.json()).toEqual({+ id: "session-1",+ status: "idle",+ question,+ turns: [+ {+ id: "turn-1",+ input: "Fix the flaky test.",+ mode: "queue",+ status: "completed",+ outcome: "question",+ createdAt: "2026-10-02T09:59:00.000Z",+ updatedAt: "2026-10-02T10:00:00.000Z",+ },+ ],+ createdAt: "2026-10-02T09:59:00.000Z",+ updatedAt: "2026-10-02T10:00:00.000Z",+ });++ // A session with no open question answers null, not absent.+ vi.stubGlobal(+ "fetch",+ vi.fn(async () =>+ Response.json({ id: "session-1", status: "idle", question: null }),+ ),+ );+ const closed = await proxyManagedAgents(+ new Request(+ "https://app.opencomputer.dev/api/managed-agents/sessions/session-1",+ ),+ env,+ caller,+ "/api/managed-agents",+ );+ expect(await closed.json()).toEqual({+ id: "session-1",+ status: "idle",+ question: null,+ });+ });++ it("keeps the question events and the asking turn's outcome on public events", async () => {+ const event = (+ seq: number,+ type: string,+ data: Record<string, unknown>,+ ) => ({+ id: `event-${seq}`,+ seq,+ timestamp: "2026-10-02T10:00:00.000Z",+ sessionId: "session-1",+ turnId: seq < 3 ? "turn-1" : "turn-2",+ type,+ data,+ });+ const answer = {+ questionId: question.id,+ text: "Small fix",+ value: "small",+ };+ vi.stubGlobal(+ "fetch",+ vi.fn(async () =>+ Response.json({+ events: [+ event(1, "question.asked", {+ questionId: question.id,+ text: question.text,+ options: question.options,+ }),+ event(2, "turn.completed", {+ outcome: "question",+ questionId: question.id,+ }),+ event(3, "question.answered", {+ questionId: question.id,+ answer,+ accountId: "acct_private",+ }),+ event(4, "question.closed", {+ questionId: "q_turn-2_call-1",+ reason: "replaced",+ }),+ ],+ }),+ ),+ );+ const response = await proxyManagedAgents(+ new Request(+ "https://app.opencomputer.dev/api/managed-agents/sessions/session-1/events?after=0",+ ),+ env,+ caller,+ "/api/managed-agents",+ );+ expect(response.status).toBe(200);+ const { events } = (await response.json()) as {+ events: Array<{ type: string; data: unknown }>;+ };+ expect(events.map(({ type, data }) => ({ type, data }))).toEqual([+ {+ type: "question.asked",+ data: {+ questionId: question.id,+ text: question.text,+ options: question.options,+ },+ },+ {+ type: "turn.completed",+ data: { outcome: "question", questionId: question.id },+ },+ {+ type: "question.answered",+ data: { questionId: question.id, answer },+ },+ {+ type: "question.closed",+ data: { questionId: "q_turn-2_call-1", reason: "replaced" },+ },+ ]);+ });+ });+// Review finding 8 (2026-09-15): the detail route used to strip// reserved-looking keys from every nested object, so an application result// that happened to contain userId, a nested runtimeId or artifact came backdiff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.tsindex 2a7be504..e099ab66 100644--- a/cloudflare-workers/api-edge/src/managed_agents.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.ts@@ -276,6 +276,9 @@ async function publicErrorResponse(upstream: Response): Promise<Response> {backendMessage || "The deployment selects an unavailable model.";} else if (backendCode === "database_not_provisioned") {message = "Redeploy this project to provision its database.";+ } else if (backendCode === "question_stale") {+ message =+ "That question is no longer open. Read the session's current question and answer that one.";} else if (backendCode === "destination_verification_failed") {if (backendMessage === "Invite the Slack app to this conversation first"@@ -2386,6 +2389,9 @@ async function deploySourceAgent(githubConnections: Array.isArray(body.githubConnections)? body.githubConnections: [],+ linearConnections: Array.isArray(body.linearConnections)+ ? body.linearConnections+ : [],memory: Array.isArray(body.memory) ? body.memory : [],models,...(body.projectDeployment && typeof body.projectDeployment === "object"