Files
PaperClipAI/packages/paperclip-runner/docs/tutorials/codex.md
T
DottaandPaperclip 408f70e69f fix(runner): preserve stock Codex base instructions (#14920)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The native Runner connects Paperclip tasks to Codex app-server.
> - Paperclip passed its runtime context as `baseInstructions`.
> - That field replaces the stock Codex base prompt.
> - This pull request sends the same Paperclip context as additive
developer instructions.
> - Codex keeps its stock prompt and still receives Paperclip task
instructions and tools.

## Linked Issues or Issue Description

**What happened?**

The native Codex driver and Rust provider sent Paperclip context through
`baseInstructions` on thread start and resume. Codex used this text in
place of its stock base instructions. Direct-chat resume also sent an
empty replacement base. The Runner Lab session path used the same
replacement field.

**Expected behavior**

Codex should retain its stock base prompt. Paperclip should add its
runtime context through `developerInstructions`. Other provider facades
should retain their current instruction handling.

**Steps to reproduce**

1. Create a native Codex session through Paperclip Runner.
2. Inspect the `thread/start` request in the native provider trace.
3. Resume the session and inspect `thread/resume`.
4. Before this fix, these paths set `baseInstructions`. After this fix,
the Codex paths set `developerInstructions` and omit `baseInstructions`.

**Paperclip version or commit**

Reproduced against master at `cad26c6bfb736039c8ed5743da650a44792a083c`.

**Deployment mode**

Built from source. Native Codex app-server and runnerd paths. A local
protocol probe used codex-cli 0.153.4 and a localhost Responses stub.

No duplicate fix or matching public issue was found in the GitHub
search.

## What Changed

- Send additive developer instructions on Codex start and resume in the
TypeScript driver, Rust provider, and Runner Lab session path.
- Carry the additive fragment through runnerd, including runtime asset
path mapping.
- Preserve existing instruction fields for other provider facades,
including OpenCode.
- Add start/resume/direct-chat regression coverage and check the actual
Rust provider request.
- Document the historical option and trace field names. Record progress
and follow-ups in the working checklist.

## Verification

- `pnpm -r typecheck` — passed.
- `pnpm build` — passed.
- Targeted Codex driver lifecycle, driver, and live-session Vitest
suites — 139 tests passed.
- `cargo test --manifest-path
packages/paperclip-runner/runner/Cargo.toml --locked -p
paperclip-runner-core --test codex_provider` — 91 passed, 2 ignored
subprocess helpers.
- Real app-server probe: a localhost Responses stub captured identical
14,732-character stock base instructions on fresh start and cold resume.
Both requests retained the Paperclip marker in developer input. Both
stub turns completed. No paid inference was used.
- Runnerd transport Vitest suite — 182 tests passed.
- The initial `pnpm test:run` attempt reported local dependency-loading,
embedded PostgreSQL startup, and macOS `/var` versus `/private/var` path
failures. It was stopped after those failures. Loading-suite reruns
passed 1,428 tests after the build; native interaction/finalization
reruns passed 38 tests. A seven-suite diagnostic rerun passed 463 tests
and isolated the remaining path and PostgreSQL setup failures.
- With `TMPDIR=/private/tmp`, workspace, gateway, interaction, and
attachment suites passed all 356 tests. The remaining environment-image
and native-session-resumption suites passed all 44 tests with the same
canonical temp path. All affected suites passed on rerun. The original
full local command was stopped after failures and is not claimed as
passing.
- All 55 PR checks passed at `83281439456181396f3707eecda5d2ebc90bd14d`.
Greptile scored 5/5 with no open review threads.
- No paid live campaign or Product E2E browser suite was run. This
change has protocol and regression coverage; it does not claim improved
task quality.

## Risks

- Stock Codex behavior may differ from behavior under the previous
Paperclip replacement prompt. Restoring that behavior is the intended
change.
- Existing Codex threads retain their saved replacement base prompt.
They need a provider session reset to receive the stock base. This PR
does not reset active sessions or alter recovery rules.
- The legacy `baseInstructions` option and trace field names remain for
compatibility. They now describe the additive Paperclip fragment for
Codex.
- The separate Codex-through-ACP dependency patch remains a follow-up in
the harness coverage checklist. This PR covers native app-server
execution.

## Model Used

OpenAI Codex, GPT-6. The exact runtime model variant and context window
are not exposed in this session. Used reasoning, repository inspection,
code editing, shell execution, and test tools.

## 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>
2026-10-02 08:53:47 -05:00

6.0 KiB

Codex: Run the Skillless Codex Driver

What this phase is

Codex connects the mock core to a real Codex app-server session.

Codex gets one small task envelope. Codex does not get the Paperclip skill. Codex does not get a Paperclip API key or API instructions.

What this phase proves

This phase proves that a real Codex session can create a file, stream typed events, return one checked result, and replay the same result.

It also proves that steer, interrupt, resume, and unsupported-operation paths keep clear session identities and safe diagnostics.

Before you start

  • Run commands from the repository root.
  • Install Node.js 20+, pnpm 9+, Rust, and the codex CLI.
  • Sign in to Codex with the normal local Codex setup.
  • Do not add a Paperclip or OpenAI API key for this tutorial.

Check the installed harness:

codex --version
codex app-server --help

Run the real-Codex steps from an ordinary operator shell with a workspace that has no AGENTS.md in that directory or any ancestor. A child directory of this repository is not skillless because Codex discovers the repository AGENTS.md. In a Paperclip-managed agent run, PAPERCLIP_WORKSPACE_CWD also prevents mktemp -d from selecting a directory outside the assigned workspace; use a separate clean operator workspace rather than bypassing that guard.

Step 1: Run the focused conformance checks

pnpm --filter @paperclipai/paperclip-runner typecheck:typescript
pnpm --filter @paperclipai/paperclip-runner exec vitest run \
  src/drivers/codex/app-server-transport.test.ts \
  src/drivers/codex/codex-app-server-driver.test.ts
pnpm --filter @paperclipai/paperclip-runner check:forbidden-imports

Confirm that the driver tests pass and the package boundary check says Standalone boundary check passed.

Step 2: Run the safe real Codex task

Choose a temporary directory and trace file:

codex_workspace="$(mktemp -d)"
codex_trace="$codex_workspace/trace.json"
pnpm --filter @paperclipai/paperclip-runner trace:codex -- \
  --working-directory "$codex_workspace" \
  --output "$codex_trace"

Confirm:

  • the result is done;
  • every printed assertion says PASS;
  • the file has the exact text:
test "$(cat "$codex_workspace/hello.txt")" = "hello from Codex runner"

Step 3: Inspect the exact model boundary

Paperclip sends its runtime instructions as additive developerInstructions on Codex thread start and resume. Codex retains its stock base instructions. The historical context.baseInstructions trace field contains the Paperclip fragment, not the full Codex base prompt. The driver option with the same name also supplies this additive fragment.

Threads created before this change retain their saved replacement base prompt when resumed. Reset those provider sessions to apply the stock base instructions; adding developer instructions does not repair an already saved base prompt. This change does not alter session recovery or reset active sessions automatically.

jq '.context | {
  protocolVersion,
  codexVersion,
  model,
  modelProvider,
  workingDirectory,
  sandbox,
  approvalPolicy,
  baseInstructions,
  instructionSources,
  instructionPolicy,
  environmentKeys,
  dynamicToolNames,
  modelInputKinds,
  envelope
}' "$codex_trace"

Confirm:

  • instructionSources is empty;
  • all three instruction-policy values are false;
  • modelInputKinds contains only text;
  • the semantic tools are paperclip_finish and paperclip_block;
  • no environment value is present;
  • the requested permission profile denies root and host-home access, exposes read-only minimal runtime files, grants write access to the assigned workspace, and disables network access;
  • the returned legacy sandbox facts are inspected separately because Codex may add provider-managed state roots such as ~/.codex/memories even when memory instructions are disabled;
  • command HOME and CODEX_HOME are absent;
  • the envelope contains only this safe task and its completion criteria.

Check that no control-plane route or bearer credential appears:

if rg -ni 'authorization: bearer|paperclip_api_key|/api/issues/' "$codex_trace"; then
  echo "FAIL: forbidden control-plane context found"
  exit 1
fi

Step 4: Inspect canonical events and replay

jq '[.events[].eventType] | group_by(.) | map({type: .[0], count: length})' \
  "$codex_trace"
jq '.assertions' "$codex_trace"

Confirm:

  • session and turn lifecycle events exist;
  • model, command/tool, usage, verification, result, and terminal events exist;
  • exactlyOneTerminalResult is true;
  • liveReplayParity is true;
  • source sequence and item identity assertions are true.

The focused test suite supplies deterministic file-change and runtime-request events because a real model may choose a shell command instead of a file patch and may not need human input for this small task.

Step 5: Try steering

Use a new directory:

codex_steer_workspace="$(mktemp -d)"
pnpm --filter @paperclipai/paperclip-runner trace:codex -- \
  --working-directory "$codex_steer_workspace" \
  --steer "Keep the answer short and verify the exact file text."

Confirm that the same driver and provider session IDs are printed and the task still returns one result.

Step 6: Try interruption

Use a new directory:

codex_interrupt_workspace="$(mktemp -d)"
pnpm --filter @paperclipai/paperclip-runner trace:codex -- \
  --working-directory "$codex_interrupt_workspace" \
  --interrupt

An interrupt can win before the file is created. That is expected. Confirm that the trace still has one session identity, one semantic result, and one terminal event. It must not create a replacement session.

Step 7: Run the package verification path

pnpm --filter @paperclipai/paperclip-runner verify

This command is the package acceptance path. The real Codex example remains a separate command because automated environments may not have a signed-in Codex session.

Step 8: Read the driver reference