Files
PaperClipAI/packages/adapters/codex-local
LakshmananandPaperclip 560201c683 fix(codex-local): prevent quoted auth errors from invalidating connections (#15832)
## Thinking Path

> - Paperclip manages AI agents and their work.
> - The Codex adapter reports provider failures to connection recovery.
> - Connection recovery requests a new login after a refresh-token
failure.
> - The classifier searched the full CLI transcript, including command
output and agent messages.
> - A source review can quote an application error such as "expired
refresh token" before an unrelated provider failure.
> - This pull request limits structured stdout classification to
protocol errors.
> - A quoted application error can no longer invalidate the selected AI
connection.

## Linked Issues or Issue Description

**What happened?**

A Codex CLI agent read application source containing "Invalid or expired
refresh token". Its turn then failed for a separate provider safeguard
reason. Paperclip reported `refresh_token_expired` and asked users of
the shared connection to sign in again.

**Expected behavior**

Keep the original provider failure. Do not invalidate credentials
because command output or an agent message contains an authentication
error. Continue to detect genuine refresh-token failures.

**Steps to reproduce**

1. Include an `item.completed` command result that quotes "Invalid or
expired refresh token" in a Codex JSONL transcript.
2. End the transcript with an `error` and `turn.failed` event for an
unrelated provider failure.
3. Call `classifyCodexAuthRefreshFailure` with the transcript and the
parsed provider error.
4. The previous implementation returns `refresh_token_expired`. The
fixed implementation returns `null` and preserves the provider failure.

The regression tests use synthetic protocol events. No live credentials
or private task logs are included.

**Paperclip version or commit**

Reproduced on `b1ebe3de3c17610573de3e849fc245e2aace7742`. The branch is
based on upstream `master` at
`9ba5569030cc4f37e53906d19e13778c81c99ecc`.

**Deployment mode**

Local development from source, `local_trusted`, Windows, Node.js
24.18.0. The classifier fix applies to Codex CLI execution on other
platforms too.

**Additional context**

I searched public issues and open and closed pull requests for Codex
authentication, quoted output, logout, and refresh classification. I
found no matching report or duplicate implementation. This fix does not
change provider safeguards or token-refresh behavior.

## What Changed

- Reuse the existing JSONL parser to classify the last protocol error
instead of the full structured transcript.
- Retain plain stdout support for failures before protocol startup and
retain process stderr diagnostics.
- Add regressions for quoted errors, real protocol authentication
errors, a later unrelated failure, a process crash, and real stderr
authentication failures.
- Document why quoted application errors do not request a new connection
login.

## Verification

- `pnpm exec vitest run
packages/adapters/codex-local/src/server/parse.test.ts
packages/adapters/codex-local/src/server/execute.auth.test.ts`: 40 tests
passed on this branch.
- `pnpm exec vitest run
packages/adapters/codex-local/src/server/acp.test.ts -t 'classifies ACP
refresh-token auth failures'`: one selected test passed; 45 tests were
not selected.
- `pnpm --filter @paperclipai/adapter-codex-local typecheck`: passed.
- `pnpm --filter @paperclipai/adapter-codex-local build`: passed using
Git Bash for Unix build commands on Windows.
- `git diff --check`: passed.
- Full checks were attempted. `pnpm test:run` stops at `spawnSync pnpm
ENOENT` in the Windows test launcher. `pnpm -r typecheck` and `pnpm
build` stop in unchanged native-runner generated-file checks in this
Windows checkout. The first typecheck also hit a patch-byte hash
mismatch from checkout line endings. Restoring canonical bytes moved it
to the generated-file check. No generated files or patch changes are
included in this PR.
- Greptile reviewed head `10be54bcba8df2f68068daf4bb583c42ae6282ca` and
gave it 5/5 with no findings. All 53 check runs for that head completed
without failures. Linux CI passed full typecheck, build, test shards,
release-registry, native-runner, and browser checks. This PR is ready
for review.

## Risks

- Authentication recovery is sensitive. The tests retain real protocol,
stderr, and pre-protocol stdout failure detection.
- CLI execution still returns the actual failure. The fix does not
suppress a provider refusal or retry around a safeguard.
- No schema, migration, API, permission, credential storage, or
telemetry changes.

## Model Used

OpenAI Codex, a GPT-6-based assistant. The exact runtime model ID,
reasoning setting, and context-window size are not exposed in this
session, so they are not inferred from the separately configured
Paperclip agents. Capabilities used: repository analysis, code editing,
shell execution, and test 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
- [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-12-04 21:28:15 -08:00
..
2026-03-12 13:09:22 -05:00