Support live Antigravity credential writeback for both token stores (#23397)

## Thinking Path

> - Paperclip manages the connections agents use to work.
> - A run can outlive the Google refresh token that started it.
> - Antigravity writes a rotated token to a private file. Its two
runtimes use different paths and JSON layouts.
> - The task already records which connection supplied its sign-in.
> - Runner reports a rotation on PRP. Core saves it to that connection
if the saved generation still matches.
> - The next run can start with the rotated token.

## Linked Issues or Issue Description

Refs #23395. Refs #23168.

This PR targets `master` and includes the capability-based handler from
#23395. Merging this PR lands the handler and Antigravity writeback
together.

**Current behavior**

A managed Antigravity sign-in reaches the plugin as an environment
credential. Core waits for task retirement to collect a refresh.

**Proposed behavior**

Seed a private auth-file. Observe refresh-token changes for the ordinary
ACP server and the unified CLI. Use the existing credential update event
to save them during execution.

**Reason and benefit**

A long-running task can keep its source connection current across
successive rotations.

## What Changed

- Dispatch PRP credential updates to the live writeback capability
declared for the bound harness and execution target.
- Send Antigravity subscriptions as auth-file credentials to environment
task providers. Keep Gemini API keys and previously admitted environment
credentials on their existing paths.
- Watch the ACP token file and the unified CLI token file. Compare the
refresh token, copy it to the bound file, and emit the existing
secret-free event.
- Bind writeback to the original grant, secret, session epoch, and
credential generation. Save the next generation in the same transaction.

## Verification

- Reproduced the failed final Google save hanging on the next session
close. After commit `2b3e7897cd`, both focused cleanup suites passed (43
tests). The regression covers two overlapping close retries after the
credential home is released and checks that the saved credential is
removed only after persistence succeeds.
- All 21 Rust observer tests passed on both builds. They cover
interruption between the host file and event journal writes, a further
rotation before restart, and a reconnect that supersedes the task.
- On the legacy build, 422 Runner TypeScript tests passed. With the
merged unified CLI on this branch, all 126 tests in the auth, credential
staging, and runtime host suites passed.
- The two plugin writeback database suites passed (39 tests). A refresh
that starts before task stop cannot overwrite the final token after
stop.
- One run timed out in an unrelated process-retirement test. All three
suites passed together on repeat. All OAuth documents in these tests are
fixtures. No live Google sign-in was exercised.

## Risks

- The agent and any process it starts are trusted not to substitute
another account’s refresh token in the harness credential file. Core
accepts the file’s refresh token for the original connection only while
the grant, secret, session epoch, and expected credential generation
still match. Substitution within that boundary is an accepted risk.
[Review
finding](https://github.com/paperclipai/paperclip/pull/23397#discussion_r4759261984)
- Deploy with a plugin and Launcher that support the new auth-file
provider. This branch includes the unified CLI from #23168 and still
observes the legacy token format.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

OpenAI GPT-6 in Codex, with local code execution and GitHub CLI.

## 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>
This commit is contained in:
Nicky LeachandPaperclip authored and GitHub committed 2026-12-02 01:49:46 +00:00
1 parent c47452699a
commit 9092b0c667
34 files changed
+764 -207

No files matched your search

+13 -23
View File
@@ -75,12 +75,11 @@ The `credential` field has one of these types:
| `type` | Contents | Harness |
| --- | --- | --- |
| `auth-file` | `provider` and `content`: the provider's saved sign-in file, as written | `codex` or `grok` |
| `auth-file` | `provider` and `content`: the provider's saved sign-in file, as written | `codex`, `grok`, or `antigravity` |
| `claude-env` | `environment`: exactly one of `CLAUDE_CODE_OAUTH_TOKEN` or `ANTHROPIC_API_KEY` | `claude` |
| `provider-env` | `provider` and `environment`: one complete variable set for that provider | `grok`, `copilot`, `opencode` or `antigravity` |
An `auth-file` credential is the `auth.json` that the provider's sign-in saved:
a Codex subscription or API-key account, or a Grok subscription. Install it as
An `auth-file` carries a saved Codex, Grok, or Google sign-in. Install it as
written in the provider's home. When the provider refreshes it, the `credentials`
operation returns the refreshed copy in the same form, and Core saves it to the
account. `ENVIRONMENT_TASK_AUTH_FILE_PROVIDERS` exports the provider list.
@@ -115,18 +114,12 @@ binding. For `antigravity`, the Runner also removes every other `GOOGLE_*` and
`GEMINI_*` variable before it starts the provider, so a configured variable
cannot redirect the key.
For a Google Antigravity agent bound to a Google sign-in, the
`antigravity` credential carries `PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET`.
Its value is the saved sign-in as a JSON document: the client ID, client
secret, refresh token, token URI, the `scopes` list, and `project_id` when the
account has one. It never contains an access token or the account email. Set it
in the private environment of that task's Runner process only, and name it in
`PAPERCLIP_ACPX_CREDENTIAL_BINDING`. Never put it in a file, a log, a
configured environment, or the environment of another task. The Runner writes
it to `<runtime root>/antigravity-home/antigravity-acp/acp_token.json` (directory
0700, file 0600) and does not pass it to the provider process. When the provider
lease closes, the Runner writes the newest sign-in to `auth-refresh.json` in
the same directory and removes `acp_token.json`. See "Credential writeback".
For a saved Google sign-in, install the canonical OAuth document in a private
task-owned file (mode 0600) and pass its absolute path to Runner in
`PAPERCLIP_ACPX_AUTH_JSON_FILE`. The ACP server uses
`antigravity-acp/acp_token.json`. The unified CLI uses
`antigravity-cli/antigravity-oauth-token`. Runner observes the native file and
writes refresh-token changes back to the bound file before notifying Core.
## Configured environment
@@ -534,14 +527,11 @@ restarted. It uses the existing account comparison and secret service. A
revoked grant, replaced account, or changed session epoch discards the old
refresh.
For a Google sign-in, `credentials` returns the same `provider-env` type with
`provider: "antigravity"` and only `PAPERCLIP_ACPX_ANTIGRAVITY_AUTH_JSON_SECRET`,
set to the contents of the Runner's `auth-refresh.json` (or `acp_token.json`
if the lease has not closed). Core saves it only when the saved connection
still holds the exact sign-in that the task started with, and only after
Google confirms that the refreshed sign-in belongs to the connection's account.
A sign-in for another account is not saved; Core records that in the activity
log.
For a Google sign-in sent as an `auth-file`, return the current private file
with `provider: "antigravity"` on both live and final export. Core accepts a
rotation only while the original grant and saved credential generation still
match. Previously admitted `provider-env` sign-ins retain their stopped export
and Google account verification.
Keep file synchronization and backup outside this API. The provider must retain
recoverable credential state until task completion succeeds.