mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 06:03:51 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Paperclip Runner agents run tasks inside local, sandbox, and plugin task environments. > - Four pre-start failure modes still prevent valid runs from starting or create doomed failing runs before the agent launches. > - A Core-storage project running on a workspace-storage plugin environment can reserve an empty `adapter_managed` workspace on fresh retries or `project_primary` runs and retry in an hourly loop. > - A task reassigned to or reviewed by another agent on the same plugin environment fails with `plugin_workspace_owner_mismatch` because the retained `adapter_managed` workspace still names the previous agent. > - A follow-up wake whose prior plugin task stopped without retained session state fails with `checkpoint_status_unconfirmed`, and sanitized plugin task worker errors drop safe closed-enum operation and RPC codes. > - Non-timer taskless wakes (such as manual Run Heartbeat) still enqueue doomed Runner runs that immediately fail with an ineligible-work-mode message. > - This pull request fixes all four pre-start paths while preserving cross-environment, local-workspace, credential-redaction, and stop-proof invariants. ## Linked Issues or Issue Description Refs #19921, #22849, #19878. **What happened?** Four pre-start failure modes affected Paperclip Runner tasks before the agent started: 1. When a task in a Core-storage project (no `storageProviderPluginId`) ran on a workspace-storage plugin environment with `project_primary` or a fresh continuation retry, `prepareHeartbeatWorkspace` called `reserveFreshPluginTaskWorkspace` before checking project storage compatibility, creating an empty `adapter_managed` workspace and looping on retries. 2. When a task with a retained `adapter_managed` plugin workspace was reassigned to another agent or reviewed by another agent on the same plugin environment, `prepareHeartbeatWorkspace` threw `WorkspaceValidationFailure` (`plugin_workspace_owner_mismatch`). 3. When `executeEnvironmentTask` sanitized worker failures, it discarded safe closed-enum operation and RPC error codes, and when a follow-up run inspected a committed, provably stopped prior plugin task whose provider session state was gone (`executionStopped: true, sessionStateAvailable: false`), `recoverPluginRunnerCheckpoint` failed the run with `checkpoint_status_unconfirmed` instead of retiring the settled root into a fresh session. 4. When a user or caller triggered a non-timer taskless wake (for example `POST /api/agents/:id/heartbeat/invoke` or `/wakeup` without a task) on a `paperclip_runner` agent, `heartbeat.wakeup` still created a run that immediately failed with `"Paperclip Runner requires a standard, planning, ask, or skill test task."` **Expected behavior** 1. Core-storage project sources running on a workspace-storage plugin environment fail early with `configuration_incomplete` (`project_storage_environment_incompatible`) across all workspace strategies and fresh retries without reserving an empty workspace. 2. Reassigned assignees and reviewers on the same plugin environment provision their own agent-owned `adapter_managed` workspace (rebinding `issues.executionWorkspaceId` only for the assignee, leaving the assignee's workspace intact during reviews, and keeping cross-environment and local-workspace ownership guards fail-closed). 3. Sanitized plugin task errors carry closed-enum `pluginTaskError` (`operation`, `errorCode`, `rpcErrorCode`) into `resultJson` without leaking worker text or credentials, and a committed, provably stopped prior plugin task with `executionStopped: true` and `sessionStateAvailable: false` retires cleanly into `continuity-breaks` so the new run starts fresh. 4. Non-timer taskless wakes for `paperclip_runner` agents are skipped cleanly with a `heartbeat.task_required` receipt and `reason: "task_required"` wakeup response instead of creating a failing run, and `resolveNativeRuntimeMode` distinguishes missing-task (`paperclip_runner_task_required`) from wrong work mode (`paperclip_runner_issue_ineligible`). **Steps to reproduce** 1. Run `prepareHeartbeatWorkspace` with a Core-storage project workspace on an active workspace-storage plugin environment during a fresh retry or `project_primary` run. 2. Run `prepareHeartbeatWorkspace` as Agent A on a plugin environment, then reassign or review the task as Agent B on the same plugin environment. 3. Trigger a follow-up replacement run when the prior committed plugin task is stopped (`executionStopped: true`) with `sessionStateAvailable: false`, or throw a `JsonRpcCallError` timeout from a plugin task worker. 4. Call `heartbeat.wakeup` with `source: "on_demand"` and no task scope on a `paperclip_runner` agent. **Paperclip version or commit** Reproduced on `origin/master` at `2d065677959b585065ff3fec8718156a4cf6f41d`. **Deployment mode** Self-hosted / Cloud server. Verified locally on macOS arm64 with embedded PostgreSQL. ## What Changed - `server/src/services/heartbeat/workspace-preparation.ts`: - Check `projectStorageForEnvironment` for Core-storage project sources on workspace-storage plugin environments immediately after `preparePluginWorkspace` and before `reserveFreshPluginTaskWorkspace`, covering `fresh` retries and `project_primary` as well as `git_worktree`. - Detach a foreign agent's `adapter_managed` plugin workspace when a different `paperclip_runner` agent runs on the same plugin environment (not during native restart recovery) so the new agent provisions its own agent-owned workspace cleanly; rebind `issues.executionWorkspaceId` and idle the previous workspace only when `wasIssueAssignee` is true, and leave the assignee's workspace untouched during reviews. - `server/src/services/environment-task-runtime.ts` and `server/src/services/heartbeat/run-completion.ts`: - Attach closed-enum `pluginTaskError` (`operation`, optional `errorCode`, optional `rpcErrorCode`) on sanitized worker errors without forwarding raw worker text or `cause`, and persist it to `resultJson.pluginTaskError` on failed runs. - Attach closed-enum `pluginTaskCheckpointStatus` (`executionStopped`, `sessionStateAvailable`) to `checkpoint_status_unconfirmed` refusals while preserving the exact error message. - `server/src/services/native-runtime/native-session-executor.ts`: - When a replacement/created run hits `checkpoint_status_unconfirmed` with explicit `executionStopped: true` and `sessionStateAvailable: false` on a non-quarantined settled journal, pass `pluginCheckpointUnavailableConfirmed` into `retireFinishedPerTurnRunnerdOwner` / `inspectFinishedPerTurnRunnerdOwner`, verify `remoteExecutionHasStopped` plus all existing committed-owner and controller-stop proofs, and archive the prior root into `continuity-breaks` for a fresh session. Keep unconfirmed stops fail-closed. - `server/src/services/heartbeat-policy.ts`, `server/src/services/heartbeat/queue.ts`, `server/src/routes/agents.ts`, and `server/src/services/native-runtime/runtime-mode.ts`: - Add `supportsUnscopedHeartbeat`, skip non-timer taskless wakes for `paperclip_runner` agents with a `heartbeat.task_required` skipped wakeup receipt, return `reason: "task_required"` in `buildSkippedWakeupResponse`, and separate `paperclip_runner_task_required` from `paperclip_runner_issue_ineligible`. - `doc/project-environment-compatibility.md`: - Update the Core-storage-on-plugin-environment note to reflect early refusal across all workspace strategies and fresh retries. - Tests added across `workspace-preparation.test.ts`, `environment-task-runtime.test.ts`, `environment-task-authority.integration.test.ts`, `run-completion.test.ts`, `native-session-executor.test.ts`, `heartbeat-stale-queue-invalidation.test.ts`, `runtime-mode.test.ts`, and `agent-live-run-routes.test.ts`. - Note on file length: edits touch existing >1,000-line lifecycle/executor modules (`workspace-preparation.ts`, `native-session-executor.ts`, `queue.ts`, `run-completion.ts`, `agents.ts`) with minimal, scoped additions directly at each invariant boundary to avoid churn. ## Verification - **RED (on base `2d065677959b585065ff3fec8718156a4cf6f41d` before production edits):** - Ran the 8 new focused tests across `workspace-preparation.test.ts`, `environment-task-runtime.test.ts`, `run-completion.test.ts`, `native-session-executor.test.ts`, `heartbeat-stale-queue-invalidation.test.ts`, and `runtime-mode.test.ts`: **8 failed | 1 control passed**, confirming every bug reproduced before edits. - **GREEN (on head `9c860ca51c4e9742a6594e12ae160895aab8dbdf`):** - `pnpm --filter @paperclipai/server typecheck` (all 7 layers): **PASS**. - Unit suites (`environment-task-runtime.test.ts`, `runtime-mode.test.ts`, `provider-fresh-workspace.test.ts`, `native-exact-resume-failure.test.ts`): **4/4 files passed** (`100%`). - `native-session-executor.test.ts` (focused plugin checkpoint + unconfirmed checkpoint tests) and `agent-live-run-routes.test.ts` (focused wakeup/invoke/task_required tests): **PASS**. - Real embedded-Postgres integration suites (`environment-task-authority.integration.test.ts` 11/11, `ephemeral-server-data.test.ts` 6/6, `workspace-preparation.test.ts` 18/18 focused plugin/storage/reassignment/fresh-retry tests, `heartbeat-stale-queue-invalidation.test.ts` + `run-completion.test.ts` 8/8 focused tests): **PASS**. - `node scripts/check-test-budget.mjs --files <all 8 modified test files>`: **PASS** (`110 nightly suites validated, 8 test file(s) checked`). - Broad repo-wide verification is supplied by sharded GitHub Actions CI. ## Risks - Low risk. Cross-environment mismatches, local-workspace reuse on plugin environments, and native restart recovery ownership checks remain fail-closed (`plugin_workspace_owner_mismatch`). - Only committed, provably stopped (`remoteExecutionHasStopped` + controller-stop proof + settled journal) prior plugin tasks with explicit provider `executionStopped: true, sessionStateAvailable: false` retire into `continuity-breaks`; unconfirmed stops still fail closed. - Sanitized plugin task errors only expose closed-enum operation, errorCode, and RPC code names; raw worker messages and credentials remain redacted. - No database migrations or schema changes are required. ## Model Used - Google Gemini (Antigravity agentic coding assistant) with tool use, shell execution, and local embedded-PostgreSQL test verification. Exact deployment model ID and context window are not exposed to the session. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
547 lines
21 KiB
TypeScript
547 lines
21 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { BUILTIN_ADAPTER_TYPES } from "../../adapters/builtin-adapter-types.js";
|
|
import {
|
|
NativeRuntimeEligibilityError,
|
|
isRunnerIngressAuthorized,
|
|
resolveHeartbeatNativeRuntimeMode,
|
|
resolveNativeRuntimeMode,
|
|
} from "./runtime-mode.js";
|
|
|
|
const eligible = {
|
|
enabled: true,
|
|
runtimeConfig: {},
|
|
adapterConfig: { provider: "codex" },
|
|
agent: { status: "running", adapterType: "paperclip_runner" },
|
|
issue: { id: "issue", workMode: "standard" },
|
|
target: { kind: "local" },
|
|
workspaceId: "workspace",
|
|
} as const;
|
|
|
|
describe("resolveNativeRuntimeMode", () => {
|
|
it("requires experimental opt-in and a local controller for Cursor Cloud while retaining its backend on recovery", () => {
|
|
const adapterConfig = { provider: "cursor_cloud", model: "caller-model", repoUrl: "https://github.com/acme/repo" };
|
|
expect(resolveNativeRuntimeMode({ ...eligible, adapterConfig })).toMatchObject({ kind: "native", profile: { backend: "cursor_cloud_api" } });
|
|
expect(() => resolveNativeRuntimeMode({ ...eligible, enabled: false, adapterConfig })).toThrow(expect.objectContaining({ code: "paperclip_runner_rollout_disabled" }));
|
|
expect(() => resolveNativeRuntimeMode({ ...eligible, adapterConfig, target: { kind: "remote" } })).toThrow(expect.objectContaining({ code: "paperclip_runner_cursor_cloud_local_controller_required" }));
|
|
expect(resolveHeartbeatNativeRuntimeMode({ ...eligible, enabled: false, adapterConfig, persisted: { runtimeMode: "native", runtimeModeReason: "eligible_opt_in", runtimeModeResolvedAt: new Date(), driverKind: "cursor_cloud_api" } })).toMatchObject({ kind: "native", profile: { backend: "cursor_cloud_api" } });
|
|
});
|
|
it("keeps every direct built-in adapter outside native arbitration", () => {
|
|
for (const adapterType of BUILTIN_ADAPTER_TYPES) {
|
|
if (adapterType === "paperclip_runner") continue;
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
runtimeConfig: {
|
|
nativeRunner: {
|
|
mode: "native",
|
|
backend: "codex_app_server",
|
|
protocolVersion: 1,
|
|
},
|
|
},
|
|
agent: { ...eligible.agent, adapterType },
|
|
})).toEqual({
|
|
kind: "legacy",
|
|
resolverVersion: "phase6-v1",
|
|
reason: "direct_adapter",
|
|
});
|
|
}
|
|
});
|
|
|
|
it("admits fresh native Codex when the experimental rollout is disabled", () => {
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
})).toMatchObject({ kind: "native", profile: { backend: "codex_app_server" } });
|
|
});
|
|
|
|
it("admits saved-token Copilot with the generic Runner rollout disabled", () => {
|
|
expect(resolveNativeRuntimeMode({ ...eligible, enabled: false,
|
|
adapterConfig: { provider: "acpx", acpxAgent: "copilot", model: "gpt-5.6-luna" },
|
|
})).toMatchObject({ kind: "native", profile: { backend: "acpx_runtime" } });
|
|
for (const acpxAgent of ["grok", "cursor", "codex"]) {
|
|
expect(() => resolveNativeRuntimeMode({ ...eligible, enabled: false,
|
|
adapterConfig: { provider: "acpx", acpxAgent, model: "gpt-5.6-luna" },
|
|
})).toThrow(expect.objectContaining({ code: "paperclip_runner_rollout_disabled" }));
|
|
}
|
|
});
|
|
|
|
it.each([
|
|
[false, false],
|
|
[false, true],
|
|
[true, false],
|
|
])("retains the Grok Bot gate with runner enabled=%s and Grok enabled=%s", (enabled, grokEnabled) => {
|
|
expect(() => resolveNativeRuntimeMode({
|
|
...eligible,
|
|
enabled,
|
|
grokEnabled,
|
|
adapterConfig: {
|
|
provider: "grok_bot",
|
|
externalBindingId: "00000000-0000-4000-8000-000000000001",
|
|
allowUnmeteredProvider: true,
|
|
},
|
|
})).toThrow(expect.objectContaining({ code: "paperclip_runner_grok_disabled" }));
|
|
});
|
|
|
|
it("admits a bound Grok Bot when its existing experimental gates are enabled", () => {
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
grokEnabled: true,
|
|
adapterConfig: {
|
|
provider: "grok_bot",
|
|
externalBindingId: "00000000-0000-4000-8000-000000000001",
|
|
allowUnmeteredProvider: true,
|
|
},
|
|
})).toMatchObject({ kind: "native", profile: { backend: "grok_bot_mcp" } });
|
|
});
|
|
|
|
it("admits OpenCode without the experimental flag", () => {
|
|
expect(resolveNativeRuntimeMode({ ...eligible, enabled: false,
|
|
adapterConfig: { provider: "opencode", model: "openrouter/anthropic/claude-sonnet-4.6" },
|
|
})).toMatchObject({ kind: "native", profile: { backend: "opencode_server" } });
|
|
});
|
|
|
|
it("still rejects Grok while the rollout flag is disabled", () => {
|
|
expect(() => resolveNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
adapterConfig: { provider: "acpx", acpxAgent: "grok", model: "openrouter/deepseek/deepseek-v4-flash-0731" },
|
|
})).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_rollout_disabled",
|
|
}));
|
|
});
|
|
|
|
it("admits Pi without the generic rollout flag", () => {
|
|
expect(resolveNativeRuntimeMode({ ...eligible, enabled: false,
|
|
adapterConfig: { provider: "acpx", acpxAgent: "pi", model: "openrouter/anthropic/claude-sonnet-4.6", piThinkingLevel: "max" },
|
|
})).toMatchObject({ kind: "native", profile: { backend: "acpx_runtime" } });
|
|
});
|
|
|
|
it("rejects unknown Paperclip Runner providers", () => {
|
|
expect(() => resolveNativeRuntimeMode({
|
|
...eligible,
|
|
runtimeConfig: {},
|
|
adapterConfig: { provider: "claude" },
|
|
agent: { ...eligible.agent, adapterType: "paperclip_runner" },
|
|
})).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_provider_unsupported",
|
|
}));
|
|
});
|
|
|
|
it("admits fresh local, managed, and qualified ACPX profiles", () => {
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
adapterConfig: { provider: "opencode", model: "openrouter/deepseek/deepseek-v4-flash-0731" },
|
|
})).toMatchObject({
|
|
kind: "native",
|
|
profile: { backend: "opencode_server" },
|
|
});
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
adapterConfig: {
|
|
provider: "claude_managed",
|
|
managedProfileId: "managed-primary",
|
|
managedAgentsRetentionAcknowledged: true,
|
|
},
|
|
})).toMatchObject({
|
|
kind: "native",
|
|
profile: { backend: "claude_managed_agents_api" },
|
|
});
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
adapterConfig: {
|
|
provider: "aws_agentcore",
|
|
agentCoreProfileId: "agentcore-primary",
|
|
agentCoreRetentionAcknowledged: true,
|
|
},
|
|
})).toMatchObject({
|
|
kind: "native",
|
|
profile: { backend: "aws_agentcore_harness_api" },
|
|
});
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
adapterConfig: { provider: "acpx", acpxAgent: "claude", model: "claude-sonnet-5" },
|
|
})).toMatchObject({
|
|
kind: "native",
|
|
profile: { backend: "acpx_runtime" },
|
|
});
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
adapterConfig: { provider: "acpx", acpxAgent: "codex", model: "gpt-5.6-sol" },
|
|
})).toMatchObject({
|
|
kind: "native",
|
|
profile: { backend: "acpx_runtime" },
|
|
});
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
adapterConfig: { provider: "acpx", acpxAgent: "copilot", model: "gpt-5.6-luna" },
|
|
})).toMatchObject({
|
|
kind: "native",
|
|
profile: { backend: "acpx_runtime" },
|
|
});
|
|
});
|
|
|
|
it("rejects malformed OpenCode and unregistered ACPX profiles", () => {
|
|
expect(() => resolveNativeRuntimeMode({
|
|
...eligible,
|
|
adapterConfig: { provider: "opencode", model: "gpt-5.6-sol" },
|
|
})).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_opencode_model_invalid",
|
|
}));
|
|
for (const acpxAgent of ["unregistered-acpx-agent"]) {
|
|
expect(() => resolveNativeRuntimeMode({
|
|
...eligible,
|
|
adapterConfig: { provider: "acpx", acpxAgent, model: "explicit-provider-model" },
|
|
})).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_acpx_agent_unavailable",
|
|
}));
|
|
}
|
|
expect(() => resolveNativeRuntimeMode({
|
|
...eligible,
|
|
adapterConfig: { provider: "acpx", acpxAgent: "claude", model: "claude-opus-5" },
|
|
})).not.toThrow();
|
|
});
|
|
|
|
it("rejects incomplete managed-provider selections before a run is persisted", () => {
|
|
expect(() => resolveNativeRuntimeMode({
|
|
...eligible,
|
|
adapterConfig: {
|
|
provider: "claude_managed",
|
|
managedProfileId: "managed-primary",
|
|
},
|
|
})).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_claude_managed_retention_required",
|
|
}));
|
|
expect(() => resolveNativeRuntimeMode({
|
|
...eligible,
|
|
adapterConfig: {
|
|
provider: "aws_agentcore",
|
|
agentCoreRetentionAcknowledged: true,
|
|
},
|
|
})).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_aws_agentcore_profile_required",
|
|
}));
|
|
});
|
|
|
|
it("distinguishes missing task from ineligible workMode for Paperclip Runner", () => {
|
|
expect(() => resolveNativeRuntimeMode({ ...eligible, issue: null })).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_task_required",
|
|
message: expect.stringContaining("requires a task"),
|
|
}));
|
|
expect(() => resolveNativeRuntimeMode({
|
|
...eligible,
|
|
issue: { id: "issue", workMode: "unsupported_mode" },
|
|
})).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_issue_ineligible",
|
|
message: "Paperclip Runner requires a standard, planning, ask, or skill test task.",
|
|
}));
|
|
});
|
|
|
|
it("uses adapterConfig as the fresh provider authority", () => {
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
runtimeConfig: {
|
|
nativeRunner: { provider: "opencode" },
|
|
},
|
|
adapterConfig: { provider: "codex" },
|
|
})).toMatchObject({
|
|
kind: "native",
|
|
profile: { backend: "codex_app_server" },
|
|
});
|
|
});
|
|
|
|
it("preserves legacy as the default and as the kill-switch behavior", () => {
|
|
const direct = {
|
|
...eligible,
|
|
agent: { ...eligible.agent, adapterType: "codex_local" },
|
|
runtimeConfig: { nativeRunner: { mode: "native", backend: "codex_app_server", protocolVersion: 1 } },
|
|
};
|
|
expect(resolveNativeRuntimeMode(direct)).toEqual(expect.objectContaining({
|
|
kind: "legacy",
|
|
reason: "direct_adapter",
|
|
}));
|
|
expect(resolveNativeRuntimeMode({ ...direct, enabled: false })).toEqual(expect.objectContaining({
|
|
kind: "legacy",
|
|
reason: "direct_adapter",
|
|
}));
|
|
});
|
|
|
|
it("selects native only for an eligible explicit profile", () => {
|
|
expect(resolveNativeRuntimeMode(eligible)).toEqual(expect.objectContaining({
|
|
kind: "native",
|
|
reason: "eligible_opt_in",
|
|
}));
|
|
});
|
|
|
|
it("keeps a persisted experimental run native while the flag rejects a fresh start", () => {
|
|
const disabled = { ...eligible, enabled: false,
|
|
adapterConfig: { provider: "acpx", acpxAgent: "grok", model: "openrouter/deepseek/deepseek-v4-flash-0731" },
|
|
};
|
|
expect(resolveHeartbeatNativeRuntimeMode({
|
|
...disabled,
|
|
persisted: {
|
|
runtimeMode: "native",
|
|
runtimeModeReason: "eligible_opt_in",
|
|
runtimeModeResolvedAt: new Date(),
|
|
driverKind: "acpx_runtime",
|
|
},
|
|
})).toEqual(expect.objectContaining({
|
|
kind: "native",
|
|
reason: "eligible_opt_in",
|
|
authorityDecision: expect.objectContaining({ reasonCode: "live_continuation_registered" }),
|
|
}));
|
|
expect(() => resolveHeartbeatNativeRuntimeMode({
|
|
...disabled,
|
|
persisted: { runtimeMode: null, runtimeModeReason: null, runtimeModeResolvedAt: null },
|
|
})).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_rollout_disabled",
|
|
}));
|
|
});
|
|
|
|
it("authorizes ingress from the native runtime decision without a second flag", () => {
|
|
const freshNative = resolveHeartbeatNativeRuntimeMode({
|
|
...eligible,
|
|
persisted: {
|
|
runtimeMode: null,
|
|
runtimeModeReason: null,
|
|
runtimeModeResolvedAt: null,
|
|
},
|
|
});
|
|
const persistedNative = resolveHeartbeatNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
persisted: {
|
|
runtimeMode: "native",
|
|
runtimeModeReason: "eligible_opt_in",
|
|
runtimeModeResolvedAt: new Date(),
|
|
},
|
|
});
|
|
const directLegacy = resolveHeartbeatNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
agent: { ...eligible.agent, adapterType: "codex_local" },
|
|
persisted: {
|
|
runtimeMode: null,
|
|
runtimeModeReason: null,
|
|
runtimeModeResolvedAt: null,
|
|
},
|
|
});
|
|
|
|
expect(isRunnerIngressAuthorized(freshNative)).toBe(true);
|
|
expect(isRunnerIngressAuthorized(persistedNative)).toBe(true);
|
|
expect(isRunnerIngressAuthorized(directLegacy)).toBe(false);
|
|
});
|
|
|
|
it.each(["paused", "terminated", "pending_approval"])(
|
|
"refuses persisted native recovery for a %s agent",
|
|
(status) => {
|
|
expect(() => resolveHeartbeatNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
agent: { ...eligible.agent, status },
|
|
persisted: {
|
|
runtimeMode: "native",
|
|
runtimeModeReason: "eligible_opt_in",
|
|
runtimeModeResolvedAt: new Date(),
|
|
driverKind: "codex_app_server",
|
|
},
|
|
})).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_agent_ineligible",
|
|
}));
|
|
},
|
|
);
|
|
|
|
it("fails closed for an unknown persisted driver", () => {
|
|
expect(() => resolveHeartbeatNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
persisted: {
|
|
runtimeMode: "native",
|
|
runtimeModeReason: "eligible_opt_in",
|
|
runtimeModeResolvedAt: new Date(),
|
|
driverKind: "unknown_driver",
|
|
},
|
|
})).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_driver_unsupported",
|
|
}));
|
|
});
|
|
|
|
it("does not recover a native run through a direct adapter", () => {
|
|
expect(() => resolveHeartbeatNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
agent: { ...eligible.agent, adapterType: "codex_local" },
|
|
persisted: {
|
|
runtimeMode: "native",
|
|
runtimeModeReason: "eligible_opt_in",
|
|
runtimeModeResolvedAt: new Date(),
|
|
driverKind: "codex_app_server",
|
|
},
|
|
})).toThrow(expect.objectContaining({
|
|
code: "paperclip_runner_adapter_binding_mismatch",
|
|
}));
|
|
});
|
|
|
|
it("keeps a persisted OpenCode recovery on its immutable driver", () => {
|
|
expect(resolveHeartbeatNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
persisted: {
|
|
runtimeMode: "native",
|
|
runtimeModeReason: "eligible_opt_in",
|
|
runtimeModeResolvedAt: new Date(),
|
|
driverKind: "opencode_server",
|
|
},
|
|
})).toEqual(expect.objectContaining({
|
|
profile: { mode: "native", backend: "opencode_server", protocolVersion: 1 },
|
|
}));
|
|
});
|
|
|
|
it.each([
|
|
"claude_managed_agents_api",
|
|
"aws_agentcore_harness_api",
|
|
] as const)("keeps a persisted %s recovery on its immutable driver", (driverKind) => {
|
|
expect(resolveHeartbeatNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
persisted: {
|
|
runtimeMode: "native",
|
|
runtimeModeReason: "eligible_opt_in",
|
|
runtimeModeResolvedAt: new Date(),
|
|
driverKind,
|
|
},
|
|
})).toEqual(expect.objectContaining({
|
|
profile: { mode: "native", backend: driverKind, protocolVersion: 1 },
|
|
}));
|
|
});
|
|
|
|
it("keeps a persisted ACPX recovery even when fresh selection is disabled", () => {
|
|
expect(resolveHeartbeatNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
adapterConfig: {
|
|
provider: "acpx",
|
|
acpxAgent: "pi",
|
|
model: "historical",
|
|
},
|
|
persisted: {
|
|
runtimeMode: "native",
|
|
runtimeModeReason: "eligible_opt_in",
|
|
runtimeModeResolvedAt: new Date(),
|
|
driverKind: "acpx_runtime",
|
|
},
|
|
})).toEqual(expect.objectContaining({
|
|
profile: { mode: "native", backend: "acpx_runtime", protocolVersion: 1 },
|
|
}));
|
|
});
|
|
|
|
it("rejects an explicit native profile outside the approved boundary", () => {
|
|
expect(resolveNativeRuntimeMode({ ...eligible, agent: { ...eligible.agent, adapterType: "claude_local" } }))
|
|
.toEqual(expect.objectContaining({ kind: "legacy", reason: "direct_adapter" }));
|
|
expect(() => resolveNativeRuntimeMode({ ...eligible, issue: { id: "issue", workMode: "unknown" } }))
|
|
.toThrow(NativeRuntimeEligibilityError);
|
|
});
|
|
|
|
it("admits Skills Studio tests on remote Runners", () => {
|
|
expect(resolveNativeRuntimeMode({ ...eligible,
|
|
issue: { id: "skill-test", workMode: "skill_test" }, target: { kind: "remote" },
|
|
})).toMatchObject({ kind: "native", profile: { backend: "codex_app_server" } });
|
|
});
|
|
|
|
it("admits remote targets only through paperclip_runner", () => {
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
target: { kind: "remote" },
|
|
runtimeConfig: {},
|
|
adapterConfig: { provider: "codex" },
|
|
agent: { ...eligible.agent, adapterType: "paperclip_runner" },
|
|
})).toMatchObject({ kind: "native" });
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
target: { kind: "remote" },
|
|
agent: { ...eligible.agent, adapterType: "codex_local" },
|
|
})).toMatchObject({ kind: "legacy", reason: "direct_adapter" });
|
|
});
|
|
|
|
it("allows paperclip_runner to use a transient local workspace for projectless issues", () => {
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
workspaceId: null,
|
|
agent: { ...eligible.agent, adapterType: "paperclip_runner" },
|
|
runtimeConfig: {},
|
|
adapterConfig: { provider: "codex" },
|
|
})).toEqual(expect.objectContaining({ kind: "native" }));
|
|
});
|
|
|
|
it("admits planning only through paperclip_runner", () => {
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
issue: { id: "plan-issue", workMode: "planning" },
|
|
runtimeConfig: {},
|
|
adapterConfig: { provider: "codex" },
|
|
agent: { ...eligible.agent, adapterType: "paperclip_runner" },
|
|
})).toMatchObject({ kind: "native", profile: { backend: "codex_app_server" } });
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
issue: { id: "plan-issue", workMode: "planning" },
|
|
agent: { ...eligible.agent, adapterType: "codex_local" },
|
|
})).toEqual(expect.objectContaining({ kind: "legacy", reason: "direct_adapter" }));
|
|
});
|
|
|
|
it("admits ask mode through paperclip_runner while preserving the legacy native boundary", () => {
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
issue: { id: "ask-issue", workMode: "ask" },
|
|
runtimeConfig: {},
|
|
adapterConfig: { provider: "codex" },
|
|
agent: { ...eligible.agent, adapterType: "paperclip_runner" },
|
|
})).toMatchObject({ kind: "native", profile: { backend: "codex_app_server" } });
|
|
expect(resolveNativeRuntimeMode({
|
|
...eligible,
|
|
issue: { id: "ask-issue", workMode: "ask" },
|
|
agent: { ...eligible.agent, adapterType: "codex_local" },
|
|
})).toEqual(expect.objectContaining({ kind: "legacy", reason: "direct_adapter" }));
|
|
});
|
|
});
|
|
|
|
describe("resolveHeartbeatNativeRuntimeMode", () => {
|
|
it("keeps every direct built-in adapter on the legacy path", () => {
|
|
for (const adapterType of BUILTIN_ADAPTER_TYPES) {
|
|
if (adapterType === "paperclip_runner") continue;
|
|
expect(resolveHeartbeatNativeRuntimeMode({
|
|
...eligible,
|
|
persisted: { runtimeMode: null, runtimeModeReason: null, runtimeModeResolvedAt: null },
|
|
agent: { ...eligible.agent, adapterType },
|
|
})).toMatchObject({ kind: "legacy", reason: "direct_adapter" });
|
|
}
|
|
});
|
|
|
|
it("recovers a persisted Codex run with no recorded driver kind", () => {
|
|
expect(resolveHeartbeatNativeRuntimeMode({
|
|
...eligible,
|
|
enabled: false,
|
|
persisted: { runtimeMode: "native", runtimeModeReason: null, runtimeModeResolvedAt: new Date() },
|
|
})).toMatchObject({ kind: "native", profile: { backend: "codex_app_server" } });
|
|
});
|
|
|
|
it("admits native Claude without enabling other ACPX providers", () => {
|
|
expect(resolveNativeRuntimeMode({ ...eligible, enabled: false, adapterConfig: { provider: "acpx", acpxAgent: "claude" } })).toMatchObject({ kind: "native", profile: { backend: "acpx_runtime" } });
|
|
expect(() => resolveNativeRuntimeMode({ ...eligible, enabled: false, adapterConfig: { provider: "acpx", acpxAgent: "grok" } })).toThrow(expect.objectContaining({ code: "paperclip_runner_rollout_disabled" }));
|
|
});
|
|
});
|
|
|
|
|
|
describe("Muse native selection", () => {
|
|
const muse = { ...eligible, museEnabled: true, adapterConfig: { provider: "muse", museBindingId: "00000000-0000-4000-8000-000000000001", allowUnmeteredProvider: true, lifecycleMode: "per_turn" } };
|
|
it("requires both Runner and Muse rollout gates for fresh work", () => {
|
|
expect(() => resolveNativeRuntimeMode({ ...muse, museEnabled: false })).toThrow("Enable Muse");
|
|
expect(() => resolveNativeRuntimeMode({ ...muse, enabled: false })).toThrow("disabled");
|
|
expect(resolveNativeRuntimeMode(muse)).toMatchObject({ kind: "native", profile: { backend: "muse_external" } });
|
|
});
|
|
it("rejects model, workspace and inherited Dot attachment grants", () => {
|
|
for (const extra of [{ model: "local-model" }, { dotWorkspaceAccess: true }, { dotAttachmentAccess: true }, { lifecycleMode: "warm" }]) {
|
|
expect(() => resolveNativeRuntimeMode({ ...muse, adapterConfig: { ...muse.adapterConfig, ...extra } })).toThrow("Muse requires");
|
|
}
|
|
});
|
|
});
|