The Open Framework for Building Agents
test(eve): expect a failed sign-in to stop re-prompting its connector (#4944)
roboeve[bot]c1a6fb10465c
diff --git a/.changeset/refuse-failed-sign-in.md b/.changeset/refuse-failed-sign-in.mdnew file mode 100644index 000000000..269000422--- /dev/null+++ b/.changeset/refuse-failed-sign-in.md@@ -0,0 +1,5 @@+---+"eve": patch+---++A sign-in that fails with `retryable: false` now stops the turn from starting the same sign-in again. A later tool call in the same turn that needs the same grant for the same principal gets that failure back instead of a new `authorization.required`, and the next turn asks again. `authorization.required` and `authorization.completed` now carry `grant` and the connection principal's identity (no attributes), and a `failed` `authorization.completed` carries `retryable`. A failure without `retryable`, from an older eve, is treated as retryable.diff --git a/docs/connections/overview.mdx b/docs/connections/overview.mdxindex 1e452a26d..0067e1039 100644--- a/docs/connections/overview.mdx+++ b/docs/connections/overview.mdx@@ -332,7 +332,7 @@ channels fall back to title-casing the connection name when neither is set.Two error classes drive the consent flow. Throw them from `getToken` or `completeAuthorization`; both are exported from `eve/connections`.- `ConnectionAuthorizationRequiredError(connectionName)`: the user must authorize. Throw it from `getToken` to emit `authorization.required` and kick off the flow.-- `ConnectionAuthorizationFailedError(connectionName, { reason?, retryable? })`: authorization failed. `reason` is a stable machine-readable code (e.g. `"access_denied"`) that shows up on the `authorization.completed` event and the failed tool result. `retryable` defaults to `true`; set it to `false` for terminal cases like user denial so the runtime stops re-prompting.+- `ConnectionAuthorizationFailedError(connectionName, { reason?, retryable? })`: authorization failed. `reason` is a stable machine-readable code (e.g. `"access_denied"`) that shows up on the `authorization.completed` event and the failed tool result. `retryable` defaults to `true`; set it to `false` for terminal cases like user denial. The `authorization.completed` event then carries `retryable: false`, and a later tool call in the same turn that needs the same grant for the same principal fails with that failure instead of asking the user to sign in again. The next turn asks again.```tsimport { ConnectionAuthorizationFailedError } from "eve/connections";diff --git a/packages/eve/extension-contracts/compatibility/channel/v61.ts b/packages/eve/extension-contracts/compatibility/channel/v61.tsnew file mode 100644index 000000000..26150a76c--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/channel/v61.ts@@ -0,0 +1,14 @@+// Epoch 61 of the channel capability: the authoring contract of epoch 60 still compiles.+import { defineChannel } from "#public/channels/index.js";++// Epoch 60 `action.result` errors had no `name`; epoch 61 adds it as optional.+// Channels that read the failure code and message keep working.+export default defineChannel({+ routes: [],+ events: {+ "action.result"(event) {+ if (event.error === undefined) return;+ console.info("action failed", { code: event.error.code, message: event.error.message });+ },+ },+});diff --git a/packages/eve/extension-contracts/compatibility/connection/v50.ts b/packages/eve/extension-contracts/compatibility/connection/v50.tsnew file mode 100644index 000000000..57a8c35db--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/connection/v50.ts@@ -0,0 +1,13 @@+// Epoch 50 of the connection capability: the authoring contract of epoch 49 still compiles.+import { defineMcpClientConnection } from "#public/connections/index.js";++// Epoch 49 Connect providers carry connector metadata without an events bridge.+export default defineMcpClientConnection({+ description: "Read issues from the tracker.",+ url: "https://tracker.example.com/mcp",+ auth: {+ principalType: "app",+ getToken: async () => ({ token: "service-credential" }),+ vercelConnect: { connector: "oauth/issues" },+ },+});diff --git a/packages/eve/extension-contracts/compatibility/dynamicInstructions/v39.ts b/packages/eve/extension-contracts/compatibility/dynamicInstructions/v39.tsnew file mode 100644index 000000000..654050690--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/dynamicInstructions/v39.ts@@ -0,0 +1,10 @@+// Epoch 39 of the dynamicInstructions capability: the authoring contract of epoch 38 still compiles.+import { defineDynamic, defineInstructions } from "#public/instructions/index.js";++// Epoch 38 `action.result` errors had no `name`; epoch 39 adds it as optional.+export default defineDynamic({+ events: {+ "turn.started": (_event, ctx) =>+ defineInstructions({ markdown: `Review evidence for session ${ctx.session.id}.` }),+ },+});diff --git a/packages/eve/extension-contracts/compatibility/dynamicSkill/v38.ts b/packages/eve/extension-contracts/compatibility/dynamicSkill/v38.tsnew file mode 100644index 000000000..e6ce34896--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/dynamicSkill/v38.ts@@ -0,0 +1,13 @@+// Epoch 38 of the dynamicSkill capability: the authoring contract of epoch 37 still compiles.+import { defineDynamic, defineSkill } from "#public/skills/index.js";++// Epoch 37 `action.result` errors had no `name`; epoch 38 adds it as optional.+export default defineDynamic({+ events: {+ "turn.started": (_event, ctx) =>+ defineSkill({+ description: "Review the active request.",+ markdown: `Review evidence for session ${ctx.session.id}.`,+ }),+ },+});diff --git a/packages/eve/extension-contracts/compatibility/dynamicTool/v86.ts b/packages/eve/extension-contracts/compatibility/dynamicTool/v86.tsnew file mode 100644index 000000000..42c925d44--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/dynamicTool/v86.ts@@ -0,0 +1,22 @@+// Epoch 86 of the dynamicTool capability: the authoring contract of epoch 85 still compiles.+import { defineDynamic, defineTool } from "#public/tools/index.js";++// Epoch 85 dynamic tools can use Connect auth without opting into event handling.+export default defineDynamic({+ events: {+ "session.started": () => ({+ authorization: defineTool({+ description: "Check that the issue service is authorized.",+ inputSchema: { type: "object", properties: {}, additionalProperties: false },+ async execute(_input, ctx) {+ const { token } = await ctx.getToken({+ principalType: "app",+ getToken: async () => ({ token: "service-credential" }),+ vercelConnect: { connector: "oauth/issues" },+ });+ return { authorized: token.length > 0 };+ },+ }),+ }),+ },+});diff --git a/packages/eve/extension-contracts/compatibility/hook/v46.ts b/packages/eve/extension-contracts/compatibility/hook/v46.tsnew file mode 100644index 000000000..287b6bb66--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/hook/v46.ts@@ -0,0 +1,14 @@+// Epoch 46 of the hook capability: the authoring contract of epoch 45 still compiles.+import { defineHook } from "#public/hooks/index.js";++// Epoch 45 `action.result` errors had no `name`; epoch 46 adds it as optional.+// Hooks that read the failure code and message keep working.+export default defineHook({+ events: {+ "action.result"(event) {+ const { error } = event.data;+ if (error === undefined) return;+ console.info("action failed", { code: error.code, message: error.message });+ },+ },+});diff --git a/packages/eve/extension-contracts/compatibility/schedule/v33.ts b/packages/eve/extension-contracts/compatibility/schedule/v33.tsnew file mode 100644index 000000000..786c0ef72--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/schedule/v33.ts@@ -0,0 +1,20 @@+// Epoch 33 of the schedule capability: the authoring contract of epoch 32 still compiles.+import { defineChannel } from "#public/channels/index.js";+import { defineSchedule } from "#public/schedules/index.js";++// Epoch 32 `action.result` errors had no `name`; epoch 33 adds it as optional.+const reports = defineChannel({+ routes: [],+ receive(input, { from }) {+ return from("nightly-report").send(input.message, { auth: input.auth });+ },+});++export default defineSchedule({+ cron: "0 2 * * *",+ async run({ to, appAuth, waitUntil }) {+ const session = await to(reports, {}).send("Prepare the nightly report.", { auth: appAuth });+ const events = await session.getEventStream({ startIndex: 0 });+ waitUntil(events.cancel());+ },+});diff --git a/packages/eve/extension-contracts/compatibility/subagent/v38.ts b/packages/eve/extension-contracts/compatibility/subagent/v38.tsnew file mode 100644index 000000000..fc662a5ab--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/subagent/v38.ts@@ -0,0 +1,8 @@+// Epoch 38 of the subagent capability: the authoring contract of epoch 37 still compiles.+import { defineAgent } from "#public/index.js";++// Epoch 37 `action.result` errors had no `name`; epoch 38 adds it as optional.+export default defineAgent({+ description: "Summarize a customer's open support tickets.",+ model: "anthropic/claude-sonnet-5",+});diff --git a/packages/eve/extension-contracts/compatibility/tool/v92.ts b/packages/eve/extension-contracts/compatibility/tool/v92.tsnew file mode 100644index 000000000..30ce6a011--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/tool/v92.ts@@ -0,0 +1,16 @@+// Epoch 92 of the tool capability: the authoring contract of epoch 91 still compiles.+import { defineTool } from "#public/tools/index.js";++// Existing Connect auth providers still work without event support.+export default defineTool({+ description: "Check that the issue service is authorized.",+ inputSchema: { type: "object", properties: {}, additionalProperties: false },+ async execute(_input, ctx) {+ const { token } = await ctx.getToken({+ principalType: "app",+ getToken: async () => ({ token: "service-credential" }),+ vercelConnect: { connector: "oauth/issues" },+ });+ return { authorized: token.length > 0 };+ },+});diff --git a/packages/eve/extension-contracts/reports/channel/v62.json b/packages/eve/extension-contracts/reports/channel/v62.jsonnew file mode 100644index 000000000..a7e348ffc--- /dev/null+++ b/packages/eve/extension-contracts/reports/channel/v62.json@@ -0,0 +1,23 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "channel",+ "epoch": 62,+ "sha256": "f8b2fe832a1108829343d687b1a39311fc458485c3f0c9545e38fcaf400e9e9b",+ "exports": [+ "DELETE",+ "GET",+ "HEAD",+ "OPTIONS",+ "PATCH",+ "POST",+ "PUT",+ "SessionStrandedError",+ "WS",+ "attachmentError",+ "createWebSocketUpgradeServer",+ "defineChannel",+ "disableRoute",+ "isChannel",+ "isDisabledRouteSentinel"+ ]+}diff --git a/packages/eve/extension-contracts/reports/connection/v51.json b/packages/eve/extension-contracts/reports/connection/v51.jsonnew file mode 100644index 000000000..e86a04306--- /dev/null+++ b/packages/eve/extension-contracts/reports/connection/v51.json@@ -0,0 +1,16 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "connection",+ "epoch": 51,+ "sha256": "7d3a25ec8321ef2b2fab7601af916a9a8c7ff18a0130d907a27daa568e6e1a1c",+ "exports": [+ "ConnectionAuthorizationFailedError",+ "ConnectionAuthorizationRequiredError",+ "defineDynamic",+ "defineInteractiveAuthorization",+ "defineMcpClientConnection",+ "defineOpenAPIConnection",+ "isConnectionAuthorizationFailedError",+ "isConnectionAuthorizationRequiredError"+ ]+}diff --git a/packages/eve/extension-contracts/reports/dynamicInstructions/v40.json b/packages/eve/extension-contracts/reports/dynamicInstructions/v40.jsonnew file mode 100644index 000000000..9d11662a5--- /dev/null+++ b/packages/eve/extension-contracts/reports/dynamicInstructions/v40.json@@ -0,0 +1,7 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "dynamicInstructions",+ "epoch": 40,+ "sha256": "7fc773d24c0e90f9f51fcbc6097a40f7175e81bafc58f84a375a397fa4f3a4d9",+ "exports": ["defineDynamic"]+}diff --git a/packages/eve/extension-contracts/reports/dynamicSkill/v39.json b/packages/eve/extension-contracts/reports/dynamicSkill/v39.jsonnew file mode 100644index 000000000..aacc07fc7--- /dev/null+++ b/packages/eve/extension-contracts/reports/dynamicSkill/v39.json@@ -0,0 +1,7 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "dynamicSkill",+ "epoch": 39,+ "sha256": "dce5cc6beda5062ad9fa752147bd6d1cb745ef605f7b97e09f95e2d2e9224c6e",+ "exports": ["defineDynamic"]+}diff --git a/packages/eve/extension-contracts/reports/dynamicTool/v87.json b/packages/eve/extension-contracts/reports/dynamicTool/v87.jsonnew file mode 100644index 000000000..29d300d11--- /dev/null+++ b/packages/eve/extension-contracts/reports/dynamicTool/v87.json@@ -0,0 +1,16 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "dynamicTool",+ "epoch": 87,+ "sha256": "0249d17fc2797179526f30b6ce854f32b26bc2b42972d4a43c43de1d60bdf570",+ "exports": [+ "DynamicToolEntry",+ "DynamicToolEvents",+ "DynamicToolResult",+ "DynamicToolSet",+ "auto",+ "defineDurableCallback",+ "defineDurableSchema",+ "defineDynamic"+ ]+}diff --git a/packages/eve/extension-contracts/reports/hook/v47.json b/packages/eve/extension-contracts/reports/hook/v47.jsonnew file mode 100644index 000000000..78e71477e--- /dev/null+++ b/packages/eve/extension-contracts/reports/hook/v47.json@@ -0,0 +1,7 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "hook",+ "epoch": 47,+ "sha256": "cad2547b2cfcaccdc486f3f3f99e1196564526f41c8ea48117855c7364b502ef",+ "exports": ["defineHook"]+}diff --git a/packages/eve/extension-contracts/reports/schedule/v34.json b/packages/eve/extension-contracts/reports/schedule/v34.jsonnew file mode 100644index 000000000..3deb4f06f--- /dev/null+++ b/packages/eve/extension-contracts/reports/schedule/v34.json@@ -0,0 +1,15 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "schedule",+ "epoch": 34,+ "sha256": "30bc91f27fc75ca8ea1e397f6c7401365f0d92ff4987d3cd3fdd49a79f00c3eb",+ "exports": [+ "ScheduleDefinition",+ "ScheduleHandlerArgs",+ "ScheduleRunHandler",+ "ScheduleToFn",+ "TypedReceiveTarget",+ "defineSchedule",+ "isScheduleAuth"+ ]+}diff --git a/packages/eve/extension-contracts/reports/subagent/v39.json b/packages/eve/extension-contracts/reports/subagent/v39.jsonnew file mode 100644index 000000000..21cd55fc6--- /dev/null+++ b/packages/eve/extension-contracts/reports/subagent/v39.json@@ -0,0 +1,23 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "subagent",+ "epoch": 39,+ "sha256": "a53779d9915ea2158635c6e99dbd16d0439b9ae9a4b579a1c61bd45469d33514",+ "exports": [+ "AgentCompactionDefinition",+ "AgentDefinition",+ "AgentModelDefinition",+ "AgentStaticModelDefinition",+ "DefinedAgent",+ "DynamicLocalSubagentDefinition",+ "DynamicSubagentDefinition",+ "RemoteAgentDefinition",+ "RemoteAgentDefinitionInput",+ "WorkspaceAgentDefinition",+ "WorkspaceAgentTransport",+ "defineAgent",+ "defineDynamic",+ "defineRemoteAgent",+ "defineWorkspaceAgent"+ ]+}diff --git a/packages/eve/extension-contracts/reports/tool/v93.json b/packages/eve/extension-contracts/reports/tool/v93.jsonnew file mode 100644index 000000000..fd5f76adb--- /dev/null+++ b/packages/eve/extension-contracts/reports/tool/v93.json@@ -0,0 +1,29 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "tool",+ "epoch": 93,+ "sha256": "d02ac973797103804dcd1035cf79f799917b49d5c23cecd9b26f1665369a7bd3",+ "exports": [+ "AgentRouterInput",+ "AgentRouterTool",+ "WorkflowStepToolContext",+ "WorkflowTool",+ "WorkflowToolDefinition",+ "WorkflowToolInput",+ "WorkflowToolOptions",+ "agentRouter",+ "decide",+ "defaultWebSearch",+ "defineTool",+ "defineWorkflowTool",+ "disableTool",+ "isDisabledToolSentinel",+ "isWebSearchToolDefinition",+ "serializeModelInputSchema",+ "toolOutput",+ "toolOutputPart",+ "toolResultFrom",+ "webSearch",+ "workflow"+ ]+}diff --git a/packages/eve/src/compiler/extension-compatibility.ts b/packages/eve/src/compiler/extension-compatibility.tsindex 90c33bcaa..f043c43f4 100644--- a/packages/eve/src/compiler/extension-compatibility.ts+++ b/packages/eve/src/compiler/extension-compatibility.ts@@ -22,10 +22,10 @@ interface ExtensionCapabilityContract {const EXTENSION_CAPABILITY_CONTRACTS = {extension: { current: 1, supported: [1], dropped: {} },tool: {- current: 92,+ current: 93,supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 29, 30, 31, 32, 34, 35, 76, 77, 78, 80, 81, 82, 84,- 85, 86, 87, 88, 89, 90, 91, 92,+ 85, 86, 87, 88, 89, 90, 91, 92, 93,],dropped: {14: "TaskExec.delegated was removed; migrate to workflow-backed background tools",@@ -89,11 +89,11 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},dynamicTool: {- current: 86,+ current: 87,supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 31, 32, 33, 52, 54,60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,- 85, 86,+ 85, 86, 87,],dropped: {21: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",@@ -134,10 +134,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},channel: {- current: 61,+ current: 62,supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 29, 31, 36, 37, 38, 39, 40, 41, 42,- 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 61,+ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62,],dropped: {12: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",@@ -160,10 +160,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},schedule: {- current: 33,+ current: 34,supported: [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,- 29, 30, 31, 32, 33,+ 29, 30, 31, 32, 33, 34,],dropped: {5: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",@@ -172,10 +172,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},subagent: {- current: 38,+ current: 39,supported: [3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,- 34, 35, 36, 37, 38,+ 34, 35, 36, 37, 38, 39,],dropped: {1: "Persistent subagent sessions are now the default and the experimental opt-in was removed",@@ -189,10 +189,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},connection: {- current: 50,+ current: 51,supported: [1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 32, 33, 34,- 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50,+ 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51,],dropped: {9: "Dynamic connection resolvers no longer receive conversation or channel continuation data",@@ -208,8 +208,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},hook: {- current: 46,- supported: [20, 21, 22, 23, 25, 27, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46],+ current: 47,+ supported: [+ 20, 21, 22, 23, 25, 27, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47,+ ],dropped: {1: "Model identity moved from session.started runtime metadata to step.started call attribution.",2: "Model identity moved from session.started runtime metadata to step.started call attribution.",@@ -240,10 +242,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},skill: { current: 3, supported: [1, 2, 3], dropped: {} },dynamicSkill: {- current: 38,+ current: 39,supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 25, 26, 27, 28, 29, 30,- 31, 32, 33, 34, 35, 36, 37, 38,+ 31, 32, 33, 34, 35, 36, 37, 38, 39,],dropped: {13: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",@@ -254,10 +256,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},instructions: { current: 2, supported: [1, 2], dropped: {} },dynamicInstructions: {- current: 39,+ current: 40,supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 26, 27, 28, 29, 30,- 31, 32, 33, 34, 35, 36, 37, 38, 39,+ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,],dropped: {14: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",diff --git a/packages/eve/src/execution/session/entry-sign-in-failure.integration.test.ts b/packages/eve/src/execution/session/entry-sign-in-failure.integration.test.tsnew file mode 100644index 000000000..ab4e43191--- /dev/null+++ b/packages/eve/src/execution/session/entry-sign-in-failure.integration.test.ts@@ -0,0 +1,185 @@+import { MockLanguageModelV4 } from "ai/test";+import { describe, expect, it } from "vitest";+import {+ ConnectionAuthorizationFailedError,+ ConnectionAuthorizationRequiredError,+} from "#connections/errors.js";+import { defineDynamic } from "#dynamic/definition.js";+import { workflowEntry } from "#execution/session/entry.js";+import {+ sessionCommandHookToken,+ sessionInboxHookToken,+} from "#execution/session-inbox/address.js";+import { markMockModel } from "#internal/mock-model-identity.js";+import { textStreamResult, toolCallStreamResult } from "#internal/testing/approval-resume.js";+import { createTestRuntime } from "#internal/testing/app-harness.js";+import { buildSerializedContext, captureEvents } from "#internal/testing/entry-test-helpers.js";+import { filterEventsByType } from "#internal/testing/events.js";+import { startSessionOwner } from "#internal/testing/workflow-test-helpers.js";+import { resumeHook } from "#internal/workflow/runtime.js";+import { defineAgent } from "#public/definitions/agent.js";+import type { AuthorizationDefinition } from "#shared/connection-types.js";+import { defineTool } from "#tools/definition.js";++// Calls list_issues, then create_issue, then replies; a second turn calls create_issue again.+const script: readonly ({ readonly tool: string } | { readonly text: string })[] = [+ { tool: "list_issues" },+ { tool: "create_issue" },+ { text: "All done." },+ { tool: "create_issue" },+];+let scriptIndex = 0;+const scriptedModel = markMockModel(+ new MockLanguageModelV4({+ doStream: async () => {+ const next = script[scriptIndex++] ?? { text: "Done." };+ return "text" in next+ ? textStreamResult(next.text)+ : toolCallStreamResult({+ input: "{}",+ toolCallId: `call-${scriptIndex}`,+ toolName: next.tool,+ });+ },+ modelId: "scripted-model",+ provider: "eve-test",+ }),+);++describe("workflowEntry sign-in failure", () => {+ // #4943: after a terminal sign-in failure, create_issue gets that failure, not a fresh sign-in.+ it("does not prompt again for a grant whose sign-in failed with retryable: false", async () => {+ scriptIndex = 0;+ let starts = 0;+ let completes = 0;+ // One Vercel Connect connector shared by two tools; the exchange never yields a token.+ const issuesAuth: AuthorizationDefinition<{ nonce: string }> = {+ principalType: "user",+ vercelConnect: { connector: "oauth/issues" },+ async getToken() {+ throw new ConnectionAuthorizationRequiredError("issues");+ },+ async startAuthorization({ callbackUrl }) {+ starts += 1;+ return {+ challenge: {+ displayName: "Issues",+ url: `https://idp.example/authorize?cb=${callbackUrl}`,+ },+ resume: { nonce: "issues-nonce" },+ };+ },+ async completeAuthorization() {+ completes += 1;+ throw new ConnectionAuthorizationFailedError("issues", {+ message: "Authorization did not complete.",+ reason: "authorization_incomplete",+ retryable: false,+ });+ },+ };+ const issuesTool = (name: string) => ({+ loadNamespace: async () => ({+ default: defineTool({+ description: `Run ${name}.`,+ execute: async (_input, ctx) => ({ token: (await ctx.getToken(issuesAuth)).token }),+ inputSchema: {},+ }),+ }),+ logicalPath: `tools/${name}.ts`,+ });+ const runtime = await createTestRuntime({+ agent: {+ definition: defineAgent({+ model: defineDynamic({+ events: {+ "step.started": () => ({ model: scriptedModel, modelContextWindowTokens: 200_000 }),+ },+ }),+ }),+ name: "workflow-entry-sign-in-failure",+ },+ modules: [issuesTool("list_issues"), issuesTool("create_issue")],+ });++ await runtime.run(async () => {+ const run = await startSessionOwner(workflowEntry, [+ {+ kind: "initial",+ ownerDeploymentId: "dpl_inline",+ input: { message: "List my issues, then create one." },+ serializedContext: buildSerializedContext({+ auth: {+ attributes: {},+ authenticator: "test-idp",+ issuer: "test-idp",+ principalId: "user-1",+ principalType: "user",+ },+ channelKind: "http",+ continuationToken: "http:workflow-entry-sign-in-failure",+ }),+ },+ ]);+ const stream = captureEvents(run);++ try {+ const asked = await stream.nextUntil(+ "first sign-in",+ (event) => event.type === "authorization.required",+ );+ const required = filterEventsByType(asked, "authorization.required")[0]!.data;+ await stream.nextUntil("sign-in hold", (event) => event.type === "turn.waiting");++ await resumeHook(sessionInboxHookToken(sessionCommandHookToken(run.runId)), {+ kind: "authorization-callback",+ payloads: [+ {+ authorizationCallback: {+ attemptId: required.attemptId,+ callback: { method: "GET", params: { code: "oauth-code" } },+ connectionName: required.name,+ },+ },+ ],+ });++ // The exchange failed terminally: create_issue, on the same grant, gets that failure+ // instead of a fresh sign-in, and the turn ends.+ const resumed = await stream.nextUntil(+ "turn after the failed sign-in",+ (event) => event.type === "session.waiting" || event.type === "authorization.required",+ );+ expect(completes).toBe(1);+ expect(filterEventsByType(resumed, "authorization.required")).toEqual([]);+ expect(starts).toBe(1);+ expect(resumed.at(-1)?.type).toBe("session.waiting");+ // The model reads why create_issue didn't run.+ expect(+ filterEventsByType(resumed, "action.result").map(({ data }) => data.result),+ ).toContainEqual(+ expect.objectContaining({+ isError: true,+ output: expect.stringContaining("already failed in this turn"),+ toolName: "create_issue",+ }),+ );++ // The refusal lasts the turn: the next one asks for the sign-in again.+ await resumeHook(sessionInboxHookToken(sessionCommandHookToken(run.runId)), {+ kind: "send",+ payload: { message: "Create one more." },+ });+ const nextTurn = await stream.nextUntil(+ "next turn's sign-in",+ (event) => event.type === "authorization.required",+ );+ expect(filterEventsByType(nextTurn, "authorization.required")).toHaveLength(1);+ expect(starts).toBe(2);+ } finally {+ stream.dispose();+ await run.cancel();+ }+ });+ });+});diff --git a/packages/eve/src/harness/authorization-event-fields.ts b/packages/eve/src/harness/authorization-event-fields.tsindex 7ab2ae588..870c9ed25 100644--- a/packages/eve/src/harness/authorization-event-fields.ts+++ b/packages/eve/src/harness/authorization-event-fields.ts@@ -1,4 +1,6 @@import type { AuthorizationChallenge } from "#harness/authorization.js";+import type { AuthorizationPrincipal } from "#protocol/message.js";+import type { ConnectionPrincipal } from "#shared/connection-types.js";/*** Fields every `authorization.*` event copies from its challenge. Emitters@@ -10,7 +12,20 @@ export function authorizationEventFields(challenge: AuthorizationChallenge) {attemptId: challenge.attemptId,authorization: challenge.challenge,candidateId: challenge.candidateId,+ grant: challenge.grant,name: challenge.name,+ principal: principalIdentity(challenge.principal),principalId: challenge.principalId,};}++/** The connection principal without its attributes, which events don't carry. */+function principalIdentity(+ principal: ConnectionPrincipal | undefined,+): AuthorizationPrincipal | undefined {+ if (principal === undefined) return undefined;+ if (principal.type === "app") return { type: "app" };+ return principal.issuer === undefined+ ? { id: principal.id, type: "user" }+ : { id: principal.id, issuer: principal.issuer, type: "user" };+}diff --git a/packages/eve/src/harness/hitl/approved-calls.ts b/packages/eve/src/harness/hitl/approved-calls.tsindex 2f46d29ca..5181c5283 100644--- a/packages/eve/src/harness/hitl/approved-calls.ts+++ b/packages/eve/src/harness/hitl/approved-calls.ts@@ -96,6 +96,7 @@ export async function runApprovedCalls(input: {...at,outcome: reason === undefined ? "authorized" : "failed",...(reason !== undefined && { reason }),+ ...(isConnectionAuthorizationFailedError(failure) && { retryable: failure.retryable }),}),);}diff --git a/packages/eve/src/harness/hitl/sign-ins.ts b/packages/eve/src/harness/hitl/sign-ins.tsindex 217a35999..0dca7feaa 100644--- a/packages/eve/src/harness/hitl/sign-ins.ts+++ b/packages/eve/src/harness/hitl/sign-ins.ts@@ -1,9 +1,13 @@import type { AuthorizationChallenge } from "#harness/authorization.js";+import type { SessionAuthorization, SessionProjection } from "#protocol/session-projection.js";import type { ConnectionPrincipal } from "#shared/connection-types.js";// Which sign-in attempts replace which. Pure: the session state that holds them is// `requests.ts`'s.+/** What makes two sign-in attempts the same one. */+type SignInIdentity = Pick<AuthorizationChallenge, "candidateId" | "grant" | "name" | "principal">;+/** The pending sign-ins once `challenges` are asked for: each replaces the attempt it supersedes. */export function withSignIns(previous: readonly AuthorizationChallenge[],@@ -34,15 +38,30 @@ export function supersededChallenges();}+/**+ * The sign-in this turn already tried and failed terminally (`retryable: false`) for the same+ * grant and principal as `challenge`: asking again would send the person through the same+ * failure. Calls before the turn's first sign-in failure have nothing to find.+ */+export function terminalSignInFailure(+ projection: SessionProjection,+ challenge: SignInIdentity,+): SessionAuthorization | undefined {+ return Object.values(projection.authorizations).find(+ (attempt) =>+ attempt.status === "failed" &&+ attempt.retryable === false &&+ attempt.turnId === projection.activeTurnId &&+ sameSignIn(attempt, challenge),+ );+}+/*** Same scope, or the same grant from another scope, such as two tools and a* connection that all use one Vercel Connect connector. Approval sign-ins* stay per candidate because each one settles its own approval.*/-function sameSignIn(- left: Pick<AuthorizationChallenge, "candidateId" | "grant" | "name" | "principal">,- right: Pick<AuthorizationChallenge, "candidateId" | "grant" | "name" | "principal">,-): boolean {+function sameSignIn(left: SignInIdentity, right: SignInIdentity): boolean {const sameGrant =left.grant !== undefined &&left.grant === right.grant &&diff --git a/packages/eve/src/harness/session-machine/current.ts b/packages/eve/src/harness/session-machine/current.tsindex 2f3eb0997..875593f95 100644--- a/packages/eve/src/harness/session-machine/current.ts+++ b/packages/eve/src/harness/session-machine/current.ts@@ -35,6 +35,16 @@ export function ensureSessionProjection(if (!liveProjections.has(ctx)) enterSessionProjection(ctx, state);}+/**+ * The current step's projection, or `undefined` outside a session step, such as a workflow-step+ * tool, which runs without one.+ */+export function liveProjection(+ ctx: ContextReader | undefined = contextStorage.getStore(),+): SessionProjection | undefined {+ return ctx === undefined ? undefined : liveProjections.get(ctx)?.projection;+}+/** The projection as of the last event the current step published. */export function currentProjection(ctx: ContextReader | undefined = contextStorage.getStore(),diff --git a/packages/eve/src/protocol/message.ts b/packages/eve/src/protocol/message.tsindex 15073cb6f..1c9edabdd 100644--- a/packages/eve/src/protocol/message.ts+++ b/packages/eve/src/protocol/message.ts@@ -740,6 +740,14 @@ export interface CompactionCompletedStreamEvent {type: "compaction.completed";}+/**+ * Who a sign-in is for: the connection principal's identity. Its `attributes` stay out of+ * events, which reach every client of the stream.+ */+export type AuthorizationPrincipal =+ | { readonly type: "app" }+ | { readonly type: "user"; readonly id: string; readonly issuer?: string };+/*** Stream event emitted when a connection or tool needs user authorization* before it can continue.@@ -751,7 +759,11 @@ export interface AuthorizationRequiredStreamEvent {authorization?: ConnectionAuthorizationChallenge;candidateId?: string;description: string;+ /** The credential the sign-in grants, shared by every scope that uses it. */+ grant?: string;name: string;+ /** The connection principal the sign-in is for. */+ principal?: AuthorizationPrincipal;/*** Session principal that started this sign-in, matching `responderPrincipalId`* on approval events. Channels use it to deliver the challenge privately.@@ -797,11 +809,21 @@ export interface AuthorizationCompletedStreamEvent {* challenge's `displayName` in completion status text.*/authorization?: ConnectionAuthorizationChallenge;+ /** The credential the sign-in grants, as on the matching `authorization.required`. */+ grant?: string;name: string;outcome: AuthorizationOutcome;+ /** The connection principal the sign-in is for, as on the matching `authorization.required`. */+ principal?: AuthorizationPrincipal;/** Session principal that started the matching sign-in. */principalId?: string;reason?: string;+ /**+ * Whether a `failed` sign-in may be started again in the turn. `false` is terminal: the+ * session reports the failure instead. Absent means retryable, as on events from eve+ * versions before it.+ */+ retryable?: boolean;sequence: number;stepIndex: number;/** The task that needed the sign-in, when it comes from a task's run. */@@ -1286,7 +1308,9 @@ export function createAuthorizationRequiredEvent(input: {readonly authorization?: ConnectionAuthorizationChallenge;readonly candidateId?: string;readonly description: string;+ readonly grant?: string;readonly name: string;+ readonly principal?: AuthorizationPrincipal;readonly principalId?: string;readonly sequence: number;readonly stepIndex: number;@@ -1310,6 +1334,12 @@ export function createAuthorizationRequiredEvent(input: {if (input.candidateId !== undefined) {data.candidateId = input.candidateId;}+ if (input.grant !== undefined) {+ data.grant = input.grant;+ }+ if (input.principal !== undefined) {+ data.principal = input.principal;+ }if (input.principalId !== undefined) {data.principalId = input.principalId;}@@ -1334,10 +1364,13 @@ export function createAuthorizationCompletedEvent(input: {readonly attemptId?: string;readonly authorization?: ConnectionAuthorizationChallenge;readonly candidateId?: string;+ readonly grant?: string;readonly name: string;readonly outcome: AuthorizationOutcome;+ readonly principal?: AuthorizationPrincipal;readonly principalId?: string;readonly reason?: string;+ readonly retryable?: boolean;readonly sequence: number;readonly stepIndex: number;readonly taskId?: string;@@ -1359,12 +1392,21 @@ export function createAuthorizationCompletedEvent(input: {if (input.candidateId !== undefined) {data.candidateId = input.candidateId;}+ if (input.grant !== undefined) {+ data.grant = input.grant;+ }+ if (input.principal !== undefined) {+ data.principal = input.principal;+ }if (input.principalId !== undefined) {data.principalId = input.principalId;}if (input.reason !== undefined) {data.reason = input.reason;}+ if (input.retryable !== undefined) {+ data.retryable = input.retryable;+ }if (input.taskId !== undefined) {data.taskId = input.taskId;}diff --git a/packages/eve/src/protocol/session-projection.test.ts b/packages/eve/src/protocol/session-projection.test.tsindex efab57f55..44cccb338 100644--- a/packages/eve/src/protocol/session-projection.test.ts+++ b/packages/eve/src/protocol/session-projection.test.ts@@ -219,4 +219,29 @@ describe("foldSession", () => {expect(callStatus(denied, "call_1")).toBe("rejected");expect(pruneSessionProjection(denied)).toMatchObject({ calls: {}, inputs: {}, turns: {} });});++ it("folds a sign-in's grant and principal, and why and whether its failure may be retried", () => {+ const sameSignIn = {+ attemptId: "attempt_1",+ grant: "oauth/issues",+ name: "issues",+ principal: { id: "user-1", issuer: "idp", type: "user" },+ ...at,+ } as const;+ const projection = fold([+ turnStarted,+ { type: "authorization.required", data: { ...sameSignIn, description: "Sign in." } },+ {+ type: "authorization.completed",+ data: { ...sameSignIn, outcome: "failed", reason: "denied", retryable: false },+ },+ ]);+ expect(projection.authorizations.attempt_1).toMatchObject({+ grant: "oauth/issues",+ principal: { id: "user-1", issuer: "idp", type: "user" },+ reason: "denied",+ retryable: false,+ status: "failed",+ });+ });});diff --git a/packages/eve/src/protocol/session-projection.ts b/packages/eve/src/protocol/session-projection.tsindex e4a997830..27d9ae735 100644--- a/packages/eve/src/protocol/session-projection.ts+++ b/packages/eve/src/protocol/session-projection.ts@@ -2,6 +2,7 @@ import type {ActionResultError,ApprovalCandidateOutcome,AuthorizationOutcome,+ AuthorizationPrincipal,InputResolutionOutcome,UnstampedMessageStreamEvent,} from "#protocol/message.js";@@ -114,7 +115,14 @@ export interface SessionAuthorization {readonly principalId?: string;/** The approval candidate whose responder signs in. */readonly candidateId?: string;+ /** The credential the sign-in grants, which every scope that uses it shares. */+ readonly grant?: string;+ readonly principal?: AuthorizationPrincipal;readonly status: "required" | AuthorizationOutcome;+ /** A `failed` sign-in that reported `retryable: false`: the turn reports it, not asks again. */+ readonly retryable?: boolean;+ /** Why a `failed` sign-in failed, as its completion reported it. */+ readonly reason?: string;/** The sign-in resumes its work through a callback, rather than inline. */readonly awaitsCallback?: true;}@@ -524,13 +532,15 @@ export function foldSession<S extends SessionProjection>(if (typed.data.taskId !== undefined) authorization.taskId = typed.data.taskId;if (typed.data.principalId !== undefined) authorization.principalId = typed.data.principalId;if (typed.data.candidateId !== undefined) authorization.candidateId = typed.data.candidateId;+ if (typed.data.grant !== undefined) authorization.grant = typed.data.grant;+ if (typed.data.principal !== undefined) authorization.principal = typed.data.principal;if (typed.data.webhookUrl !== undefined) authorization.awaitsCallback = true;return { ...state, authorizations: { ...state.authorizations, [attemptId]: authorization } };}case "authorization.completed": {const attemptId = typed.data.attemptId ?? typed.data.name;const current = state.authorizations[attemptId];- const completed: SessionAuthorization = {+ const completed: Mutable<SessionAuthorization> = {...(current ?? {attemptId,name: typed.data.name,@@ -540,6 +550,10 @@ export function foldSession<S extends SessionProjection>(}),status: typed.data.outcome,};+ if (typed.data.grant !== undefined) completed.grant = typed.data.grant;+ if (typed.data.principal !== undefined) completed.principal = typed.data.principal;+ if (typed.data.retryable !== undefined) completed.retryable = typed.data.retryable;+ if (typed.data.reason !== undefined) completed.reason = typed.data.reason;return { ...state, authorizations: { ...state.authorizations, [attemptId]: completed } };}default:diff --git a/packages/eve/src/runtime/connections/scoped-authorization.ts b/packages/eve/src/runtime/connections/scoped-authorization.tsindex 676c9de7e..593df150b 100644--- a/packages/eve/src/runtime/connections/scoped-authorization.ts+++ b/packages/eve/src/runtime/connections/scoped-authorization.ts@@ -36,6 +36,8 @@ import {resolveConnectionPrincipal,resolveConnectionPrincipalFromAuth,} from "#runtime/connections/principal.js";+import { liveProjection } from "#harness/session-machine/current.js";+import { terminalSignInFailure } from "#harness/hitl/sign-ins.js";import { AuthKey, type SessionAuthContext } from "#context/keys.js";import {type AuthorizationDefinition,@@ -178,6 +180,24 @@ export async function handleAuthorizationError(});}+ // A sign-in this turn already failed terminally is reported, not started again.+ const projection = liveProjection();+ const refused =+ projection === undefined+ ? undefined+ : terminalSignInFailure(projection, {+ grant: scoped.authorization.vercelConnect?.connector,+ name: scoped.scope,+ principal: resolveScopedPrincipal(scoped),+ });+ if (refused !== undefined) {+ throw new ConnectionAuthorizationFailedError(scoped.scope, {+ message: `Authorization for "${scoped.scope}" already failed in this turn and can't be retried${refused.reason === undefined ? "." : `: ${refused.reason}`}`,+ ...(refused.reason !== undefined && { reason: refused.reason }),+ retryable: false,+ });+ }+if (options.evictToken) {await evictScopedToken(scoped);}