mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-16 03:31:44 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Codex agents can run inside sandbox environments, and operators can bake a Codex login into the sandbox image during interactive image setup > - Two credential gates (the control plane's pre-dispatch configuration-incomplete gate and the adapter's execute-time fail-fast) required host-side Codex credentials — a usable `auth.json` in the managed home or a configured `OPENAI_API_KEY` — regardless of where the run executes > - On managed cloud hosts a local Codex login never exists, so every sandbox run of a Codex agent failed immediately with "configuration incomplete: no Codex credentials available for managed home …", even though the adapter's inbound auth merge already supports the image-login case end to end > - This pull request makes the execute-time gate probe the sandbox for its own `~/.codex/auth.json` before failing, and exempts sandbox-destined runs from the pre-dispatch host check > - The benefit is that a sandbox image signed in to Codex is a first-class credential source, matching what the auth-merge, precedence-warning, and copy-back machinery were already built for ## Linked Issues or Issue Description **What happened?** Running a `codex_local` agent in a sandbox environment whose image carries a Codex login failed instantly with `configuration incomplete: no Codex credentials available for managed home "…/codex-home". Sign in to Codex on the host with a ChatGPT subscription, or bind a per-agent OPENAI_API_KEY secret for this agent.` The host has no Codex login and never will on a managed cloud deployment; the sandbox's own login was never consulted. **Steps to reproduce** 1. Configure a sandbox environment and capture a custom image after signing in to Codex inside the interactive image setup. 2. Create a `codex_local` agent that uses that environment, on a host with no Codex login and no `OPENAI_API_KEY` bound. 3. Start a run: it fails pre-dispatch with the configuration-incomplete blocker above. **Expected behavior** The run launches and Codex authenticates with the sandbox image's own login, the same way the adapter's host↔sandbox auth merge already keeps the sandbox credential when the host ships none. A run should only fail fast when neither the host, a bound `OPENAI_API_KEY`, nor the sandbox has credentials. **Paperclip version** Current `master` (cloud image deployments). **Deployment mode** Managed cloud stacks (any deployment where the server host has no local Codex login). ## What Changed - Extracted the adapter's execute-time gate into `assertCodexCredentialsLaunchable`: when host readiness fails and the target is a sandbox, it probes `~/.codex/auth.json` in the sandbox (same command the auth-precedence warning uses) and proceeds with a log line naming the credential source; when the sandbox has no login either, the error now names all three remediation options (sandbox image sign-in, per-agent `OPENAI_API_KEY`, host sign-in). Non-sandbox targets keep today's strict behavior byte-for-byte. - The control plane's pre-dispatch gate in `resolveExecutionRunAdapterConfig` now takes the selected environment's driver and skips the host-credential check for sandbox-destined runs — only the adapter can probe the sandbox once it is up, so the execute-time gate is the authority there. Non-sandbox runs keep the early, well-attributed configuration-incomplete blocker. - The codex Test flow needed no change: it already seeds host credentials only when they exist and otherwise leaves the sandbox's `CODEX_HOME` alone; this aligns the run path with it. ## Verification - `cd packages/adapters/codex-local && pnpm vitest run` — 210 tests, including new gate cases: sandbox login present (proceeds + logs source), sandbox and host both credential-less (fails with the extended message), non-sandbox target (strict host requirement kept, no sandbox probe), per-agent API key (no probe at all). - `cd server && pnpm vitest run src/__tests__/heartbeat-project-env.test.ts src/__tests__/codex-local-adapter-environment.test.ts` — includes the new sandbox-exemption case next to the existing blocker tests. - `pnpm run typecheck` in `server` and `packages/adapters/codex-local`. ## Risks - Sandbox-destined misconfigurations (no credentials anywhere) now surface at adapter execute time instead of pre-dispatch, so they read as an adapter failure with a precise message rather than a configuration-incomplete blocker. The trade-off is deliberate: the sandbox must be up to know whether credentials exist, and the failure message names the exact remediations. - The sandbox probe adds one short (5s-capped) shell command to sandbox runs whose host has no credentials; runs with host credentials or a bound key are untouched. - Self-hosted behavior is unchanged for local and SSH targets. ## Model Used Claude Fable 5 (`claude-fable-5`, Anthropic) via Claude Code — extended thinking, agentic tool use (file edits, vitest/tsc runs). No other models involved. ## 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
74 lines
2.3 KiB
Bash
Executable File
74 lines
2.3 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "Usage: codex-auth-merge-extract.sh <asset-dir> <asset-tar>" >&2
|
|
exit 1
|
|
fi
|
|
|
|
asset_dir=$1
|
|
asset_tar=$2
|
|
auth_name=auth.json
|
|
stage_root="$asset_dir.paperclip-extract.$$"
|
|
stage_dir="$stage_root/stage"
|
|
preserve_dir="$stage_root/preserve"
|
|
sandbox_auth="$asset_dir/$auth_name"
|
|
host_auth="$stage_dir/$auth_name"
|
|
preserve_auth="$preserve_dir/$auth_name"
|
|
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P) || exit 1
|
|
decision_script="$script_dir/codex-auth-merge-decision.cjs"
|
|
|
|
cleanup() {
|
|
rm -rf "$stage_root" "$asset_tar"
|
|
}
|
|
trap cleanup EXIT HUP INT TERM
|
|
rm -rf "$stage_root" &&
|
|
mkdir -p "$stage_dir" "$preserve_dir" &&
|
|
tar -xf "$asset_tar" -C "$stage_dir" || exit 1
|
|
|
|
keep_sandbox=0
|
|
if [ -f "$sandbox_auth" ]; then
|
|
if command -v node >/dev/null 2>&1; then
|
|
node "$decision_script" "$sandbox_auth" "$host_auth"
|
|
decision_rc=$?
|
|
if [ "$decision_rc" -eq 10 ]; then
|
|
keep_sandbox=1
|
|
else
|
|
keep_sandbox=0
|
|
fi
|
|
else
|
|
echo "[paperclip] node not found in PATH; cannot evaluate auth-merge decision - aborting sandbox restore" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if [ "$keep_sandbox" -eq 1 ]; then
|
|
if ! ( umask 077 && rm -f "$preserve_auth" && cat "$sandbox_auth" > "$preserve_auth" ); then
|
|
keep_sandbox=0
|
|
fi
|
|
fi
|
|
|
|
rm -rf "$asset_dir" || exit 1
|
|
mkdir -p "$asset_dir" || exit 1
|
|
find "$stage_dir" -mindepth 1 -maxdepth 1 ! -name "$auth_name" -exec mv -f -- {} "$asset_dir/" \; || exit 1
|
|
|
|
source_auth="$host_auth"
|
|
if [ "$keep_sandbox" -eq 1 ] && [ -f "$preserve_auth" ]; then
|
|
source_auth="$preserve_auth"
|
|
fi
|
|
|
|
# When neither the shipped host home nor a preserved prior-lease credential
|
|
# provides auth.json, fall back to the sandbox image's own Codex login so an
|
|
# image signed in to Codex works on hosts with no credentials (managed cloud
|
|
# hosts never have one). Host and preserved credentials always win over the
|
|
# image login, preserving the existing shadowing precedence.
|
|
if [ ! -f "$source_auth" ] && [ -f "${HOME:-/nonexistent}/.codex/$auth_name" ]; then
|
|
source_auth="${HOME:-/nonexistent}/.codex/$auth_name"
|
|
fi
|
|
|
|
if [ -f "$source_auth" ]; then
|
|
target_auth="$asset_dir/$auth_name"
|
|
target_tmp="$asset_dir/.auth.json.paperclip.$$"
|
|
( umask 077 && rm -f "$target_tmp" && cat "$source_auth" > "$target_tmp" ) || exit 1
|
|
mv -f "$target_tmp" "$target_auth" || exit 1
|
|
fi
|