mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 23:06:17 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Cloud onboarding supports a starter-inference variant
(`free_inference_1`) where the first agent uses Paperclip Cloud's
server-proxied OpenRouter starter key
(`runtimeConfig.cloudTrialInference: true`) before the user connects
their own model provider
> - On Cloud plugin Runner environments, both
`agentHarnessVerificationService` and heartbeat run admission
(`execution-configuration.ts`) rejected `paperclip_runner` agents with
`ai_connection_required` whenever `runtimeConfig.aiConnection` was
absent
> - Because verification failed, the hired first agent stayed stuck in
`status: "paused"` / `lifecycleState: "verifying"` and the first
free-inference chat never executed or replied
> - This pull request allows `cloudTrialInference` agents (with isolated
homes) through plugin Runner verification and run admission, verifying
starter-key eligibility and model restriction via
`prepareCloudTrialRuntime(..., { probeOnly: true })`
> - The benefit is that `free_inference_1` onboarding agents transition
immediately to `ready`/`idle` and execute their first chat turn on
starter inference without requiring a user-managed AI connection
## Linked Issues or Issue Description
Refs #23401
**What happened?**
When a user completes `free_inference_1` onboarding on a Cloud stack
with a plugin Runner environment, the first agent is hired with
`runtimeConfig.cloudTrialInference: true` and no
`runtimeConfig.aiConnection`. Agent harness verification fails with
`ai_connection_required`, leaving the agent stuck in `paused` (`"Agent
setup needs attention"`) so the first chat run sits in `queued` forever.
**What did you expect to happen?**
The starter-trial agent should pass harness verification using Paperclip
Cloud's starter-trial eligibility and key check, transition to `idle`,
and execute its first chat turn via the Cloud trial OpenRouter proxy.
**Steps to reproduce**
1. Enable `free_inference_1` on a Cloud stack backed by a plugin Runner
environment.
2. Complete onboarding and click "Start chatting".
3. Send a message in the first chat; observe the agent remains paused on
`"Agent setup needs attention"`.
## What Changed
- Updated `server/src/services/agent-harness-verification.ts` to
recognize `runtimeConfig.cloudTrialInference: true` on
`paperclip_runner` agents (while still refusing `homeMode:
"preconfigured"` on plugin Runner environments), strip host AI auth env
bindings, and verify starter-key eligibility + model restriction via
`prepareCloudTrialRuntime(..., { probeOnly: true })` + `cleanup()`.
- Updated `server/src/services/heartbeat/execution-configuration.ts` to
allow `cloudTrialInference` agents (when `homeMode` is not
`"preconfigured"`) past the plugin Runner `aiConnection` preflight check
so the first chat run reaches `prepareCloudTrialRuntime`.
- Added optional `probeOnly?: boolean` to `prepareCloudTrialRuntime` in
`server/src/services/cloud-trial-proxy.ts` so verification checks do not
increment `trialRunsCount` telemetry.
- Added a red-green regression test in
`server/src/__tests__/agent-harness-verification-preflight.test.ts`
covering both valid starter-trial verification on a plugin Runner
environment and continued rejection of `homeMode: "preconfigured"`.
## Verification
- Confirmed RED before the fix
(`agent-harness-verification-preflight.test.ts` rejected with
`ai_connection_required`).
- Confirmed GREEN after the fix:
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/agent-harness-verification-preflight.test.ts
src/__tests__/cloud-trial-inference.test.ts` (22/22 passed)
- `pnpm --filter @paperclipai/server typecheck` (0 errors)
## Risks
- Low risk. Scope is restricted to agents with
`runtimeConfig.cloudTrialInference === true` and no `aiConnection`.
Non-trial agents and `homeMode: "preconfigured"` agents keep identical
fail-closed `ai_connection_required` enforcement.
## Model Used
- Google Gemini (Antigravity agentic harness with tool use and code
execution)
## 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
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
76 lines
4.2 KiB
TypeScript
76 lines
4.2 KiB
TypeScript
import type { AdapterEnvironmentTestResult } from "@paperclipai/adapter-utils";
|
|
import type { Db } from "@paperclipai/db";
|
|
import { isAgentUsingCloudTrialInference } from "@paperclipai/shared";
|
|
import { parseEnvironmentDriverConfig } from "./environment-config.js";
|
|
|
|
/**
|
|
* A plugin environment that runs Runner tasks executes only runs with a
|
|
* managed AI connection. The account installed on the provider's machine is
|
|
* not a supported credential source, so Core refuses these runs and setup
|
|
* probes before it leases or calls the provider.
|
|
*/
|
|
export const PLUGIN_RUNNER_AI_CONNECTION_REQUIRED = "ai_connection_required";
|
|
|
|
export const PLUGIN_RUNNER_AI_CONNECTION_REQUIRED_MESSAGE =
|
|
"This agent's environment requires a managed AI connection. Choose an AI connection for this agent in Configuration, then retry.";
|
|
|
|
/** A preconfigured Runner home does not use the agent's AI connection, even when one is saved. */
|
|
export const PLUGIN_RUNNER_ISOLATED_HOME_REQUIRED_MESSAGE =
|
|
"This agent's environment requires a managed AI connection, which a preconfigured Runner home does not use. Switch this agent to an isolated Runner home in Configuration, then retry.";
|
|
|
|
export function pluginRunnerAiConnectionRequiredMessage(preconfiguredHome: boolean) {
|
|
return preconfiguredHome ? PLUGIN_RUNNER_ISOLATED_HOME_REQUIRED_MESSAGE : PLUGIN_RUNNER_AI_CONNECTION_REQUIRED_MESSAGE;
|
|
}
|
|
|
|
/**
|
|
* Shared admission/verification policy for plugin Runner-task environments:
|
|
* a preconfigured Runner home is always refused, and an isolated home requires
|
|
* either a managed AI connection or Cloud starter-trial inference.
|
|
*/
|
|
export function requiresPluginRunnerAiConnection(input: {
|
|
adapterType: string;
|
|
preconfiguredHome: boolean;
|
|
hasAiBinding: boolean;
|
|
runtimeConfig: unknown;
|
|
}): boolean {
|
|
if (input.adapterType !== "paperclip_runner") return false;
|
|
if (input.preconfiguredHome) return true;
|
|
if (input.hasAiBinding) return false;
|
|
return !isAgentUsingCloudTrialInference(input.runtimeConfig);
|
|
}
|
|
|
|
// The plugin's manifest declaration decides whether its environment runs
|
|
// Runner tasks. Run admission separately verifies a ready plugin and a live
|
|
// worker, so a plugin that is down still selects the Runner and fails its run.
|
|
export type PluginRunnerTaskWorkers = { getWorker(pluginId: string): { supportedMethods: readonly string[] } | undefined };
|
|
|
|
export async function pluginEnvironmentRunnerTaskDriver(db: Db, environment: Parameters<typeof parseEnvironmentDriverConfig>[0], workers?: PluginRunnerTaskWorkers) {
|
|
let config: { pluginKey: string; driverKey: string };
|
|
try {
|
|
const parsed = parseEnvironmentDriverConfig(environment);
|
|
if (parsed.driver !== "plugin") return undefined;
|
|
config = parsed.config;
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
const { pluginRegistryService } = await import("./plugin-registry.js");
|
|
const plugin = await pluginRegistryService(db).getByKey(config.pluginKey);
|
|
const driver = plugin?.manifestJson.capabilities.includes("environment.drivers.register")
|
|
? plugin.manifestJson.environmentDrivers?.find(driver => driver.driverKey === config.driverKey && driver.supportsTasks === true) : undefined;
|
|
const methods = driver?.supportedAdapters && plugin ? workers?.getWorker(plugin.id)?.supportedMethods : undefined;
|
|
if (!driver || !methods) return driver;
|
|
const { pluginDriverSupportedAdapters } = await import("./plugin-environment-driver.js");
|
|
return { ...driver, supportedAdapters: pluginDriverSupportedAdapters(driver, methods) };
|
|
}
|
|
|
|
/** The setup probe result for a plugin Runner-task target without a managed AI connection. */
|
|
export function pluginRunnerAiConnectionRequiredTestResult(adapterType: string, preconfiguredHome = false, testedAt = new Date().toISOString()): AdapterEnvironmentTestResult {
|
|
return { adapterType, status: "fail", testedAt, checks: [{ code: PLUGIN_RUNNER_AI_CONNECTION_REQUIRED, level: "error",
|
|
message: pluginRunnerAiConnectionRequiredMessage(preconfiguredHome) }] };
|
|
}
|
|
|
|
/** Lifecycle verification throws this before it resolves a probe target or acquires a lease. */
|
|
export function pluginRunnerAiConnectionRequiredFailure(preconfiguredHome: boolean) {
|
|
return Object.assign(new Error(pluginRunnerAiConnectionRequiredMessage(preconfiguredHome)), { code: PLUGIN_RUNNER_AI_CONNECTION_REQUIRED });
|
|
}
|