Files
PaperClipAI/server
Devin FoleyandPaperclip f23af2e079 Fix user attribution for agent lifecycle verification (#23800)
## Thinking Path

> - Paperclip manages work for AI agents.
> - An agent must pass execution checks before it can run work.
> - Personal AI accounts require the identity of the responsible user.
> - An environment change could start those checks without a user
identity.
> - The manual connection test still passed because it used the
signed-in user.
> - This pull request records the configuring user and repairs missing
identity on an authorized retry.

## Linked Issues or Issue Description

**What happened?**

An agent could pass its manual connection test and stay paused after an
environment change. Background verification had no responsible user and
rejected access to the selected personal AI account. Retry now repeated
the same failure.

**Expected behavior**

Verification started by a configuration change uses the configuring
user. An authorized retry can repair an older operation that has no
responsible user. Existing account sharing and task access checks still
apply.

**Steps to reproduce**

1. Use an agent with a personal AI connection and no saved lifecycle
user or company default responsible user.
2. Move the agent to an environment that requires setup.
3. Run its manual connection test. The test passes under the signed-in
user.
4. Observe failed background verification. Retry now does not repair the
missing identity.

**Paperclip version or commit**

Reproduced on base commit `f0d4f6c3eb2e931f2f7a3e8b426f964aeb54aeee`.

**Deployment mode**

Authenticated hosted server. The local regression uses disposable
PostgreSQL databases on macOS arm64, Node 25.6.1, and pnpm 9.15.4.

## What Changed

- Record the authenticated responsible user when a configuration change
starts a new lifecycle operation. Include the verified human context for
an agent acting on behalf of a user. Keep the prior identity for changes
without that context.
- Pass the authenticated board identity to the existing retry command.
Fill only missing responsibility; preserve an operation's recorded
owner.
- Start a new operation when repairing a missing identity. Repeat the
host check under that identity. A prior attempt cannot complete the
replacement operation.
- Extend the lifecycle owner suites to cover human and delegated
configuration attribution, retry repair, existing owners, active leases,
readiness, and request-body spoofing. The existing board, agent, and
company access checks remain covered.

The lifecycle module owns the repair. Its internal store contract now
accepts the authenticated retry identity. The routes supply those values
after their existing authorization checks. No new API field, migration,
provider policy, or credential permission is added.

## Verification

- Before the fix, focused regressions failed in four cases:
configuration attribution, board retry attribution, and retry identity
repair with and without a lease.
- The three owner suites passed all 141 tests after the fix. The final
retry suite passed all 27 tests, including rejection of a stale host
completion after identity repair.
- Server typechecking passed with `node scripts/typecheck-layers.mjs`
after the Runner and SDK build prerequisites. An initial test-only type
error was corrected with the lifecycle operation type.
- `pnpm verify --explain` returned exit 2 because the internal port type
lies outside the resolved runtime test graph. Required CI will supply
the listed broad typecheck, test, build, and end-to-end coverage. No
full local suite pass is claimed.
- Test budget, module boundaries, runtime push guard, whitespace, and
local secret/PII checks passed.
- CI found one stale mocked retry expectation in
`agent-cross-tenant-authz-routes.test.ts`. It now checks the
authenticated board user as well as the agent ID. All 18 tests in that
suite pass locally. The interrupted native-runner CI job was stopped by
a runner shutdown; the new revision will rerun CI.
- Greptile reviewed the final `e5701b3584a57bbdde269b60439c561acca1f9b1`
revision at 5/5. There are no unresolved review threads.
- GitHub CI passed on `e5701b3584a57bbdde269b60439c561acca1f9b1`: all 68
reported checks are green, including typecheck, build, native Runner,
serialized server, general tests, and end-to-end shards. [CI
run](https://github.com/paperclipai/paperclip/actions/runs/47452634326).
The initial canceled Runner attempt and stale mock failure are
superseded by this successful run.
- Hosted acceptance remains pending deployment of the reviewed revision.
No live provider call is made by the regression tests.

## Risks

- Identity repair does not change credential sharing. Verification still
fails if the responsible user lacks access to the selected account.
- An identity repair starts a replacement operation and fences any old
lease. Existing plugin and host work must pass under that operation
before readiness.
- No schema or migration changes. Background retry behavior without an
explicit user keeps the saved identity.

## Model Used

- OpenAI `gpt-6.1-sol`, through the Codex harness in T3 Code, with xhigh
reasoning and terminal tool access. The harness does not expose the
context-window size.

## 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 16:21:51 -08:00
..