mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-02 10:44:52 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The Runner's credential observer watches an ACPX Codex or Grok session's isolated login and reports refreshes to Core > - The execution host's own copy of the login stays at the token the session started from, so it is spent once the provider rotates its refresh token > - With write-back rules in place (#23339), the observer can return each refresh to a host file the Runner is given > - This pull request has the observer write refreshes back to the file named in `PAPERCLIP_ACPX_AUTH_JSON_FILE` > - The benefit is that a host's login file stays current through every session that uses it ## Linked Issues or Issue Description **Subsystem affected** Paperclip Runner (`runner-core`): the credential observer and the native provider backend's pre-stop poll. **Problem or motivation** A refresh an ACPX Codex or Grok session makes stays in the Runner's isolated home. A host that keeps the login in its own file never receives it, and the next session starts from a token the provider has already rotated. **Proposed solution** When the Runner process names a host file, the observer writes each refresh back to it through the write-back rules, during the session and at close. **Alternatives considered** Write back only once, at session close. Rejected: a long session can refresh several times, and a crash before close would lose every rotated token. **Roadmap alignment** None in `ROADMAP.md`; this extends the Runner's existing credential observer. **Additional context** Builds on #23339. Nothing names a host file until the Runner seeds sessions from one, in the change stacked above this. ## What Changed - With `PAPERCLIP_ACPX_AUTH_JSON_FILE` set, the observer writes each refresh back during the session and at close (the provider's `auth-refresh.json` handoff). Each poll also offers a retained `auth-refresh.json` to the rules even while `auth.json` exists, so a refresh made while an old provider shut down still reaches the host file after a warm `run.attach` or idle restart reseeds the home. Write-back does not wait for an update event's acknowledgement, and a binding without the `observeCredentials` opt-in writes back without emitting events. - The host file seeds the observer's baseline, so a refresh during provider startup is still caught. - A host file that changes during a replacement is decided again at once, up to three times. A kept decision holds only while the host file keeps its stamp, so a repaired or replaced host file is compared again. - A failed write-back, or a host file that keeps changing, fails the poll, and with it the command or turn, with an error that carries no credential. The poll before a stop ignores that failure so the provider still stops; the poll after it reports. - A recovered Runner follows the host file it is given now: it adopts a new one, switches to a changed one, and stops writing back when none is named. Revision, baseline and any pending event are unchanged. - A host file is refused for any session other than an ACPX Codex or Grok one. - Saved observer state gains two optional fields (`host_file`, `silent`), omitted when unset, so existing state loads unchanged. - No code comments are added, per CONTRIBUTING.md. ## Verification - `cargo test -p paperclip-runner-core --lib credential_`: 28 passed. New observer tests cover write-back during the session and at close with and without events; a shutdown refresh written back after a restart reseeds `auth.json`; a failed write-back that fails the poll without the credential in the error and succeeds once the host file is back; a host file repaired after a kept decision receiving the refresh; the binding's path checks, provider checks and seeded baseline; recovery adopting, switching and dropping a host file; and a native Codex home refused. - `cargo test -p paperclip-runner-core --test native_provider_backend`: 47 passed. - `cargo fmt -p paperclip-runner-core -- --check`. - Not run locally: clippy and the full Runner workspace tests. CI runs them. ## Risks - A host file that cannot be written, for example on a full or read-only volume, fails the command or turn that observed it instead of being logged. Such a host is already broken, and failing visibly keeps a rotated refresh token from being lost without notice. - Copies of one sign-in share its refresh token wherever they live. When two copies refresh separately, the later refresh can fail that command or turn, or the provider can revoke the sign-in and the user signs in again. - On non-Unix hosts write-back is unsupported, like the credential observer itself. - No migration. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use (shell, file edits, cargo runs) and extended thinking. ## 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 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Paperclip <noreply@paperclip.ing> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>