mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-20 18:26:40 +01:00
9874608d0aa66e090ce8ad2b93401fdcebe7b37f
4497
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
9874608d0a |
fix(native): retry a workspace failure write that loses a deadlock (#21507)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The native runtime finalizes each agent run after the provider turn
ends. It copies the workspace back and records the result.
> - When the workspace copy-back fails, `recordRetryableFailure` records
the failure and a bounded export retry in one transaction.
> - That transaction locks the coordinator, issue and run rows. Then the
recovery-action insert takes `FOR KEY SHARE` on the agent row for its
foreign keys.
> - A different transaction that holds the agent row and waits on the
run row deadlocks with it. Postgres aborts the failure write with 40P01.
> - The run then fails with `Database query failed (40P01)`, and the
export retry is never recorded.
> - This pull request runs the whole failure write through the existing
`retryTransientLockContention` helper.
> - The benefit is that a lost deadlock no longer fails the run or drops
its workspace export retry.
## Linked Issues or Issue Description
Refs #21494 (same mechanism, but for the provider-turn failure write in
`native-session-executor.ts`. This PR covers `native-run-finalizer.ts`.)
Refs #21506 (a different agent-row deadlock in run setup. It does not
change this write.)
**What happened?**
On a hosted staging server, two runs finished their provider turn, and
then the workspace copy-back failed. The server tried to record that
failure and lost a Postgres deadlock on `insert into
issue_recovery_actions`. The stack was `recordNativeFinalizationFailure`
-> `recordRetryableFailure` -> `upsertSourceScoped`. Each run failed
with `Database query failed (40P01)`.
**Expected behavior**
A lost deadlock in the failure write is retried. The run records
`retryable_failure` and an active `active_run_watchdog` recovery action
for the bounded workspace export retry.
**Steps to reproduce**
1. Hold `FOR UPDATE` on the agent row in one transaction.
2. Start `recordRetryableFailure` for a run of that agent. It locks the
run and issue rows, then waits on the agent row.
3. In the first transaction, request a lock on the run row. Postgres
detects the deadlock and aborts one side with 40P01.
The new integration test does these steps with embedded Postgres.
**Paperclip version or commit**
`master` at
|
||
|
|
b5c53a996b |
fix(native): stop a repeated startup rejection when a run resumes its predecessor's provider session (#22393)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Native runs on a remote sandbox start a Runner, and the Runner opens
the provider session with `session.open`
> - When the provider refuses `session.open` at startup, no provider
work began. The executor records a startup failure signature, so the
next attempt can stop a repeat of the same refusal (#20874)
> - Only bootstrap retries recorded that signature. A run that continues
its predecessor's provider session (for example a provider-limit Retry)
recovers as an exact checkpoint resume, so it never recorded one
> - Such a run retried every 30 seconds against the same provider rate
limit, spent all 3 attempts, and ended as
`provider_session_open_rejected`. That outcome is reported as a run
failure
> - This pull request records the signature for every remote startup
rejection
> - The benefit is that the second identical refusal ends the run at
once. With #22386, a repeated rate-limit refusal then becomes the
usage-limit hold that retries the task at the reset
## Linked Issues or Issue Description
Refs #22386
Refs #20874
**What happened?**
A staging run resumed its predecessor's provider session. The provider
refused `session.open` with HTTP 429 ("would exceed your account's rate
limit") on each attempt. The recovery mode was
`exact_checkpoint_resume`, so no startup failure signature was saved.
Each attempt looked new. The run made 3 attempts in about 3 minutes and
ended as `provider_session_open_rejected` (retry budget spent).
**Expected behavior**
The second identical startup refusal stops the retries, as it does for a
bootstrap retry. A rate-limit refusal waits for the reset (with #22386)
and does not use the full retry budget.
**Steps to reproduce**
1. Give a remote native run a session checkpoint with an established
provider session.
2. Make the provider refuse `session.open` at startup with the same
error on two attempts, with the runner exit proven.
3. See that the second attempt is retried again, and the run ends only
when the attempt budget is spent.
**Paperclip version or commit**
`master` at
|
||
|
|
7485e01161 |
fix(heartbeat): keep a credential denial an owner action when the lease lapses during AI selection (#22379)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The heartbeat prepares each run before the agent starts. One
preparation step selects the AI account for the run.
> - AI selection can reject an account for a reason that only its owner
can fix. An example is a credential that is not shared with the
responsible user.
> - Run setup gives a lost controller lease priority over every other
failure code. When the lease lapsed during the same setup, the run got
`controller_lease_lost` instead of `configuration_incomplete`.
> - `controller_lease_lost` is retryable. So the run retried and failed
again with the same rejection. The code also bypassed the Sentry filter
for owned AI selection blockers, so the server sent a spurious Sentry
event.
> - This pull request keeps `configuration_incomplete` when AI selection
itself rejected the account, even when the lease is lost at the same
time.
> - The benefit is that the owner gets the correct action at once, with
no wasted retry and no Sentry noise.
## Linked Issues or Issue Description
Refs #15714 (this PR adds the Sentry filter for owned AI selection
blockers, and this change reuses that check).
**What happened?**
A legacy run was in setup. AI selection correctly rejected the account
(`ai_connection_credential_not_shared`). At the same time, a lease
renewal stalled for about 29 seconds and the controller lease lapsed.
Setup recorded the run as `controller_lease_lost` with the configuration
message. The run was retried. The retry failed again as
`configuration_incomplete`. The first failure also went to Sentry,
because the filter only matches `configuration_incomplete`.
**Expected behavior**
When AI selection rejects the account for an owned reason, the run fails
as `configuration_incomplete`. The run is not retried. The board gets
the configuration action. No Sentry event is sent. The run result keeps
the lease-loss evidence.
**Steps to reproduce**
1. Start a legacy run whose AI account selection fails with an owned
rejection (for example, a credential that is not shared with the
responsible user).
2. Make the controller lease lapse while setup selects the AI account.
3. Look at the run `errorCode`, the retry schedule, and the Sentry
report.
**Paperclip version or commit**
`master` at
|
||
|
|
4d954646eb |
fix(native-runtime): refresh a runtime asset lease once for concurrent turns (#22384)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Before a turn starts, the server copies each assigned skill into a
content-addressed runtime asset bundle. Retention garbage collection can
delete old bundles.
> - `withRuntimeAssetUse` keeps a bundle safe from deletion with an
hourly access lease. It records the lease under the same directory
publication lock that deletion uses. The lease is held in memory, so it
is cold after a server restart and again each hour.
> - When the lease is cold, each concurrent turn that uses the same
bundle takes the exclusive lock in sequence and verifies the full bundle
again. One large skill has 1,350 files (24 MB). On a busy server, the
turns at the end of that queue wait more than the 30 s lock budget. The
run then fails with "Timed out waiting for workspace restore lock". The
lock diagnostics show that the same process holds the lock
(`knownLocalHolder: true`).
> - This pull request lets concurrent uses of one digest share one
locked lease refresh.
> - The benefit is that a restart or an hourly lease expiry no longer
makes the preparation of parallel turns fail.
## Linked Issues or Issue Description
No public issue exists. This is the bug description.
**What happened?**
Agent runs on a hosted staging server failed during preparation with
`ERR_WORKSPACE_RESTORE_LOCK_TIMEOUT` ("Timed out waiting for workspace
restore lock at <instance>/locks/directory-merge/<sha256>.lock"). The
stack is `materializeSelectedSkills` (Promise.all) ->
`materializeSkillAsset` -> `withCanonicalDirectoryMergeLock` ->
`acquireDirectoryMergeLock` -> `waitForLock`. The lock diagnostics were
`knownLocalHolder: true` and `waitMs: 30052`, and the owner sidecar read
timed out. The server process had started 48 minutes before the failure.
Eight events occurred in two days. One agent ran many turns in parallel
with the same large skill.
**Expected behavior**
Concurrent turns that use the same runtime asset bundle start without
waiting for each other to verify the bundle again.
**Steps to reproduce**
1. Start a server with an empty in-memory lease map (a new process).
2. Start many turns at the same time. Assign the same large skill to all
of them.
3. Each turn takes the publication lock for that bundle in sequence. The
last turns time out after 30 s.
The new unit test shows the cause directly: 8 concurrent cold uses of
one digest take the lock 8 times on `master`. With this change, they
take it once.
**Paperclip version or commit**
Release `24132dac169fafc616615b4f3144e921aae8ad54`. The code is
unchanged on `master`.
**Deployment mode**
Hosted (staging).
**Agent adapter(s) involved**
Not adapter-specific (core bug).
## What Changed
- `withRuntimeAssetUse`
(`server/src/services/native-runtime/runtime-asset-retention.ts`): the
first non-mutation use of a digest with a cold lease runs the locked
refresh. It registers the refresh in a per-process map before its first
`await`. Concurrent non-mutation uses of the same digest wait for that
refresh. When the refresh records the lease, they use the asset without
the lock, as warm turns already do. When it records no lease (for
example, the refresh failed or no manifest exists), each waiter takes
the lock as before.
- Mutation uses (`captureSkills`, rebuilds) always take the lock. Their
behavior does not change.
- The locked body moved to a `useLocked` helper without changes.
- Two regression tests in `runtime-asset-retention.test.ts`: one refresh
serves 8 concurrent cold uses, and waiters fall back to the lock when
the shared refresh records no lease.
## Verification
- Red: on `master` the new test fails with `expected [ true, true, true,
true, true, …(3) ] to have a length of 1 but got 8`.
- Green: `npx vitest run
src/services/native-runtime/runtime-asset-retention.test.ts` passes 4/4
with this change.
- Related suites pass: `runtime-context.test.ts`,
`runtime-skill-preservation.test.ts`, `managed-skill-content.test.ts`,
`ephemeral-server-runtime-skill-startup.test.ts` (with the retention
suite: 103 of 104 tests pass). The single failure is
`remote-launch-assets.test.ts` "delivers the selected Codex skills…"
(`expected 256 to be 292`). It fails the same way on unmodified `master`
in this sandbox because the sandbox umask is 077.
- `node server/scripts/typecheck-layers.mjs`: all layers pass (below,
cycle, above, tests, test-tree-0..2), exit 0.
## Risks
- Low risk. The change only removes repeated lock acquisitions while one
refresh for the same digest runs in the same process. The lease
semantics and the deletion lock do not change.
- A waiter uses the asset without the lock only after the shared refresh
recorded a fresh lease. This is the same condition that warm turns use
today.
- If a refresh never settles, its waiters wait with it. Before this
change they waited on the lock and failed after 30 s. The lock
acquisition in the refresh keeps its own 30 s budget, so a refresh
cannot wait for the lock without limit.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use
(shell, file edits, 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
- [ ] 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
- [ ] I will address all Greptile and reviewer comments before
requesting merge
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
||
|
|
1196a3402d |
fix(native): do not report a provider usage-limit run that a restart ended (#22385)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Native runs report an unexpected terminal failure to Sentry through the run-failure reporter > - The reporter keeps an expected provider usage-limit failure (`native_provider_usage_limit`) out of Sentry, because the task takes its provider-limit wait and runs again after the reset > - A server restart can end such a run after its provider turn failed on the limit, but before its executor saves `native_provider_usage_limit`. Restart recovery then blocks the run as `provider_checkpoint_permanently_failed`, and the reporter sends it to Sentry > - On staging, one deploy restart sent seven such reports at once. Each task then took its provider-limit wait and finished after the reset, so no operator action was necessary > - This pull request re-derives the usage-limit fact from the run's last committed runner turn terminal and keeps that expected failure out of Sentry > - The benefit is that a deploy during a provider limit does not create false error reports, and real checkpoint failures are still reported ## Linked Issues or Issue Description **What happened?** A deploy restarted the server while several native runs were settling a provider turn that failed on a weekly allowance (`quota_exhausted`). Restart recovery blocked each run as `native_restart_recovery_blocked` / `provider_checkpoint_permanently_failed`. The run-failure reporter sent one Sentry event per run. **Expected behavior** A run that ended on a provider usage limit is an expected failure. The reporter does not send it to Sentry when the executor settles it normally. A restart during settlement must not change that. **Steps to reproduce** 1. Start a native run whose provider turn fails with a `quota_exhausted` or `rate_limit` provider failure. 2. Restart the server before the executor saves `native_provider_usage_limit`. 3. Restart recovery blocks the run as `provider_checkpoint_permanently_failed`, and the reporter sends a Sentry event. Refs #20149 ## What Changed - `native-provider-failure.ts`: move `nativeProviderUsageLimitFromEvent` here from `native-session-executor.ts` so that the evidence reader can use it. The executor re-exports it, so its callers do not change. - `native-provider-failure-evidence.ts`: add `readPersistedNativeTerminalUsageLimit`. It reads the run's last committed turn lifecycle event. It returns true only when that event is a `turn.failed` from the run's own runner instance, the PRP event validates against the stored row (run, session, source, sequence and payload hash), and the failure is a provider usage limit. - `run-failure-report.ts`: for an unexpected `native_restart_recovery_blocked` / `provider_checkpoint_permanently_failed` failure, skip the report when that reader returns true. A read error logs a warning and keeps the report. - Add a real-process restart-recovery test with four cases: usage limit and rate limit are not reported; an unknown failure and a later turn after the limit are still reported. ## Verification - `cd server && npx vitest run src/services/native-runtime/native-runner-restart-recovery.integration.test.ts -t "provider usage limit|pending retry|unreported"`: 5 passed. - Red proof: with only `run-failure-report.ts` reverted, the `usage-limit` and `rate-limit` cases fail (`expected ... to have a length of +0 but got 1`). The two report cases still pass. - `cd server && PAPERCLIP_TYPECHECK_LOW_MEMORY=1 pnpm run typecheck`: passed. - `npx vitest run src/services/run-failure-report src/services/native-runtime/native-provider-failure src/services/native-runtime/native-session-executor.test.ts`: 1619 passed, 1 failed. The failure (`compares export process compatibility without changing conversation identity (changed: false)`, `db.transaction is not a function`) also fails on unchanged `master` (`ce8006de3c`), so this change does not cause it. ## Risks - Low risk. The change only removes a Sentry report. It does not change run status, task status, recovery, or the provider-limit wait. - The filter needs a validated, run-bound runner terminal. A missing, tampered, foreign or later event keeps the report. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code execution in an agent harness. ## 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: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
d60cecf625 |
fix(server): show a retry message when managed app sign-in is rate-limited (#22309)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - People connect apps such as GitHub through the Paperclip Cloud connector > - The connector `session` call can return 429 with the reason `RATE_LIMITED` > - The OAuth start path does not catch this error, so the server answers 500 > - A 500 tells the user that Paperclip is broken. It does not tell the user to try again later. The error also goes to error reporting as a server crash > - This pull request changes a connector rate limit into a 429 with a clear retry message > - The benefit is that users see "try again in a moment" and the server does not report a false crash ## Linked Issues or Issue Description **What happened?** A user on a Cloud beta workspace started GitHub connect two times. The Paperclip Cloud connector rate-limited the `session` call (status 429, reason `RATE_LIMITED`). Both times, the UI showed an internal server error. **Steps to reproduce** 1. Use a Cloud connector where the `session` call returns 429 `RATE_LIMITED`. 2. POST `/api/companies/:companyId/tools/apps/connect` with `galleryKey: "github"` and `connectionMethodKey: "managed"`. 3. Look at the response status. **Expected behavior** The server answers 429 with a readable message and retry guidance. **Actual behavior** The server answers 500 with "Internal server error". No public GitHub issue exists for this. ## What Changed - `server/src/services/tool-access/oauth/authorization-start.ts`: the managed connector branch catches errors from `startAuthorization`. A `PaperclipCloudConnectorError` with status 429 or broker reason `RATE_LIMITED` becomes an `HttpError` 429. The message is "`<App>` sign-in is busy right now. Try again in a moment.", the code is `paperclip_cloud_connector_rate_limited`, and `details.retryAfterSeconds` comes from the broker `Retry-After` value when the broker sends one. - All other errors pass through with no change. - `server/src/__tests__/tool-access-service.test.ts`: a new route test for a rate-limited managed GitHub connect. It checks the 429 status, the message, the code, `retryAfterSeconds`, and that the raw broker reason is not in the response. ## Verification - Reproduced first: before the fix, the new test failed with `expected 500 to be 429`. - `pnpm exec vitest run src/__tests__/tool-access-service.test.ts` in `server/`: 514 tests pass. - `pnpm typecheck` in `server/`: no errors in `server/src`. The local run reported errors only in sibling packages that the limited local install did not include. CI runs the full check. - The UI uses the `error` string of the response body as the message (`ui/src/api/errors.ts` `apiErrorMessage`), so the user sees the new text. ## Risks - Low risk. The change applies only to the managed connector sign-in start, and only when the connector reports a rate limit. - The response does not set a `Retry-After` header. The retry delay is in `details.retryAfterSeconds`, the same as other 429 responses that the service layer makes. - This change does not change the broker rate limit. A separate investigation must find out why the broker rate-limits the `session` call. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) through Claude Code, with tool use and shell code 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 - [ ] 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: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: paperclipbugbot <bots+paperclipbugbot@paperclip.ing> |
||
|
|
62bc0519d9 |
fix(native): bound per-turn harness backups by inactivity, not total time (#22382)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - After a remote native turn is accepted, the executor saves the provider's harness state to durable storage, so another web server can continue the same conversation. > - That save runs under a fixed 300 s total deadline (`AbortSignal.timeout(300_000)`). The deadline covers archive capture, digest, encryption, the upload, any storage-outage wait and a full verifying read-back. > - On staging, five accepted runs failed this save 337–388 s after it began. The run then reported `native_workspace_sync_out_failed` with "The operation was aborted" or tar-stream's "already finalized or destroyed", and workspace copy-back went to retry. > - #19906 fixed the same fixed-deadline rule on the restore side. The write side still uses it. Since #20772/#20871 the save also waits out storage throttling and outages for up to five minutes, which cannot finish inside a five-minute total. > - This pull request bounds the upload and the read-back by inactivity instead of total time. A slow transfer continues while the store makes progress. A transfer that stops fails with a named code. > - The benefit is that an accepted turn no longer loses its provider backup only because the backup is large or the store is slow. ## Linked Issues or Issue Description Refs #19906 (same idle-deadline rule for failover-backup restores), #20772 and #20871 (file-source resends and storage-outage waits during the save), #19108 (stops tar-stream from hiding the real abort), #18932 (durable harness backups). **What happened?** On staging, five native per-turn runs failed within one hour, all after the provider turn was accepted. In each run, `harness_state.backup.persist` failed after 359,588 / 365,422 / 387,471 / 383,801 / 337,335 ms, and `session.checkpoint.persist` failed with it. The only fixed limit on that path is `AbortSignal.timeout(300_000)` around `persistNativeHarnessBackup` in `native-session-executor.ts`. The durations sit just above 300 s, plus a variable sandbox sync-out step before the save. Errors were reported as "The operation was aborted" and, before #19108, as "already finalized or destroyed". **Expected behavior** An accepted turn saves its provider backup while the store keeps making progress, even when the total time is more than five minutes. A write or read-back that stalls fails with a named, diagnosable code. A failed save publishes no backup. **Steps to reproduce** 1. Persist a native harness backup through a store that takes upload chunks slowly, so the full save takes longer than the deadline. 2. With the executor's fixed total deadline, the save fails with "The operation was aborted" and publishes nothing. 3. A store that stops taking bytes, with no caller deadline, waits indefinitely. ## What Changed - `native-harness-backup-storage.ts`: generalize `withDownloadProgressDeadline` into `withTransferProgressDeadline`. It still wraps `getObject` exactly as before, and it now also wraps `putFile` with a five-minute idle timer: - A provider that reads the stream body (local disk) renews it with each chunk it takes. - A provider that sends the file source itself (S3 with `sourceFile`, which never reads the stream) renews it with each request the store answers, each multipart part it takes, and each resend or outage wait that starts. - After the last of them the timer stays armed until the store answers, so a write that never completes is named too. - `persistNativeHarnessBackup` gains `transferIdleTimeoutMs` and `persistMaxMs` (default 30 minutes). The outer bound wraps the whole save, including the storage-outage wait. With an idle limit, a stalled upload throws `native_harness_storage_upload_stalled`, a stalled read-back throws `native_harness_storage_download_stalled`, and the whole save throws `native_harness_storage_persist_deadline_exceeded` at the outer bound. Caller cancellation keeps its own reason, and a storage outage that outlasts its own budget still surfaces as the storage error. Callers that pass no idle limit (controller archive, offline migration, preservation) are unchanged. - `storage/request-stats.ts`: add `observeStorageProgress(onProgress, work)`, an `AsyncLocalStorage` observer called from the existing `recordStorageRequest`, `recordStoragePart` and `recordStorageBackoff` hooks. It is scoped to the wrapped `putFile` call only, and a throwing observer is ignored. Stats collection is unchanged. - `native-session-executor.ts`: the per-turn backup passes `NATIVE_HARNESS_UPLOAD_IDLE_TIMEOUT_MS` (five minutes) instead of `AbortSignal.timeout(300_000)`. - Restore behavior and error codes are unchanged: `withDownloadProgressDeadline` now delegates to the shared helper with the same defaults. - `doc/database-backups.md`: document the write-side idle limit, what counts as progress, and the new codes. Previous-release story (`rules/upgrade-safe-run-state.mdc`): no persisted shape changes. Backup rows, references, receipts and checkpoints are unchanged. A deploy that lands during a save stops the process, and the pending row is never published, as before. ## Verification Run from `server/` (provider env vars unset): - `pnpm exec vitest run src/services/native-runtime/native-harness-backup-upload-deadline.integration.test.ts`: 6 tests passed. They use embedded PostgreSQL, local-disk storage and an incompressible 1 MB acpx backup. - "keeps saving a backup whose upload outlasts the idle window while the store keeps taking bytes". Under the former fixed-total policy the same slow upload fails with "The operation was aborted" and publishes nothing. With the idle limit it completes after more than twice the window and restores. - "names an upload that stops taking bytes and publishes no backup", then saves the same source once the store responds. - "keeps a file-source upload going while the store answers its requests, and names one that stops". The fake store never reads the stream and records each request answer the way the S3 provider does. - "names a read-back that stops sending bytes and publishes no backup". - "stops at the outer bound while an upload still progresses". - "lets Stop end a progressing upload with its own reason". - RED, part 1: with `native-harness-backup-storage.ts` and `request-stats.ts` reverted to `master`, 4 tests fail. Three stall tests hang until the 10 s test timeout, and the outer-bound test resolves instead of rejecting. - RED, part 2: with only the progress observer disabled, the file-source test fails with `native_harness_storage_upload_stalled` on an upload that is still progressing. - `native-harness-backup-*` suites, `native-harness-online-preservation`, `src/storage/`, `storage-request-stats` and `storage-s3-multipart-backoff`: 200 of 201 passed. The one failure, `native-harness-backup-cleanup.test.ts` ("removes retired backups containing immutable skills…", expected mode 256 to be 292), fails the same way on unmodified `master` in this sandbox. - `native-session-executor.test.ts`: 1541 of 1542 passed. The new assertion checks that the per-turn backup passes `transferIdleTimeoutMs` and no fixed signal, and flipping it fails the `opencode-new-durable*` cases. The one failure, "compares export process compatibility without changing conversation identity (changed: false)" (`db.transaction is not a function`), fails the same way on unmodified `master`. - `node scripts/typecheck-layers.mjs`: no errors in `server/`. The local filtered install lacked some CLI/UI/demo packages, which reported unrelated errors. CI covers the full typecheck. Not verified: a live staging run with this build. The staging evidence shows the save failing just after 300 s on several runs. It does not show which step was slow (upload, read-back or local capture), so the fix removes the fixed total for every step on that path. ## Risks - A save that progresses very slowly can now take longer than five minutes. Before, it failed. The settle step waits for it, up to the 30-minute outer bound. - A local step that hangs (for example a stalled disk during capture) is now cut off at 30 minutes instead of 5 minutes, with `native_harness_storage_persist_deadline_exceeded`. - For S3 file-source uploads, progress is measured per request, not per byte. A single request that takes more than five minutes counts as stalled. For a 16 MiB single PUT, that is a store slower than about 55 KB/s. Multipart parts are 8 MiB, eight in flight. - If a successor takes over during a long save, the existing fence checks before and after the upload reject it with `owner_superseded`, and nothing is published. This is unchanged behavior. ## Model Used - Provider: Anthropic. Model: Claude Opus 5.5 (`claude-opus-5-5`), with tool use (shell, file edits) in Claude Code. ## 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: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
3f6c3d37dc |
fix(mcp): keep remote HTTP 405 connection checks out of Sentry (#22376)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Connected apps can be remote MCP servers that Paperclip reaches over
Streamable HTTP
> - A connection health check sends a `tools/list` POST to the saved URL
> - `markMcpHttpResponseFailure` marks 401, 403, 404, 429 and 5xx
answers as known external failures, so the error handler does not send
them to Sentry
> - A remote app answered the health check with HTTP 405, and this
status was not marked, so Sentry recorded an app error
> - A Streamable HTTP MCP endpoint always accepts POST, so a 405 means
that the saved URL is not an MCP endpoint (for example a web page or a
legacy SSE-only path)
> - This pull request marks a 405 answer as `endpoint_not_found`, the
same as a 404
> - The benefit is that a bad remote URL no longer creates a Sentry
error, and the connection still shows the failed check
## Linked Issues or Issue Description
No public issue exists.
**What happened?**
On a hosted staging server, a connection health check for a gallery app
failed with `Error: Remote app returned HTTP 405`. The stack is
`connectGalleryApp` -> `checkConnectionHealth` -> remote MCP
`tools/list` POST. The error handler sent this error to Sentry as an
unexpected app error.
**Expected behavior**
A 405 answer from a remote app is an external failure. The connection
shows the failed check with the `endpoint_not_found` reason. Sentry does
not record it.
**Steps to reproduce**
1. Save a remote MCP app with a URL that answers POST with HTTP 405.
2. Run the connection health check.
3. On `master`, the failure has no known reason, so it goes to Sentry.
The new test in
`server/src/services/__tests__/mcp-connection-failure.test.ts` does
these steps.
**Paperclip version or commit**
`master` at
|
||
|
|
fe0c4aa95d |
fix(recovery): settle a late workspace hold when a remote-epoch continuation already took over (#22387)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Restart recovery must continue a task after a server is killed. A person must never need to press Retry. > - When Paperclip cannot resume a cut-off run exactly, it records a "fresh continuation". For a remote workspace, the continuation abandons the old run's workspace epoch and restores the last save into a new root. It does not apply the old run's unsaved files. > - Workspace recovery can try to save the old run's files after that. The epoch is already abandoned, so the source is "unavailable". Recovery then wrote an active hold that asked a person to press Retry to continue in a new workspace, which the continuation had already arranged. > - That hold made the dispatch gate withhold every queued run of the task, and the task rested on a Retry banner. > - This pull request settles that hold into the recorded continuation at the moment workspace recovery would leave it exhausted. Dispatch and continuation delivery are unchanged. > - The benefit is that the queued continuation starts automatically after a hard kill, with no Retry banner. ## Linked Issues or Issue Description **What happened?** A restart-chaos release-swap wave hard-killed the old server. One task (of 6) then rested on a Retry banner for about 5 minutes. The other 5 tasks passed. The sequence for the failed task: 1. A run started on the incoming server. The wave's injected database delay held its process-identity write for 480 s, so its runner attach timed out. The run saved a same-run resume. 2. Restart recovery found a newer queued run for the task (a child-completion wake). It treated the same-run resume as superseded, and the run ended `failed` with `native_restart_recovery_blocked`. 3. The dispatch gate withheld the queued run (`execution_reconciliation_required`). In the same transaction, it recorded a fresh continuation with `remote_epoch` isolation, which abandoned the old run's remote workspace epoch. 4. 4 s later, workspace preservation for the old run found the abandoned epoch (`source_unavailable`, `use_alternative_strategy`). It left an active hold: "Paperclip cannot recover the unsaved files from the previous run ... Retry continues the task in a new workspace". The retained-source fallback also refused it later, with `workspace_authority_changed`, because the continuation owned the epoch. 5. The gate withheld both bounded retries because of that hold. The retries were spent, and the task showed a Retry banner. 6. A person pressed Retry. Retry started a run in a new workspace, which the recorded continuation had already decided to do. **Expected behavior** The queued continuation starts automatically. No Retry banner shows. **Steps to reproduce** 1. Run the restart-chaos K1 kill variant: 2 release swaps, and the old server is hard-killed 120 s after SIGTERM. 2. Use an OpenCode task on a remote sandbox whose run starts just before the second swap and that gets a child-completion wake while it runs. 3. Watch the task after the kill. Workspace recovery writes the unsaved-files hold, the gate cancels each queued run with `execution_reconciliation_required`, and the task rests on a Retry banner. `server/src/__tests__/heartbeat-isolated-continuation-hold.test.ts` reproduces the database state at step 5. **Paperclip version or commit** `master` at |
||
|
|
c41145e72a |
fix: wait on pending questions and quiet provider holds (#22363)
## Thinking Path > - Paperclip manages agents and the tasks they work on. > - Recovery should continue unfinished work when it is eligible. > - An active unanswered question is a persisted reason to wait for a person. > - Treating a later Retry as an answer makes the recovery sweep repeatedly request continuations that admission refuses. > - Provider-limit holds also produce one cancellation toast per task, even though provider work never started. > - This PR aligns recovery with persisted interaction status and presents these waits accurately. ## Linked Issues or Issue Description Refs: #20466. This addresses the question blocker presentation and automatic recovery loop; it preserves the existing interaction-resolution policy. Related work: #19420 schedules provider quota retries, and #21570 handles notices and reply ownership in agent chats. This change concerns assigned-task reconciliation, task/inbox status, and per-run cancellation toasts. **What happened?** The assigned-work sweep ignored pending interactions whenever a newer run carried `explicitUserContinuation`. Continuation admission still refused the pending question, so repeated sweeps recorded unsuccessful continuation attempts. The task could meanwhile show an older provider error as its current blocker. Separately, each pre-dispatch provider-limit hold generated a cancellation toast, and the one-hour fallback was described as a known reset and promised start time. **Expected behavior** Wait quietly while the question remains active under the shared interaction eligibility rules, then react to the existing resolution notification. Dismissed or historical ordinary questions remain answerable without blocking work; governed requests keep their gates. Show the current question on task and inbox surfaces. Keep provider failure history, suppress cancellation toasts for expected provider holds, and describe scheduled availability checks without promising the provider will accept work. **Steps to reproduce** 1. Leave an `ask_user_questions` interaction pending with `supersedeOnUserComment: false`. 2. Create a later failed/interrupted explicit Retry and run assigned-work reconciliation repeatedly. 3. Observe that the question remains pending while the sweep attempts fresh continuations. 4. Separately, let an agent with recent provider rate-limit evidence receive automatic task wakes without a reported reset time. ## What Changed - Remove inferred question supersession from both assigned-work fact loading and candidate selection. Use the existing active-interaction predicate consistently in those reads, fresh-continuation admission, and the task projection. Cover dismissed/historical ordinary questions, retained governed gates, repeated checks, idle workers, and the existing resolution notification. - Add the `question` interruption action, load active pending question IDs alongside approvals in one company-scoped query, and show that blocker on tasks and inbox rows. Preserve a supported manual Retry after a failed attempt, suppress duplicate actions for saved input, and keep other current user gates authoritative. This preserves the existing issue-detail SQL statement budget. Historical run failures remain intact. Refresh the shared source SDK input pin. - Suppress cancellation toasts specifically for cancelled `provider_limit_wait` runs. Label provider retry deadlines as availability rechecks, retain relative-time formatting, and record successful scheduling as an informational lifecycle event. - Document the wait contract in the continuation architecture guide. ## Verification - Demonstrated failing regressions before the implementation: continuation loop, task projection, task notice, cancellation toast, provider deadline wording, and deadline formatting. - Initial focused Vitest qualification: 642 tests passed across 14 files, using: ```sh pnpm exec vitest run \ server/src/__tests__/{assigned-work-invariant,assigned-work-recheck-idle,heartbeat-provider-limit-wait,task-interruption-query}.test.ts \ server/src/services/{task-interruption-presentation,execution-projection,fresh-continuation-fallback,issue-thread-interactions}.test.ts \ server/src/services/recovery/assigned-work-invariant.test.ts \ ui/src/{components/ExecutionBlockerNotice.test.tsx,context/LiveUpdatesProvider.test.ts,context/LiveUpdatesProvider.hook.test.tsx,lib/provider-limit-message.test.ts,pages/Inbox.test.tsx} ``` - `pnpm --filter @paperclipai/shared typecheck` — passed. - Review follow-up: 157 tests passed in `assigned-work-invariant`, `task-interruption-query`, and `fresh-continuation-fallback`; 575 passed in `task-interruption-query`, `assigned-work-recheck-idle`, `task-interruption-presentation`, `issue-question-context`, `issue-thread-interactions`, and `explicit-native-continuation` (the query file overlaps). The strengthened final dismissed/historical/governed projection regression also passed separately. - Final query-consolidation verification: 157 tests passed across five files, including the unchanged 64-statement issue-detail census and mixed approval/question batches: ```sh pnpm exec vitest run \ server/src/__tests__/{issue-detail-statements,task-interruption-query,assigned-work-invariant,assigned-work-recheck-idle}.test.ts \ server/src/services/task-interruption-presentation.test.ts ``` - `pnpm --filter @paperclipai/server typecheck` — passed, including test layers. - Manual-recovery follow-up: 204 tests passed across seven projection/recovery/notice suites, and all 104 Inbox tests passed. The lost-runner integration still starts exactly one run from a manual Retry and leaves the question unanswered. The saved-decision census verifies one decision batch query for a 41-task list, with at most three statements referencing interactions; the overall 64-statement issue-detail limit remains unchanged. - `pnpm --filter @paperclipai/ui typecheck` — passed. - `pnpm --filter @paperclipai/ui build` — passed. - `node tests/runner-e2e/source-sdk-public-inputs.mjs $(git rev-parse HEAD) --check` — passed. - `pnpm verify` — exit 2: broader CI is required for changed global inputs. Focused tests and package checks supply local evidence; broad CI remains required. - `git diff --check` and a local secret/instance-data scan — passed. - Final CI on `1c16fe7c0d8`: [trusted CI workflow](https://github.com/paperclipai/paperclip/actions/runs/44650155842) passed, including all server shards, native-server verification, build, canary, e2e, release registry, and serialized suites. All PR checks are complete, with no failures; the branch is conflict-free. - Greptile reviewed the latest revision, `1c16fe7c0d8`, at 5/5 with no actionable findings or unresolved review threads. The focused tests cover genuine provider failures, live work and terminal tasks, unchanged task locks/retry delivery, preservation of historical failures, and question resolution waking the affected task while other active pending questions remain quiet. Review regressions also cover dismissed/historical ordinary questions retaining Retry and governed requests retaining their gates. No live task was retried or answered for validation. ## Risks - An active pending question now consistently blocks automatic assigned-work recovery. Shared interaction eligibility determines when ordinary conversation input becomes deferred or historical; governed requests retain their authority. Automatic recovery no longer infers that a newer Retry resolved an active question. - Manual Retry keeps its existing admission policy and recovery checks. The question notice preserves that supported action after a failed attempt without changing approval or credential authority; pending saved input prevents duplicate actions. - The shared interruption action gains `question`; the task and inbox consumers are updated together. The pending-question query returns only task IDs and uses the existing company/task/status index. - Provider cooldown policy, quotas, credentials, routing, cancellation history, and durable retry timing are unchanged. The actual provider can still return a rate limit at the recheck. - No migration is required. Existing large owner modules receive small localized changes; no code file crosses 1,000 lines. ## Model Used OpenAI `gpt-6.1-sol` through the Codex harness in T3 Code, xhigh reasoning effort, with code execution and tool use. ## 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 linked existing issues or described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links - [x] My branch name describes the change and contains no internal 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> |
||
|
|
25b5cad7f9 |
fix(native-runtime): start first OpenCode turns from any saved launch-file copy instead of waiting on a stalled one (#22367)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - OpenCode agents in remote sandboxes must have a saved, verified copy of their launch files before their first turn (#19622, #21287) > - The first runs of a company share one copy of these files per server. Other runs wait for it > - In a restart chaos wave, the shared copy out of one sandbox stalled for 330 s. Seven other runs waited silently for it. Two runs then failed before their first turn with the cause `unknown` > - The copy speed out of a sandbox differs from one sandbox to the next. When the first copy failed, the other sandboxes copied the same 314 MB in 15 to 24 s > - This pull request lets every waiting run use the first copy that any run saves, starts a second copy when the first one is slow, and names the cause of a stalled copy > - The benefit is a shorter cold start for the first runs of a company, no failed run when another run already saved the files, and a named cause instead of `unknown` ## Linked Issues or Issue Description Refs #19622 Refs #21287 **What happened?** A restart chaos wave started 15 OpenCode runs on new Daytona sandboxes (1 vCPU) in a new company. The first run (A) started the shared copy of the 314 MB launch files out of its sandbox. The copy did not finish. The plugin call timed out after 330 s, and run A failed before its first turn. The other runs waited for that copy without any run event, so the task looked dead for 284 to 343 s. When run A failed, every waiting run started its own copy at the same time. Five copies finished in 15 to 24 s. One copy (run B) stalled again and failed after 330 s, although a saved copy existed after 15 s. One copy (run C) took 5 min and started its turn 10 min after the run started, although it could have used the saved copy 5 min earlier. Both failures had the technical cause `unknown`. Each failure also logged "native result could not be marked workspace_failed; the reconciliation loop will retry persisted results", but the run had no result, so there was nothing to retry. **Expected behavior** A run uses the first saved copy as soon as one exists. A slow copy does not hold all first runs. A stalled copy out of the sandbox has a named cause. A run with no result does not log a result-finalization failure. **Steps to reproduce** 1. Use a company with remote OpenCode agents on Daytona sandboxes with durable storage and no saved launch-file copy. 2. Start 8 or more runs together on new sandboxes. 3. Make the copy out of the first sandbox stall (for example, a slow sandbox link). 4. See that all other runs wait for the full plugin timeout, and see the failures with the cause `unknown`. **Agent adapter(s) involved** OpenCode (native runtime, remote sandbox). ## What Changed - `shareNativeProviderArtifactCapture` (`native-provider-artifact-capture.ts`): - The first capture that saves a ready copy ends the wait for every run. A run whose own capture is still copying uses the saved copy and aborts its own copy. - A run whose own capture fails uses a saved copy when one exists, and fails only when none exists. - When the running capture is slower than 90 s, one waiting run starts one more capture from its own sandbox. At most two captures run at once. A capture keeps its slot until its copy out of the sandbox ends. - The start decision is owned by one `SharedArtifactCapture` coordinator (`tryStart()` returns a release lease). - When the shared capture fails, one waiting run starts the next capture. The other runs keep waiting for it. Before, every waiting run started its own copy at the same time. - The capture callback now gets its own abort signal, so a superseded copy stops before upload. - A failed copy out of the sandbox is now `NativeProviderArtifactExportError` with the code `native_provider_artifacts_export_timeout` (plugin call timed out) or `native_provider_artifacts_export_failed`. The run's technical cause shows this code instead of `unknown`. A timeout shows "Setting up the computer took too long ...". - `runtime-execution.ts`: do not try to mark the workspace as failed on a native result when the run has no result. Before, this always threw `native_finalization_missing` and logged a false "will retry" warning. - `doc/opencode-cold-recovery.md`: describe the new sharing, the second capture and the new cause codes. ## Verification - Red/green: with the old `native-provider-artifact-capture.ts`, these 5 new tests fail. With this change, they pass: - `native-provider-artifact-gate.test.ts`: "starts a run's turn from another run's saved artifact while its own capture is still copying", "uses a saved artifact when the run's own capture fails after another run saved one", "starts one more capture when the shared capture runs past the hedge delay, not one per waiting run", "does not start a capture per waiting run when the shared capture fails", "names a stalled copy out of the sandbox instead of an unknown cause". - Red/green: `heartbeat-native-predispatch-retry.test.ts` "continues on a fresh ... sandbox when the provider artifacts fail to save before any turn" now also asserts that no "could not be marked workspace_failed" warning is logged. It fails before the `runtime-execution.ts` change and passes after it. - `cd server && npx vitest run src/services/native-runtime/native-provider-artifact-gate.test.ts src/services/native-runtime/native-provider-artifact-capture-confinement.test.ts src/services/native-runtime/native-session-executor.test.ts src/services/native-runtime/native-harness-backup-storage.integration.test.ts src/services/native-runtime/native-provider-artifact-capture.test.ts src/services/heartbeat/runtime-execution.test.ts src/services/task-interruption-presentation.test.ts src/__tests__/heartbeat-native-predispatch-retry.test.ts`: all pass. - `npx tsc --noEmit -p server`: pass. ## Risks - A slow first capture can now cause one more 314 MB copy after 90 s. At most two copies run at once for one company and manifest. A run whose saved copy cannot be reused (for example, an ownership fence mismatch) starts its own copy at once. Before, a failed burst started one copy per waiting run at once, which was more. - A superseded copy never uploads, but the provider call that copies files out of the sandbox continues until it ends or times out. Its local temporary directory is removed when it ends. - Sharing is still per server. Two servers can still copy the same files. - No change to the rule from #19622: a verified saved copy still exists before the first turn. - No runner or image change. No migration. > 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 - Claude (Anthropic), model ID `claude-opus-5-5`, used through Claude Code with tool use (shell, file edit, test runs). Default context window; extended reasoning on. ## 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: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
19a7381398 |
feat: restore personal archiving in task views (#22358)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - People use Tasks to see shared work and manage the work that needs their attention. > - The old inbox already let each person archive a task and undo that action. > - The combined Tasks surface needs the same controls in Unread and in task table rows. > - The existing inbox archive rules determine when new activity brings a task back. > - This pull request adds an Archived view so people can find and restore their archived tasks. ## Linked Issues or Issue Description **What existing behavior does this improve?** Personal task archiving in Tasks. Related work includes the combined Inbox and Tasks surface (#15100), the Coordinator workspace (#17983), moving Mine into Tasks (#19363), and the existing inbox archive rules (#9931). **Subsystem affected** Cross-cutting. The UI and task list API reuse the existing inbox archive state. **Current behavior** Mine has an archive action. Unread and the task table have no equivalent action. The Tasks menu has no dedicated view for restoring archived tasks. **Proposed behavior** Add Archive and Undo to the task views. Let people restore tasks from Archived. Keep archived tasks available in All tasks. **Reason and benefit** People can clear their personal lists and still find the original task. **Breaking changes** The task list API adds an optional archive filter and viewer archive field. Existing callers use the same response and filters unless they opt in. ## What Changed - Reuse the current inbox archive and restore actions, activity rules, and authorization. - Add Archive and Restore to task table rows, Archive and Undo to Unread, and a personal Archived view. - Give each archived task its own Undo control, including when people archive tasks quickly. - Add tests for the archive list, account isolation, new activity, row actions, and Undo. - Document the archive flow and API filter. Refresh the generated SDK source input registry. ## Verification - Passed 287 focused tests in 12 Vitest files. These cover the task views, row actions, archive cache, and PostgreSQL routes. - Passed local server and UI typechecks. The source input registry check also passed. - Reproduced a missing Undo action when archiving two tasks in a row. After the fix, the 158 task and inbox tests and the 2 toast tests passed. - On macOS with Chrome, archived a task from Mine and restored it using Undo. Archived another task from All tasks, reloaded Archived, restored it, and verified its Todo status and return to Mine. - A human tester also verified Archive, Undo, and Restore in the local browser. - On commit `c5526fd9b1`, GitHub's [verification](https://github.com/paperclipai/paperclip/actions/runs/44630156078/job/135950130662) and [browser tests](https://github.com/paperclipai/paperclip/actions/runs/44630156078/job/135946228919) passed. A targeted retry passed after the first attempt hit a watchdog self-test failure and two cancelled jobs. - [Greptile scored 5/5](https://github.com/paperclipai/paperclip/pull/22358#issuecomment-7024083610) on the same commit. Both review threads are resolved. ## Risks - An incorrect visibility rule could hide a task from a personal list. The archived filter uses the same activity predicate as Mine. The PostgreSQL test covers isolation between people and resurfacing after a reply. - The archive state is already stored per person and company. No database migration is required. ## Model Used - OpenAI Codex, GPT-6, with shell, code editing, and browser verification tools. The serving model ID and context size were unavailable in this session. ## 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: Scott Tong <1504818+scotttong@users.noreply.github.com> Co-authored-by: Paperclip <noreply@paperclip.ing> |
||
|
|
24132dac16 |
fix(tasks): verify PR merges with the managed run identity (#22357)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Native task completion independently verifies that declared PR deliverables are merged. > - Runs can already use an authorized managed GitHub connection to merge private PRs. > - Completion used the background credential resolver, which cannot select that run's managed identity. > - This pull request reuses operation-time identity and grant checks for completion verification. > - Agents can finish delivered work while unavailable grants and unverified merges remain blocked. ## Linked Issues or Issue Description Related: #22244 introduced the native PR merge gate. No duplicate fix was found in the open PR search. The roadmap's personal GitHub identity capability already covers the intended identity model. **What happened?** A native agent with a managed GitHub connection merges a private PR, then completion rejects it as not verified merged. The independent server-side check only tries legacy company token names or an instance token; it does not use the agent run's managed connection. **Expected behavior** Verify the merge with the run's current accepted GitHub identity, retaining current grant, membership, trust and company boundaries. GitHub must confirm the merge regardless of saved work-product metadata. **Steps to reproduce** 1. Configure a managed GitHub identity with access to a private repository and no legacy company GitHub token. 2. Use a native task run to merge and register a PR deliverable. 3. Finish the task. Before this change, the merge verifier cannot authenticate with the managed identity and rejects completion. ## What Changed - Bind completion credential lookup to the persisted company, native task and run. - Add a server-side completion credential path that shares managed grant, membership and trust checks with command credentials. Both active and succeeded runs capture identity under the existing task/run locks and reconcile pending steering acknowledgements before credential lookup. The command credential API still requires a running run. - Resolve credentials once for all PRs in a verification attempt; do no credential work for tasks without PR deliverables. - Preserve legacy fallback only for runs without a managed identity, and preserve the public-only restriction on server-environment credentials. - Add 23 PostgreSQL-backed authorization regression cases and document completion's identity behavior. ## Verification - Local checks cover revision `da2a3608b0375ead646bbbad35af853191488f07`. [Greptile review](https://github.com/paperclipai/paperclip/pull/22357#issuecomment-7023243798) is 5/5 on that revision with both prior threads resolved. [Required CI](https://github.com/paperclipai/paperclip/actions/runs/44625662403) passed on attempt 2 for the same revision, including typecheck, build, canary, server/runner suites and all eight e2e shards. - Red/green: the private-PR and identity-selection cases failed before the initial fix. Review exposed a succeeded-run reassessment failure and then an unsettled-steering gap in that path; each has a regression that failed on the reviewed commit and passes after its correction. Unresolved steering performs no token lookup, and durable acknowledgement selects the new person. The full worker test completes the task after automatic-review withdrawal while command credentials remain unavailable to the finished run. - `pnpm exec vitest run server/src/services/native-runtime/native-pull-request-completion.test.ts server/src/services/native-runtime/native-completion-feedback.test.ts server/src/__tests__/github-operation-credentials.test.ts server/src/__tests__/native-status-reassessment-work.test.ts server/src/__tests__/run-identity.test.ts server/src/__tests__/run-identity-projections.test.ts` — 222 tests pass across six files, on macOS arm64 with Node 25.6.1 and embedded PostgreSQL. - `pnpm --filter @paperclipai/server typecheck` — passes. - `pnpm verify --explain` — exits 2 because the subsystem documentation selects broad CI coverage. Required CI supplies the broader test/build coverage; this exit is not a full-suite pass. - The credential selection, steering, grant and company checks use real PostgreSQL state. Only the secret vault and GitHub HTTP transport are mocked; test requests never reach GitHub. - `git diff --check` and the staged secret/PII scan pass. No runtime artifacts are committed. - Earlier CI revision `4e42f64`: the [Build job](https://github.com/paperclipai/paperclip/actions/runs/44624163145/job/135914203042) ended after the runner received a shutdown signal and the workflow was cancelled. Its log does not show a compiler error before interruption; this interrupted attempt is not build verification. The current revision subsequently passed its own CI build on attempt 2. - Current revision canary: the [Canary Dry Run job](https://github.com/paperclipai/paperclip/actions/runs/44625662403/job/135919504493) was interrupted by runner shutdown before completion. The repository runner-loss classifier returns `lost: true` for its actual annotation and log. A targeted retry was refused while the workflow remained active. The same revision subsequently passed Canary Dry Run and the full workflow on attempt 2; the earlier interrupted attempt remains recorded here separately. - Live acceptance remains pending deployment; the change has not been deployed. ## Risks Completion now reads managed credentials through a server-side path shared with the existing authorization checks. Successful finished runs can be reassessed without granting them command execution credentials. Denied or unavailable identities must remain blocked without falling through to a different identity; regression tests cover revocation and company/task isolation. Credential lookup is shared within one bounded PR verification attempt, not cached across attempts. The existing HTTP deadline and merge proof requirements remain in place. No migrations or API contract changes. ## Model Used OpenAI Codex, `gpt-6.1-sol`, xhigh reasoning, with repository inspection, code editing and test execution. Context-window size is not exposed by the harness. ## 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> |
||
|
|
d8ae55198d |
Scope runtime catalog reads to standing-instruction sources (#22356)
## Thinking Path > - Paperclip uses standing instructions from authorized app connections when it prepares a run. > - The gateway already knows which connections have instructions enabled. > - The catalog read still loads tool schemas for every eligible connection in the company. > - This work delays prompt preparation and consumes database and application resources. > - The gateway can restrict the existing catalog query while preserving the names used for authorization. ## Linked Issues or Issue Description **Subsystem affected** — Tool gateway and run preparation. **Problem or motivation** — The instruction resolver filters tool descriptors after the database has returned unrelated catalog entries. **Proposed solution** — Scope the persisted catalog read to possible instruction sources. Include peers that share a candidate’s short connection ID when assigning tool names. **Alternatives considered** — An exact connection ID filter could change a tool name and its policy decision. A separate instruction authorization query would duplicate gateway policy. **Roadmap alignment** — This improves the existing task-start path. Related work includes #22347 and #14864. **Additional context** — The change uses the existing read-only catalog snapshot. It adds no schema or cache. ## What Changed - Pass the instruction candidates to the shared gateway catalog reader. - Read eligible naming peers in the same snapshot. Return only candidate descriptors after assigning their names. - Retain the existing run identity, guest restrictions, model visibility, provider tools, policy decisions and grants. ## Verification - Ran the connection instruction and gateway listing-memory integration suites against embedded PostgreSQL. All 23 tests passed. - Confirmed the bounded-read assertion fails on the baseline and passes on the change. A full listing reads 20 catalog entries from two connections. The instruction lookup reads 10 entries from one. - Covered exact-name approval and block policies, peer quarantine, unchanged instruction text and digest, and visibility of unrelated tools in normal discovery. - Ran integration tests for gateway discovery, gateway service behavior, and assigned MCP tools. All 256 tests passed. - Compared complete instruction resolution with embedded PostgreSQL on macOS, using 16 alternating measured pairs after five warm-ups. The one-tool fixture took 10.05 ms median on the baseline and 10.32 ms on the change. With 1,994 synthetic entries across 21 connections and four candidate entries, the medians were 50.44 ms and 24.47 ms. The median paired saving was 26.03 ms. Final instruction text and digest matched for every pair. - The comparison measures the local instruction resolver. Remote submission-to-turn latency was outside this verification. ## Risks The candidate read uses the first UUID component because it participates in gateway naming. Matching peers contribute to name collisions even when an agent cannot use the peer. The regression checks that a blocked candidate cannot gain access when the catalog is narrowed. Companies that enable instructions on most connections can expect smaller savings. ## Model Used OpenAI Codex directed and qualified the change. GPT-6.2 Sol implemented the change and focused regression tests. ## 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 - [ ] 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> |
||
|
|
28043f8b93 |
Measure database and projection costs in runtime tool discovery (#22347)
## Thinking Path > - Paperclip starts agent turns with instructions for the connections the agent can use. > - The gateway reads the connected-tool catalog during prompt preparation. > - A single discovery span currently covers both database waits and descriptor construction. > - Maintainers need to distinguish these costs before changing catalog reads. > - This change records the transaction, both queries, availability checks, and descriptor construction. ## Linked Issues or Issue Description **Subsystem affected** — Runtime tool discovery and run preparation. **Problem or motivation** — The existing catalog span cannot explain time spent before a remote turn starts. **Proposed solution** — Measure the existing read in place. Record the number of entries and connections returned. **Alternatives considered** — A local microbenchmark cannot reproduce a hosted database or a deployed catalog's sizes. A change to the query would confound the measurement. **Roadmap alignment** — This adds diagnostic detail to an existing operation. Related work includes #14864, which bounded catalog memory use. **Additional context** — The PostgreSQL reads share one read-only snapshot. ## What Changed - Add a transaction span with children for the entry read and the matched-connection read. - Attach the two returned row counts to that transaction. - Time availability checks and descriptor construction under the existing catalog discovery span. - Document which preparation timings can also reach the native run event table. ## Verification - Ran the gateway listing-memory, discovery HTTP, and execution timing context suites with local PostgreSQL. All 30 tests passed. - Checked the parentage and row counts with a real OpenTelemetry exporter in memory. - Ran the standing-instruction integration suite and measured the catalog from two staging application containers with read-only database sessions. ## Risks Each recorded catalog operation adds up to five spans. The existing per-phase bound applies. Only the OTel transaction span includes the aggregate row counts. With or without OTel, the existing native preparation timing path can also persist a run event for each new phase that takes at least 50 ms, subject to its normal caps. The executor defers those writes. The database query, tool eligibility, and authorization contracts stay the same. ## Model Used OpenAI Codex directed and qualified the work. GPT-6.2 Sol implemented the instrumentation and regression test. ## 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 |
||
|
|
6be53f0831 |
fix(issues): keep a held task blocked when its agent tries to resume it (#22245)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - When a run stops with an unknown outcome, recovery can record an
execution hold for the task. Wake admission refuses every wake for the
task until the system continues it from saved work or a person uses
Retry. Recovery sets the task to "Blocked", so a person can see it.
> - An agent can move that task out of "Blocked". It can change the
status, send `reopen` or `resume`, or check the task out. None of these
routes checks the execution hold, so the hold stays.
> - The task then looks workable, but its agent cannot start. Its
scheduled follow-up check (monitor) comes due, and the scheduler tries
it on every tick. Wake admission refuses each try. Agents re-arm the
check, and the check stays overdue for days.
> - #22215 makes these tasks show as "Blocked" in lists. It does not
stop agents from making the state.
> - This pull request refuses an agent request that moves a held task
out of "Blocked". The response is 409 and gives the next action of the
hold.
> - The benefit is that a held task stays "Blocked" until its hold is
released. Its follow-up checks wait and do not retry on every tick, and
the agent gets the correct reason.
## Linked Issues or Issue Description
(B) No issue exists. Bug report:
**What happened?**
Scheduled follow-up checks on agent tasks stayed overdue for many days.
Each due check was skipped with `execution_reconciliation_required`. One
skip record merged more than 25,000 attempts. The tasks were in
`in_progress` or `in_review`, but an execution hold from a failed run
refused every wake. The agent re-armed the checks, and the checks never
started. An agent can move a task out of `blocked` while such a hold
exists. The resume guard and checkout do not check the hold.
**What did you expect to happen?**
A task that wake admission holds stays `blocked` until the hold is
released. An agent that tries to move it gets an error that tells it
what must happen first.
**Steps to reproduce**
1. Make a `blocked` task that is assigned to an agent.
2. Add a recovery record for the task with status `resolved`, cause
`provider_failure_meaning_unverified` and evidence
`automaticRecovery.replay = "blocked"`. `getExecutionBlocker` returns
this hold.
3. As the assigned agent, send `PATCH /api/issues/:id` with `{ "status":
"in_progress" }`. You can also send `reopen` or `resume`, or `POST
/api/issues/:id/checkout` with `expectedStatuses: ["blocked"]`.
4. See that the request succeeds and the task leaves `blocked`. The hold
stays, so wake admission still refuses the task.
5. Give the task an execution policy with a review stage. As the agent,
send `PATCH /api/issues/:id` with `{ "status": "done" }`. The execution
policy changes the status to `in_review` and assigns the reviewer. The
task leaves `blocked`, and the hold stays.
**Paperclip version or commit**
`master` at
|
||
|
|
cf89f0436c |
fix(native-runtime): name the closest assigned tools when a tool name is mistyped (#22327)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - Native runners give agents their assigned app tools through two
wrapper tools: `paperclip_search_assigned_tools` and
`paperclip_call_assigned_tool`.
> - Search returns each tool with a hashed alias
(`app_<readable>_<digest>`). #22213 also accepts an unambiguous gateway
name or display name.
> - Some models copy the alias with an error: they drop or change one
digest character, change the characters of the bot id, or attach the
digest of a different tool.
> - The wrapper correctly rejects these names, because a guess could
select a write tool when the agent meant a read tool.
> - But the error only said "name must be an exact name". The agent
searched again and often repeated the same mistake.
> - This pull request adds the closest names that the agent can use to
the error. It does not resolve any name by approximation.
> - The benefit is a faster recovery after a mistyped name, with no
change to authorization.
## Linked Issues or Issue Description
Refs #22213
**What happened?**
An agent searched its assigned tools and then called
`paperclip_call_assigned_tool` with a name that is almost the returned
alias. For example, one digest character was missing, or the agent used
the digest of the read tool with the name of the submit tool. The call
failed with `assigned_mcp_tool_unknown: name must be an exact name
returned by paperclip_search_assigned_tools. Search assigned tools again
and use the returned name.` In observed runs, the agent made more failed
calls with other wrong names.
**Expected behavior**
The call is still rejected. The error also shows the closest assigned
names that the agent can use, so that the agent can correct the name
directly.
**Paperclip version or commit**
`master` at
|
||
|
|
806440d12c |
feat(runner): relaunch a released task as the next run after a restart (#22343)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - An environment plugin can keep a warm task for an agent session. After each turn, Core releases the task's Runner, and the next run of the session resumes it > - #22288 added `resumeIdentityVersion: 1`: for a provider that stops a released Runner, Core rotates the session to the next run and the provider starts the Runner again directly as that run > - Core takes that path only while it still holds the released session in memory. After a Core restart, it recovers the released task through the older hand-off: it resumes the task as the previous run, then switches the Runner's authority to the new run > - So a provider that advertises the capability still has to keep the hand-off for every follow-up after a Core restart, and cannot drop it > - This pull request makes restart recovery take the same path when the provider advertises the capability > - The benefit is that a provider with the capability gets one start shape for a released task, before and after a Core restart, and can retire the hand-off ## Linked Issues or Issue Description Follows #22288. **What existing behavior does this improve?** The first run of a warm plugin session after a Core restart, when its task was released and its provider advertises `resumeIdentityVersion: 1`. **Subsystem affected** The native session executor and the plugin Runner task owner. **Current behavior** After a restart, Core finds the released source on disk (`inspectRemoteWarmSessionRecovery`), creates a backend that adopts the task, and calls `recoverSession`. The task owner calls `resume` without `runner`, the provider starts the Runner as the previous run, and Core hands it to the new run. **Proposed behavior** When the provider advertises the capability, Core recorded the build the task was released on, the process configuration is unchanged, and the session is not moving to another task, Core treats the recovery like a cached released session. It revalidates the recovery, loads the warm checkpoint, and opens a new backend on the same task with `relaunchReleased`. A new task owner takes over the submitted task without adopting a Runner process, prepares the claimant run with the released source as `priorIdentity`, and calls `resume` with `runner`. Every other recovery keeps the hand-off. **Reason and benefit** A provider that advertises the capability no longer needs the hand-off for its own tasks, after a restart or not. ## What Changed - Executor: a remote warm recovery with a released source, a recorded build, a reusable process configuration and no session move, on a provider that advertises the capability, revalidates the recovery and becomes a relaunch: `relaunchReleased` with the released source and build, the warm checkpoint, and no `remoteWarmRecovery` for the backend. The startup context ends as for a cached relaunch. - Executor: the relaunch's task owner can now come from the new backend (`onPluginTaskOwner`), so the unavailable-reuse fallback and the rotation revert work without a retained owner. Without an owner, no relaunch can have started, so the revert applies. - Backend: a relaunch neither stops a resumed task that has no durable binding nor resolves a `resumeFrom` task. - Task owner: an owner created with `relaunch` and the capability takes over an already submitted task, as an adopting owner does, but adopts no process: its prepare sends the released source as `priorIdentity`, and its launcher calls `resume` with `runner`. - `doc/plugins/PLUGIN_ENVIRONMENT_TASKS.md`: Core prepares the claimant run before the resume, also after a restart, and a provider must accept that prepare without state kept in memory. ## Verification - `server`: `npx vitest run src/services/native-runtime/plugin-runner-release-resume.integration.test.ts`: new `adopted restart relaunch` cases for Codex and Claude, with real runnerd processes. Core restarts while the task is released; the next run relaunches the task as itself, with no claim, one inspection and no second submit. The existing `adopted relaunch` case now relaunches both follow-ups, since the idle close also recovers through this path. - `server`: `plugin-runner-task.test.ts`: a new owner relaunches without submitting or adopting, and prepares with the released source; without the capability it prepares a new task. - `server`: `plugin-runner-release-resume.integration.test.ts` and `plugin-runner-eviction.integration.test.ts`: 61 passed. `native-session-executor.test.ts`: 1535 passed, 7 skipped. `plugin-runner-task.test.ts`: 118 passed. - Typecheck: `server` passes. - Red-green: with the executor lane turned off, both `adopted restart relaunch` cases fail. Without the task owner change, the new-owner relaunch test fails. ## Risks - Only providers that advertise `resumeIdentityVersion: 1` see a change. Recovery without a recorded build, with a changed process configuration, or for a session moving to another task keeps the hand-off. - The provider sees a `prepare` for the claimant run on a released task right after a Core restart. A provider that tracked unclaimed released tasks only in memory must handle that prepare (the doc now says so). - A Core restart in the middle of this path is still not qualified, as for the cached relaunch. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), through Claude Code with tool use (code search, editing, local test runs). ## 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 🤖 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> |
||
|
|
46dde54f52 |
fix(cloud): migrate run evidence during online preparation (#22337)
Drive bounded run-log and provider trace migration pages during online durable-data preparation. Share the page owner and settled-native archive rules with background migration, preserve active-source and storage-integrity guards, and report fresh page results. Keep canceled transfers owned and tracked until the underlying operation settles. Retain page cursors across the preparation budget. Verified 52 focused tests, including embedded PostgreSQL and object storage, server typechecking, and all 58 successful PR checks. Greptile 5/5 with no unresolved review comments. Co-Authored-By: Paperclip <noreply@paperclip.ing> |
||
|
|
264beefeff |
fix(tools): retry a tool audit write that loses a deadlock instead of failing the call (#22329)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Agents call connector tools through the tool gateway. The gateway writes a `tool_call_events` audit row for each step of a call. > - The audit insert has foreign keys to `companies`, `agents`, `heartbeat_runs` and `issues`. Postgres takes a key-share lock on each parent row, in trigger order: company, agent, run, issue. > - Other writers lock the issue row and then the run row. When such a transaction holds the issue and then asks for the run, while the audit insert holds the run and waits for the issue, Postgres detects a deadlock and aborts the audit insert (`40P01`). > - The gateway then returns the raw `Failed query: insert into "tool_call_events" ...` error to the agent. The agent does not get the tool result. The same call works when the agent sends it again. > - This pull request runs the audit insert through the shared bounded retry that #20971 added for the same lock cycle on `workspace_operations`. > - The benefit is that a short lock conflict no longer fails a connector call or loses its audit row. ## Linked Issues or Issue Description **What happened?** Some connector calls fail with `Failed query: insert into "tool_call_events" ...`. This happens most often when an agent sends several tool calls in parallel in one run. The failed call waits for some seconds, then fails. The other parallel calls succeed. The same call succeeds when the agent sends it again. The Postgres cause is `deadlock detected` (`40P01`). **Expected behavior** A transient lock conflict does not fail the tool call. The gateway writes the audit row and returns the tool result. **Steps to reproduce** 1. Transaction A: lock the issue row `FOR UPDATE`. 2. Call a connector tool for a run on that issue. Its `tool_call_events` insert takes key-share on the company, agent and run rows, then waits for the issue. 3. Transaction A: lock the run row `FOR UPDATE`. 4. Postgres reports a deadlock. Before this change the audit insert is the victim, and the tool call fails with the database error. **Additional context** The new test reproduces this with two real transactions on embedded Postgres. Transaction A gets a longer `deadlock_timeout`, so the audit insert is always the victim, as in production. The failing statement in the test has the same column list and the same placeholder shape as the production error. Refs #20971 Refs #21703 Open PRs #15830 and #16596 make the audit insert non-fatal. That approach drops the audit row. This change keeps the row. ## What Changed - `server/src/services/tool-gateway.ts`: `writeToolCallEvent` runs its `tool_call_events` insert through `retryTransientLockContention`. The helper retries only lock timeout, deadlock and serialization failure (`55P03`, `40P01`, `40001`): 5 attempts, with 100 ms × attempt backoff. Other errors fail as before. - `server/src/__tests__/tool-gateway-connector-telemetry.test.ts`: new test with a real two-transaction deadlock between an issue-then-run locker and the audit insert of a real `executeTool` call. The fixture now also returns the issue. ## Verification - Failing before the fix: `cd server && npx vitest run src/__tests__/tool-gateway-connector-telemetry.test.ts -t "loses a deadlock"` failed. `executeTool` rejected with `Failed query: insert into "tool_call_events" ...`, cause `deadlock detected`, code `40P01`. - Passing after the fix: the same test passes. I ran it 3 times. - The full `tool-gateway-connector-telemetry.test.ts` file passes (9 tests). - `tool-gateway-service.test.ts` passes (194 tests). - Not run: `pnpm verify` and the server typecheck. The local sandbox has not enough memory and disk for them. CI runs both. ## Risks - Low risk. Only the `tool_call_events` insert retries, and only on the three contention codes. - Each attempt is a new single-statement write. A deadlock victim's statement rolls back completely, so a retry cannot write a duplicate row. - The worst added delay is about 1 s of backoff across 5 attempts, and only when the lock conflict continues. - Authorization, screening and approval checks do not change. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude Code with tool use (shell, file edits, local test execution on embedded Postgres). ## 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: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
87ef7097b6 |
refactor(wake-queue): own blocked admission deferral (#22332)
## Thinking Path > - Paperclip runs agents in response to work on a task. > - A person can leave a comment while execution recovery holds that task. > - Wake-queue checks the recovery gate under the task lock. Heartbeat used to choose how to save the blocked input. > - The deferred-work worker later retries the saved receipt by ID. > - This change gives wake-queue responsibility for saving the input before it confirms deferral. ## Linked Issues or Issue Description **Current behavior** The gate and the write that makes a blocked wake recoverable have different owners. Heartbeat also reports an admitted deferral when an update to an existing receipt matches no row. **Proposed behavior** Let the recovery admission operation save the first receipt or update the existing one in the same transaction. Confirm admission only when the write succeeds. Keep replaceable automatic signals on their existing diagnostic path. **Reason and benefit** Changes to recovery admission can now be checked against one rule. A blocked comment must have a durable receipt and remain recoverable across delivery attempts. Related changes include [#22292](https://github.com/paperclipai/paperclip/pull/22292) and [#22290](https://github.com/paperclipai/paperclip/pull/22290). ## What Changed - Added a transaction-bound deferral operation to wake-queue recovery. It handles existing receipts, saved input, and replaceable system signals. - Scoped retry updates to the company, issue, agent, deferred status, and receipt ID. A stale receipt cannot confirm admission or cause a new receipt to be inserted. - Kept case refusals and issue state callbacks in heartbeat. A saved comment uses the existing delivery worker and post-commit effects. ## Verification - Retried a saved comment by receipt ID through the real heartbeat and run-control entry points. While the hold remained, no run started. After the hold cleared, repeated retry delivered the comment to exactly one run. - Forced a rollback after the wake-queue Postgres adapter saved a receipt. The test observed the receipt within the transaction and confirmed its absence after rollback. Tested missing receipts and receipts for another issue or agent. The admission application test covers error propagation and post-commit effects when the transaction fails. - The test-only revision `9f443f9e6b` passed 9 focused PostgreSQL and recovery checks and all 15 issue-wake admission application tests. - The preceding production revision `eb37328472` passed the server TypeScript check, the module boundary check, and 498 tests across five queue and recovery suites. Twelve pairs of ordinary comments issued the same SQL before and after that production change (42 statements for a fresh wake and 35 for a join). - Both updated test files passed in full (249 tests). [CI attempt 3](https://github.com/paperclipai/paperclip/actions/runs/44572369812/attempts/3) passed on `9f443f9e6b` after retrying interrupted jobs. [Standard Greptile review](https://github.com/paperclipai/paperclip/pull/22332#issuecomment-7014835241) scored the same commit 5/5 with no open findings. ## Risks The affected path handles blocked admissions that may race a retry or a reassignment. Existing recovery gates, saved comment IDs, receipt identity, and notifications must survive that race. This change has no migration or new worker. The healthy admission path is expected to issue the same SQL. ## Model Used OpenAI Codex with GPT-6.2 Sol for implementation and verification. Codex directed and reviewed the change. ## 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> |
||
|
|
417802ca87 |
fix(plugins): refresh unchanged-version bundle descriptions (#22295)
Refresh known display descriptions in same-version bundled plugin registrations only when every behavioral field matches. Compare manifests in their persisted JSON form and await bundle reconciliation before final volume-free package qualification. Verified 77 focused tests, server typechecking, and all 59 successful PR checks. Greptile 5/5 with no unresolved review comments. Co-Authored-By: Paperclip <noreply@paperclip.ing> |
||
|
|
b7177db6aa |
fix(telemetry): report a Paperclip runner agent's underlying harness as adapter_type (#22324)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The server sends product telemetry. Two events describe agent work:
`agent.task_run` and `agent.task_completed`.
> - Each event has an `adapter_type` dimension. The generated telemetry
contract gives this dimension a fixed enum.
> - A Paperclip runner agent stores `paperclip_runner` as its adapter
type. The enum does not have this value.
> - The collector and Cloud direct delivery change a value that is not
in the enum to `other`.
> - Thus, as more agents use the runner, the adapter breakdown in
analytics becomes mostly `other`. The data is not lost, but it is in one
bucket.
> - This pull request makes a runner agent report the harness that it
runs, for example `claude_local` or `codex_local`.
> - The benefit is that the adapter breakdown shows the real harness
again.
## Linked Issues or Issue Description
Refs #8818 (this PR added the generated telemetry contract and its
`adapter_type` enum).
I did not find an existing issue. This is the bug description:
**What happened?**
`agent.task_run` and `agent.task_completed` send the stored
`agents.adapter_type`. For a Paperclip runner agent, this value is
`paperclip_runner`. The `adapter_type` enum in
`packages/shared/src/telemetry/generated/paperclip-telemetry.ts` does
not include `paperclip_runner`. The telemetry normalizer changes the
value to `other`. In analytics, almost all runner agent events show
`adapter_type = other`.
**Expected behavior**
A runner agent reports the harness that it runs. The server already
resolves this harness with `agentHarnessType()` from
`@paperclipai/shared`. For example, a runner agent with the Claude ACP
configuration must report `claude_local`.
**Steps to reproduce**
1. Create a Paperclip runner agent (`adapterType: "paperclip_runner"`).
2. Let the agent complete a heartbeat run, or let it set a task to
`done`.
3. Look at the `agent.task_run` or `agent.task_completed` event.
`adapter_type` is `paperclip_runner` before delivery, and `other` after
normalization.
**Paperclip version or commit**
`master` at
|
||
|
|
deacaf727c |
feat(connections): guided AWS role setup with a per-connection CloudFormation template (#22233)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The AWS connector (#22195) lets agents use AWS with credentials minted per connection. Its role method stores no AWS keys > - That method needs the customer to create an IAM role that trusts exactly one Paperclip connection, but setup only offered the generic form and a doc > - The connect API also refused the draft step this method needs, so the role method could not be set up through the UI at all > - This pull request adds a guided setup screen. Paperclip saves a draft, hands the user a prompt for their own agent that creates the role, takes back the role ARN the agent reports, and tests the same draft. CloudFormation and IAM steps are there under "Or do it by hand" > - The benefit is that a person can connect AWS without stored keys and without typing account details, using a template AWS has validated ## Linked Issues or Issue Description Refs #22195. **Subsystem affected** Connections (AWS connector setup), UI, tool-access API. **Problem or motivation** The AWS role method must save a connection before AWS can trust it. The API rejected `saveDraft` for every method except custom MCP servers, so the UI could not complete this flow. There was also no screen that showed the issuer, the subject, the trust policy or a template. **Proposed solution** - The connect API accepts `saveDraft` for methods that declare `credentialMinter`. - `GET /tool-connections/:id/aws-setup` returns the setup values and a CloudFormation template generated for that connection. - A new `AwsRoleSetup` step runs between saving the draft and testing it. The role is named after the connection and CloudFormation fills in the account, so the first form no longer asks for a role ARN; the user pastes it back once the role exists. **Alternatives considered** - A one-click CloudFormation quick-create link. Rejected: AWS accepts quick-create templates only from Amazon S3, so Paperclip would need to host a public template bucket. The screen offers a download and a console link instead. - Instructions in a doc only. Rejected: too many hand-copied values. - Asking for the role ARN up front. Rejected: the role does not exist yet, so users had to invent an ARN and then match it exactly. - Letting the user's agent report the role ARN to Paperclip itself, through a short-lived link. Not done here: it needs a new unauthenticated endpoint (and a Paperclip Cloud front-door change). The user pastes the ARN instead. ## What Changed - `packages/shared`: - The `saveDraft` validation allows methods with minted credentials. - New `AwsConnectionSetup` type. - `server/src/services/connectors/aws/setup.ts` builds the setup values: - The issuer, audience and connection subject. - The provider host and the trust policy. - A CloudFormation template with an optional identity provider (`CreateIdentityProvider`), a role named `paperclip-<connection id>`, `AccessPolicyArn` (`ReadOnlyAccess` by default for read-only connections) and `AWSMCPSignInOAuthAccessPolicy`. The account comes from CloudFormation, so the template needs no edits. - The service method `getAwsSetup` and the route `GET /api/tool-connections/{connectionId}/aws-setup`: - The route requires `connections:configure`. - It returns 422 for a connection that is not an AWS role connection. - It reports whether the issuer key is published and any role ARN already saved. - It returns `available: false` (`address_changed`) when the instance address changed after the draft was saved, since a role set up for the old address could never pass the test. - It is registered in OpenAPI. - UI: - The AWS form no longer shows a Role ARN field (it is hidden with an empty default). - `AwsRoleSetup.tsx` shows, by default, only "Set it up with your agent" (a copyable prompt that checks the AWS account, deploys the template with `aws cloudformation deploy`, and reports the role ARN) and a field to paste that ARN. "Or do it by hand" reveals the CloudFormation steps (download, console link, parameter notes, IAM acknowledgement) and the IAM console / AWS CLI steps with copyable values; the CLI commands read the account ID themselves. - It shows an access-key message when AWS cannot reach the instance, and asks the user to save again when the instance address changed. - Failed tests appear in place. AWS error codes show the server's own plain message, because the shared error copy replaces every 502 with "temporarily unavailable". - `useAwsRoleSetupStep` owns the AWS sequence; `ConnectionSetupFlow` only asks it for request options, hands back results and renders its step: - The first Connect for `aws-role` saves a draft and opens the AWS step. - "Test connection" resumes the same draft with the pasted role ARN. - Back keeps the draft, so a later Connect updates it and does not create a second one. Returning to an unfinished draft reopens the step. - Docs: the `doc/connections/AWS.md` setup section and the plan's phase table. The SDK public input pins are refreshed. ## Verification - `server/src/__tests__/aws-mcp-connector.test.ts` covers a new API-level case through the real route validation: - Saving an `aws-role` draft over HTTP works without a role ARN, and stores the keys the screen uses to reopen it. - `aws-setup` returns the issuer, subject and the connection's role name. - The template's trust condition keys equal `<issuer host>:aud` and `<issuer host>:sub`. - The template provider URL equals the issuer. - After an address change it returns `address_changed`, and saving the draft again records the new address. - An access-key connection returns 422. - No response field looks like a secret. - `ui/src/features/connections/AwsRoleSetup.test.tsx` covers: - Only the agent setup shows by default; Test connection stays off until a valid role ARN is pasted, then sends it. - A saved role ARN is filled in. - The by-hand steps and CLI commands; the agent prompt for read-only and full access. - The template download (filename and object URL cleanup). - The unreachable-instance message. - The in-place error and the address-changed message. - The AWS message mapping. - `ui/src/pages/apps/AppsConnect.test.tsx` covers the full two-step flow: the form has no Role ARN field, the first Connect sends `saveDraft: true` with no role ARN and does not finish, the AWS step loads the setup, and "Test connection" resumes `aws-draft` with the pasted role ARN and finishes. A second test reopens the step for a returning draft. - Red/green: - Removing the API change fails the API test. - Removing the draft-first wiring fails the flow test. - Totals: server AWS, OpenAPI and connector tests (75), shared `app-definitions` (42), UI connections and apps pages (1108). Typecheck is clean for shared, server, UI (except Storybook's generated catalog, which this worktree has not built) and all four server test-tree layers. - Browser, on a real dev server with an HTTPS public address: - AWS appears in Connectors with its logo. - The form has only region and access level. Connect saves the draft (reusing an earlier one) and shows only the agent prompt and the role ARN field; "Or do it by hand" reveals the CloudFormation and IAM steps. - The copied prompt names the connection's role and stack, and the template. - Test connection with a pasted role ARN showed AWS's refusal in place (no such role, placeholder issuer), as expected. An earlier run found the generic 502 copy problem, which is fixed and re-checked. - AWS CloudFormation `validate-template` (dev account, read-only) accepts the current generated template (role named after the connection) and reports `CAPABILITY_NAMED_IAM`. The screen tells the user to acknowledge it. - Not run: an agent actually running the prompt and creating a stack in AWS, and Paperclip Cloud staging. ## Risks - The feature is still behind `enableAwsConnector` (off by default). No migration. - The template creates IAM resources in the customer's account, and the customer must acknowledge that. The role trusts only this connection's subject. - If the customer already has an identity provider for the issuer and leaves `CreateIdentityProvider` at true, AWS fails the stack with a clear error. The screen explains the parameter. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use (shell, file edits, the in-app browser against a local dev server, AWS CLI `validate-template` in the dev account, an exploration subagent). ## 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: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Paperclip <noreply@paperclip.ing> |
||
|
|
3b978692ee |
fix(github): end a superseded automatic review with a clear outcome (#22218)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for work
> - The GitHub bot can do an automatic pull request review. An agent run does the review with review tools.
> - Each automatic run has authority for one commit only: the head commit of its pull request event.
> - When a new push moves the head during the review, the review tools refuse the run. This is correct.
> - But the refusal told the agent to "continue with the newest authorized PR event". The agent cannot do that. Agents call the refused tools again, then post the stale review as an ordinary comment.
> - This pull request makes the refusal a clear, terminal "superseded" outcome. It says if a newer review is already queued and tells the agent to stop.
> - The benefit is fewer wasted tool calls and no stale review comments on the pull request. Commit-specific authority does not change.
## Linked Issues or Issue Description
**What happened?**
An automatic pull request review starts for commit A. During the review, the author pushes commit B. Each review tool call (for example `read_pull_request`) then fails with "This automatic review was requested for an older pull request head. Continue with the newest authorized PR event or an authorized manual request." Agents call the tools again several times. Then they post their review as an ordinary pull request comment, because the comment tool does not check the head.
**What did you expect?**
The refusal tells the agent that the review is superseded. It names the old and new commits. It says if a newer automatic review for the new head is already queued on the task. It tells the agent to stop, not to call review tools again, and not to post the review as a comment. The error has a machine-readable reason code and is not retryable.
**Steps to reproduce**
1. Configure the GitHub bot for automatic reviews.
2. Open a pull request. An automatic review run starts.
3. Push a new commit while the run reviews.
4. The run calls a review tool. The tool refuses with the old, unclear message.
## What Changed
- `server/src/services/chat-github-reviews.ts`: the stale-head check now builds the error in a new `supersededAutomaticReview` helper. The helper looks for a newer automatic delivery for the current head of the same pull request. It matches the repository id and pull number that the event saves, because a new delivery has no conversation id until it is processed. It counts only deliveries that are newer than the run's own event, in the states `received`, `processing`, `processed`, or `retry`. The query stays scoped to the company and endpoint. The 409 error message names both commits, says if a newer review is queued, and tells the agent to stop. The error details carry `reasonCode: "github_review_superseded"`, `retryable: false`, `requestedCommit`, `currentCommit`, and `newerReviewQueued`.
- The first sentence of the message does not change, so existing logs and searches still match.
- The run still cannot read or review the newer head. Authorization does not change.
- `server/src/__tests__/chat-channels.integration.test.ts`: the existing stale-head assertion now checks three outcomes: a newer review is queued and processed, a newer review is still waiting with no conversation id, and no newer review is queued (the head moved with no event).
## Verification
- Failing before: `cd server && npx vitest run src/__tests__/chat-channels.integration.test.ts -t "admits signed PR events into an ordinary assigned task"` with only the test change. The test failed: `expected Error: This automatic review was requeste… to match object { status: 409, details: { reasonCode: "github_review_superseded", … } }`, and the received error had `details: undefined`.
- Passing after: the same command with the fix: `Tests 1 passed`.
- Failing before (second case): the test sends a second `synchronize` event and does not process it, so its delivery has no conversation id. Before the identity match, the test failed: expected `newerReviewQueued: true`, received `newerReviewQueued: false`. After the fix, the test passes.
- `npx vitest run src/__tests__/chat-channels.integration.test.ts -t "GitHub agent review workflow"`: 300 passed.
- `pnpm --filter @paperclipai/server typecheck` (layered typecheck): passed.
- `pnpm verify` selected 2,925 of 3,792 test files because many modules import this service. I stopped it before the end. It reported no failures before I stopped it. Required CI gives the full coverage.
## Risks
- Low risk. The change applies only to the error path when an automatic review's head is stale.
- The error path does one more indexed-scope query on `chat_deliveries` (endpoint and conversation). This query runs only when a refusal occurs.
- The message text changes after its first sentence. Code that matches the full old text would need an update. No code in this repository does.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), by Anthropic, in Claude Code with tool use and code 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
- [ ] 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
- [ ] I will address all Greptile and reviewer comments before requesting merge
Related: #21290 (completes the check run of a superseded head; a different code path).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
||
|
|
575ef12575 |
feat(responsibilities): file company skills under responsibilities (#22275)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - A responsibility shows the skills of the agents doing its work. People cannot say which skills a responsibility needs. > - The maintainer chose to file skills under responsibilities like projects, tasks and routines. > - Agents also need to set a skill's catalog details without rewriting its SKILL.md. > - This pull request lets people and agents file, move and remove company skills under a responsibility, and adds `update_skill_details`. > - The benefit is that a responsibility lists the skills it needs, beside the skills its agents already hold. ## Linked Issues or Issue Description Refs #22253, #22261 and #22274; this pull request is stacked on them. **Subsystem affected** Database (`responsibility_links`), shared types and validators, server responsibility service and routes, Dashboard versions, native runner tools, and the responsibility page UI. **Problem or motivation** Skills under a responsibility are only computed from the agents doing its work. A person cannot record that "Hiring needs interviewing", and an agent cannot file a skill when it maps work for a person. **Proposed solution** Add a nullable `skill_id` to `responsibility_links` and allow it as the one target of a link. Show filed and computed skills together. Let the file, unfile, lookup and link routes and tools take skills. Keep filed skills in Dashboard versions so undo covers them. Add a small live tool for a skill's tagline and categories. **Alternatives considered** Keeping skills computed only, and giving the skill to the agent that runs the responsibility, was the other option. It was not chosen. Extending `update_skill` would change its scenario contract, whose mock needs `markdown`, so the details tool is separate. ## What Changed - Review fixes: the default responsibility view's Skills "+" adds an existing skill, removes a filed one, or opens an agent's skills page. A newest Dashboard version without a skill list is upgraded in place, so the first skill filed after it is undone. Undo files again, or removes, only skills the restoring person can see. A read scope without a skill condition sees no filed skill. `update_skill_details` with only `skillId` is a no-op, as its schema allows. - Migration `0499`: add `responsibility_links.skill_id` (FK to `company_skills`, on delete cascade). Widen the single-target check to four targets. Add a unique `(responsibility_id, skill_id)` index and a `skill_id` index. The migration is idempotent and online-compatible (NOT VALID then VALIDATE, and the indexes are built CONCURRENTLY). It is listed in `MIGRATIONS_WITH_TOP_LEVEL_STATEMENTS`. - Shared: `ResponsibilityLink.skillId`; `ResponsibilitySkillSummary.linkId` and `computed`; `skillId` in the link and lookup schemas; `skill` in `RESPONSIBILITY_FILE_ITEM_KINDS`; optional `skillIds` in Dashboard snapshot links. - Server: filing checks the reader's skill visibility (`skillAccessService`). The detail merges filed and computed skills into one card each. Lookup accepts `skillId`. Dashboard capture, restore and summary include filed skills. A version without `skillIds` leaves filed skills as they are when it is restored. - Tools: `file_under_responsibility`, `remove_from_responsibility` and `find_responsibilities_for` accept `kind: "skill"`. `get_responsibility` returns `linkId` and `computed` for each skill. Add `update_skill_details` (tagline and categories). - UI: the responsibility page has "Add existing skill". A filed skill shows "Filed here" and a remove button. Computed skills keep their holders. ## Verification - Server: the `responsibilit*` tests (new: file, find, move and unfile a skill; one card for a skill that is both filed and computed; undo of a filed skill from the Dashboard history), `skill-tools.test.ts` (new `update_skill_details` cases), `responsibility-tools`, `routine-tools`, `routines-routes`, `paperclip-runner-tool-authority`, `runner-api` and `openapi-routes`: 24 files, 2723 tests passed. - UI: responsibility page and component tests (16 files, 158 tests, including a new filed-skill test) pass. `pnpm --filter @paperclipai/ui typecheck` passed. - `@paperclipai/db` `check:migrations` passes and reports the override. The snapshot drift test passes. `tsc` passes for `db`, `shared` and the server layers. - Runner: catalog and semantic-tool tests (317) pass. All generator checks pass. ## Risks - The migration changes a check constraint on `responsibility_links`. The replacement accepts every row that the old check accepted. It is swapped as NOT VALID and then validated. The previous release never sets `skill_id`. - Deleting a company skill removes its links (cascade). - Filed skills follow the reader's skill visibility. A skill the reader may not see is not listed. ## Model Used Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and code 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 - [ ] 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: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Paperclip <noreply@paperclip.ing> |
||
|
|
b7319eb581 |
feat(routines): let agents list and change their person's routines in plain terms (#22274)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Routines are recurring work that an agent runs on a schedule, webhook or request. People file them under their responsibilities. > - #22253 and #22261 let agents read and change areas and responsibilities. Agents still have no dedicated routine tools, and they can change only routines assigned to themselves. > - When a person says "move my weekly digest to Monday mornings" or "map my routines to my responsibilities", the agent must use the generic API, write cron, and it is refused for the person's routines. > - This pull request adds `list_routines` and `update_routine`. It also lets an agent change routines that the person its run works for is responsible for. > - The benefit is that an agent can find routines under no responsibility, file them, and change their schedule in plain terms. Each change is a routine revision the person can restore. ## Linked Issues or Issue Description Refs #22261 (phase 2; this pull request is stacked on it), #22253 (phase 1). **Subsystem affected** Server (routine routes, native runner tool authority), the native runner tool catalog, and the `paperclip` skill. **Problem or motivation** An agent can list and change only its own routines through the generic API. It cannot change the schedule of a routine its person is responsible for. It must write cron expressions, and it cannot find the routines that are filed under no responsibility. **Proposed solution** Make the existing scenario operation `list_routines` live, with filters for words, status, agent, project, responsible person, a responsibility and "unfiled". Add `update_routine` for the title, instructions, agent, project, status, priority, a plain `schedule`, and filing under a responsibility. Let an agent manage a routine when the person its run works for is responsible for it. Handing the routine to another agent needs that person to have `tasks:assign`. **Alternatives considered** A new `routines` permission grant would add a setting with no current need. Routine revisions already give an undo path, so this change adds no new history. ## What Changed - `list_routines` is now live (it was a scenario-only mock) and keeps its scenario mock. - Add `update_routine`. A `schedule` such as `{ frequency: "weekly", dayOfWeek: "monday", time: "09:00", timezone }` maps to the routine's schedule trigger through the existing routine-offer cadence helpers. `schedule: null` turns the schedule off. `fileUnder` files the routine under a responsibility. - Add `server/src/services/routine-tools.ts`. It calls the routine routes with the run token. Fields and schedule go in one `PATCH /routines/:id` (one transaction and revision, guarded by `baseRevisionId`); filing follows, and if it fails after the routine changed the tool reports what was saved. Each part reports its own undo: the routine revision, or the Dashboard history for filing. - `PATCH /routines/:id` takes `schedule` (`{ cronExpression, timezone? }` or `null`) and replaces the schedule under the routine row lock, so racing changes leave one schedule. Without a zone it keeps the current schedule's, else uses the person's saved time zone, else answers 422. - `GET /companies/:companyId/routines` filters `q`, `status`, `assigneeAgentId`, `responsibleUserId`, `responsibilityId` and `unfiled=true` in SQL. - In `routes/routines.ts`, an agent may manage routines assigned to itself or routines its person is responsible for. On a routine the agent does not run, taking it from another agent (or handing it on), turning it on, changing its schedule (also through the trigger routes), starting a run, or restoring a revision requires that person's `tasks:assign`, as for a person. The person must have directed the run (see #22261). `routine.updated` activity records `onBehalfOfUserId`. - The routine and responsibility routes share one rule, `agentPersonInCompany` in `routes/agent-person-authz.ts`. - The catalog keeps each live action's `requiredClaims` (`list_routines` is `routines:read`). - The routine tools stay visible when Responsibilities is off. Only `responsibilityId`, `unfiled` and `fileUnder` need it. - Update `search_api` tool pointers, the routines reference, the skill section, the chat directive, the operation-groups spec and the pinned counts. ## Verification - Server: `routine-tools.test.ts` (new), `routines-routes.test.ts` (new: an agent changes its person's routine, hands it off only with `tasks:assign`, and is refused for another person's routine), the `responsibilit*` tests, `paperclip-runner-tool-authority` and `runner-api`: all pass. The first test in `routines-routes.test.ts` (Fireflies) times out at 15 s in my sandbox on a cold import, with or without this change. It passes with `--testTimeout=60000`. - Server `node scripts/typecheck-layers.mjs`: passed. - Runner: catalog, semantic-tool, eval, scenario and permission-policy tests (316) pass. All generator checks pass. ## Risks - Medium-low. Agents get write access to their person's routines. The route still checks the company, the routine revision guard and `tasks:assign` for a hand-off. The person can restore any earlier routine revision. - `list_routines` changes from a scenario-only mock to a live tool, so the reconciled catalog counts change. ## Model Used Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and code 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 - [ ] 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: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Paperclip <noreply@paperclip.ing> |
||
|
|
c0aa7751f8 |
feat(responsibilities): let agents change areas and responsibilities for their person, with undo (#22261)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - People keep their areas and responsibilities in Paperclip (experimental, `enableResponsibilities`). #22253 lets agents read them. > - Agents can still only propose. They cannot rename or archive an area, change an active responsibility, let one go, or move work between responsibilities in one step. > - A person who says "file my weekly routines under Sales" must then do it by hand. > - The maintainer chose this rule: an agent may make each change that its person could make, the person can undo it from the Dashboard history, and a permanent delete still needs the person's yes on a card. > - This pull request adds eight change tools and the server rules behind them. > - The benefit is that an agent maps work to responsibilities for the person, and the person keeps control through undo and the delete card. ## Linked Issues or Issue Description Refs #22253 (phase 1; this pull request is stacked on it). **Subsystem affected** Server (responsibility and area routes, Dashboard versions, native runner tool authority), shared validators and Dashboard types, the native runner tool catalog, the `paperclip` skill, and the Dashboard history UI. **Problem or motivation** An agent that works for a person can only propose areas and responsibilities. It cannot change active ones, archive or delete them, or move filed work in one step. Unfiling needs link IDs. There is no way for the person to undo an agent's change. **Proposed solution** When an agent acts for the person its run works for (`onBehalfOfUserId`) and that person directed the run (the run's own task is one they made, such as their chat, or their own message woke it; parent tasks do not count), apply that person's own rights: their own responsibilities, or anyone's for a company owner or admin; areas for any active member. Save each such change as a version of the person's Dashboard, so the existing history and Undo line show it under the agent's name. Make a permanent delete wait for an accepted confirmation card that the agent posted. Add `file` and `unfile` routes that take items by kind and ID, with an optional move. **Alternatives considered** One card for every change, or propose-only. The maintainer chose "act for me, with undo". A separate undo journal would need a new table and a new UI; Dashboard versions already have both. A new version cause needs a check-constraint migration; this change uses `change_set` with no `interactionId` instead. ## What Changed - Add tools `create_area`, `update_area`, `delete_area`, `create_responsibility`, `update_responsibility`, `delete_responsibility`, `file_under_responsibility` and `remove_from_responsibility`. They are standard-mode only and hidden while Responsibilities is off. - Add the writer rule for agents in `routes/agent-person-authz.ts` (`agentPersonInCompany`, `agentActsForResponsibilityOwner`), used by `routes/responsibilities.ts` and `routes/responsibility-areas.ts`. The person must have directed the run: a person can name anyone as a task's responsible person, and a run can also work for a routine's person or the company default, so those runs do not borrow that person's rights. An agent with no such person keeps the old propose-only rules. - The response names only the version of the responsibility's owner (for area changes, the acting person's), and `X-Paperclip-Dashboard-Owner` says whose history holds it; tools return `dashboardOwnerUserId`. A change Undo cannot reverse (the name, description, order or un-archiving of an area other people's proposed or active responsibilities share) saves no version and is not reported as undoable. - `/file` without `moveFrom` follows the `/links` rule, so `create_responsibility` with `fileItems` works for a proposal. - A title-only create is allowed for an acting agent. It is active by default and records the agent in `proposedByAgentId`. - Add `responsibility-agent-changes.ts`. In one transaction that holds each affected owner's Dashboard lock, it saves the dashboard before the change (when a person changed it by hand), runs the change on services bound to that transaction, and saves the result as a `change_set` version by that agent. The response names the version in `X-Paperclip-Dashboard-Version`. The tools say Undo only when a version was saved. - Dashboard snapshots now also hold each responsibility's filed items, description, "run by" agent, evidence, health override and note, and each area's description (optional fields). Restore puts them back. Older versions still restore as before. A matching older version is upgraded in place, so the first change after it compares and undoes in full. - Create and update accept `areaTitle`. The server finds or makes that area in the same transaction, so a refused change leaves no area. Agent creates reuse a live responsibility with the same title under a lock, so retries and parallel calls make no copies. - Add `POST /api/responsibilities/:id/file` (`items`, optional `moveFrom`: an ID or `all`) and `POST /api/responsibilities/:id/unfile` (`items`), each in one transaction. - Agent deletes need `confirmationId`: an accepted `request_confirmation` card that this agent posted, with target key `responsibility-delete:<id>` or `responsibility-area-delete:<id>`. Someone who may manage the owner must accept it, on the card or by a verified chat reply. The tools post the card (named after the item), return `awaiting_confirmation`, and delete on the next call after acceptance. - `DELETE /api/responsibility-areas/:id` accepts `moveResponsibilitiesTo`. Area changes and deletes save versions for everyone whose Dashboard shows the area. - Agent activity details now include `onBehalfOfUserId`. The Dashboard history shows "<agent>, for you" for these versions. `ResponsibilityDashboardVersionSummary` now has `interactionId`. - Update the OpenAPI registry and metadata, the `search_api` tool pointers, the skill, the API reference, the chat directive, the operation-groups spec, and the pinned counts and SDK source pins. ## Verification - Server: `vitest run` of the `responsibilit*` tests, `responsibility-tools.test.ts`, `openapi-routes`, `runner-api*`, `paperclip-runner-tool-authority` and `task-markdown` all pass. New tests cover these cases: acting-agent create, update and undo; file, move and undo; the rule for a person who may not manage the owner; delete only after an accepted card, including a verified chat reply; area delete with move and a version for the other owner; undo of a health override, an area description and an un-archived empty area; upgrade of an older version; an area by title that a refused change rolls back; parallel creates. - UI: `DashboardEditModule.test.tsx` and `responsibility-dashboard.test.ts` passed. `pnpm --filter @paperclipai/ui typecheck` passed. - Server `node scripts/typecheck-layers.mjs` passed. - Runner: catalog, semantic-tool, eval, protocol-action and permission-policy tests (284) passed. All generator checks pass. - I did not run the browser e2e suite locally. ## Risks - Medium. Agents that work for a person can now change and archive that person's responsibilities and areas without a card. Every change is a Dashboard version that the person can restore, and a delete still needs the card. - Undo restores titles, sentences, areas, order, status, filed items, description and the "run by" agent. It does not restore a bar or metric change; those stay in the metric history. - A restore of a version from before this change does not touch filed items, which matches the earlier behavior. - Undo of a rename or archive of an area that other people also use keeps its name, as the existing restore rule does for shared areas. - Manual edits do not take the Dashboard lock. A person's edit that commits while an agent's change is open can appear in that agent's version. - Changes to proposed or let-go responsibilities are not on a Dashboard, so they cannot be undone there. The tools say so. ## Model Used Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and code 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 - [ ] 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: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
c55de053f5 |
perf(wake-queue): skip detailed recovery reads on tasks without history (#22290)
## Thinking Path > - Paperclip keeps agents from resuming work that still has an execution owner or a recovery hold. > - Ordinary board tasks have no recovery record. > - Admission evaluates two detailed recovery queries for those tasks while it holds the issue row lock. > - The source-issue foreign key prevents another transaction from inserting or moving the first recovery record onto the locked issue. > - Use one indexed existence check there. Continue to check execution ownership and apply the complete policy to tasks with history. ## Linked Issues or Issue Description **What existing behavior does this improve?** Admitting board assignments and saved task comments. **Subsystem affected** Wake-queue’s PostgreSQL adapter for task admission. **Current behavior** Admission evaluates detailed recovery predicates even when a locked board task has no recovery history. **Proposed behavior** For a locked board task that did not require writer preservation, check for any recovery row for that company and task. An empty result skips the recovery predicates for that call. **Additional context** Depends on #22292, which enforces recovery eligibility after wake-queue acquires the task lock. #22159 and #21459 address separate recovery lifecycle decisions. ## What Changed - Preserve the independent ownership and lease check. - Use the existing detailed recovery logic when history exists. Include resolved records in the existence check. - Run the probe after acquiring the issue lock, in its own statement. Cover both orderings of a concurrent recovery insert and a record moved onto the issue. ## Verification At 83d4acd8bf the two query-shape tests failed on the parent and passed on the new implementation. All 425 tests across five suites passed on that revision, including all five focused PostgreSQL regressions. A normal user comment waiting on an uncommitted recovery record creates no run after the writer commits. Its deferred receipt retains the exact comment and recovery action. Server TypeScript and the module dependency check passed. The published head |
||
|
|
7ffc58a612 |
refactor(wake-queue): enforce recovery before task admission (#22292)
## Thinking Path > - Paperclip admits assignments and task comments while it holds the task lock. > - A task can have a recovery hold. An explicit continuation can authorize additional work. > - A wake can join an active execution after a provisional check. A fresh run must settle the continuation in the transaction that creates the run. > - Heartbeat previously received both admission functions before either check ran. > - Make the wake-queue module release each function after the corresponding recovery check passes. ## Linked Issues or Issue Description **What existing behavior does this improve?** Enforce recovery eligibility at the entry points that attach a wake to an issue execution or create a fresh run. **Subsystem affected** Wake-queue and heartbeat issue admission. **Current behavior** Heartbeat selects when to read the blocker and apply the explicit continuation before invoking the admission writers. **Proposed behavior** Wake-queue controls access to its two admission writers after the task is locked. The same recovery and continuation services decide which work may proceed. **Additional context** Depends on #22289. #22290 changes the storage cost of the blocker check in a separate layer. ## What Changed - Bind the recovery read to the issue and transaction selected by wake-queue. Read the current issue lock again after durable chat authorization when required. - Expose the busy writer after the preliminary continuation check passes. Expose the fresh writer after the transaction applies any required continuation. - Preserve heartbeat’s existing ordering for system fallback, budget and daily limits, task retry, and durable receipts. ## Verification On |
||
|
|
503268b806 |
perf(wake-queue): preflight task admission without loading execution context (#22289)
## Thinking Path > - Paperclip uses task admission to turn assignments and comments into queued work. > - Wake-queue owns the issue-admission transaction. Heartbeat previously loaded full execution context to decide whether a conversation wake could proceed. > - After the conversation preflight, task state can change before admission obtains its lock. > - Wake-queue now exposes the preflight decision and obtains only the fields it needs. It provides current task attribution from the locked row. > - Heartbeat uses the existing responsible-user and routine rules when it creates a run. ## Linked Issues or Issue Description **What existing behavior does this improve?** Admitting board assignments and saved task comments. **Subsystem affected** Server task admission. **Current behavior** Conversation preflight and fresh-run attribution load full task execution context from heartbeat, including chat joins. **Proposed behavior** Give wake-queue ownership of conversation preflight and its PostgreSQL read. Use the issue row already locked by wake-queue for fresh-run attribution. **Additional context** Builds on #22280 and #22282. #17396 covers a separate workspace inspection on task context reads. ## What Changed - Give heartbeat a preflight decision. Keep storage and the five-field query inside wake-queue. - Reuse the conversation and retry predicates for all callers. Keep the locked recheck after preflight, including durable chat authorization. - Supply the task's responsible user, parent and routine origin from the current locked row. A company-only admission supplies no issue. ## Verification On `b89bed954a`, all 307 tests passed across the wake-queue preflight and release application suites, heartbeat queue and run-preparation suites, and Slack conversation lifecycle suite. The integration suites used embedded PostgreSQL. Coverage includes the owner 403, a conversation settling before admission locks the issue, saved-comment attribution after reassignment, and routine ownership written inside the admission transaction. The layered server typecheck and module dependency check passed on the same revision. In a repeated local comparison of base `90d985b8b9` and PR head `b89bed954a`, we measured 34 samples per revision, scenario, and recovery-history state, alternating the two revisions in ABBA order. Server-side admission medians were: | Recovery history | Assignment | One comment | Two serial comments | | --- | ---: | ---: | ---: | | Empty | 23.45 → 21.80 ms | 23.95 → 23.00 ms | 47.30 → 45.40 ms | | Resolved | 23.35 → 21.30 ms | 23.70 → 22.05 ms | 46.70 → 45.40 ms | Typical SQL statements fell from 36/37/74 to 35/36/73 for the three scenarios. Lock statement counts were 2/2/6 for both revisions. Throughput varied under local contention. These are local measurements. Standard Greptile scored the exact head 5/5 with no review threads. [Greptile review](https://github.com/paperclipai/paperclip/pull/22289#issuecomment-6999578088) GitHub CI passed on the exact head after one targeted retry of the serialized server shard. The initial status-card maintenance case timed out waiting for idle, passed when run locally on the same revision, and passed in the retried shard. [CI workflow attempt 2](https://github.com/paperclipai/paperclip/actions/runs/44458613437/attempts/2) ## Risks An early decision can go stale, and the caller must preserve authenticated actor identity. The locked path retains its own eligibility checks. A regression exercises the gap between the two decisions. An attribution test inserts its evidence inside the transaction to detect a read through a different connection. ## Model Used OpenAI GPT-6.2 Sol (gpt-6.2-sol) implemented the change. OpenAI Codex reviewed and qualified it. ## 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 |
||
|
|
ffcd49f6aa |
feat(responsibilities): let agents read a person's areas and responsibilities (#22253)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - People keep their areas and responsibilities in Paperclip (experimental, `enableResponsibilities`). Agents chat with them about this work. > - Agents have no dedicated tool to read a person's responsibilities. The only path is the generic `search_api` and `call_api` fallback. > - That path needs the person's user ID, and nothing in a chat tells the agent that responsibilities exist. When the feature is off, every route returns a 404 that looks like "nothing there". > - So a chief-of-staff agent asked the person "what are your responsibilities, or where are they written down?" when Paperclip already had them. > - This pull request adds three read tools, makes the owner default to the person the run works for, and tells agents in chats how to use the tools or that the feature is off. > - The benefit is that an agent reads and maps a person's responsibilities itself. This is phase 1 of 4. Later pull requests add the change tools for areas, responsibilities, routines and skills. ## Linked Issues or Issue Description **Subsystem affected** Server (responsibility routes, native runner tool authority, chat prompt), native runner tool catalog, and the `paperclip` skill. **Problem or motivation** An agent in a chat cannot find a person's responsibilities. It has no dedicated tool. The list route requires `ownerUserId` from an agent, and the chat does not give the agent that ID. The chat prompt does not mention responsibilities. When the experiment is off, the 404 does not tell the agent that the feature is off. The agent then asks the person to list their responsibilities again. **Proposed solution** Add three optional native tools: `list_responsibilities`, `get_responsibility` and `find_responsibilities_for`. They call the existing routes with the run's agent token, so all route checks and the activity log stay the same. The owner defaults to the person the run works for. The routes return a `responsibilities_disabled` code while the feature is off. The tools are hidden while the feature is off, and the chat prompt then says that the feature is off. **Alternatives considered** Better `search_api` guidance alone still needs the user ID and many calls. A new read service in the tool authority would copy the route permission rules. The tools use the routes instead. ## What Changed - Add `list_responsibilities` (areas with their responsibilities, responsibilities with no area, totals, and company work filed under no responsibility), `get_responsibility` (one responsibility with its filed items, link IDs, skills and latest status report), and `find_responsibilities_for` (where a project, task or routine is filed; a task can be a `PAP-12` identifier). - Add `server/src/services/responsibility-tools.ts`. It calls the routes over HTTP with the run token and returns compact results with page links. - When an agent sends no `ownerUserId`, the responsibility list, create, summary, automation and dashboard routes use the person the run works for (`onBehalfOfUserId`). A run that works for no person still gets a 422 with a clear message. - The nine "not enabled" checks now throw one shared error. The 404 and its message do not change. The body now also has `code: "responsibilities_disabled"` and a remediation line. One `RESPONSIBILITIES_OFF_GUIDANCE` text is the remediation, the tool error and the chat prompt note. - `list_responsibilities` with `areaId` counts only that area. Archived areas are listed only on request. When only proposals are hidden, the tool says so. - `services/paperclip-api-loopback.ts` holds the tools' authenticated API call; the project tools use it too. - Show the tools only while the instance has Responsibilities on. A hidden tool that is called by name returns "Areas and responsibilities are turned off". - In standing chats, add an "Areas and responsibilities" prompt block: use the tools before you ask the person, or say that the feature is off. - `search_api` results for these routes now name the dedicated tools. - Add an "Areas and responsibilities" section to `skills/paperclip/SKILL.md` and to `references/api-reference.md`. Add one line to the chief-of-staff persona. - Register the tools in the runner catalogs. Regenerate the semantic contracts, the action catalog, protocol coverage, the operation-groups spec and the capability inventory. Update the pinned counts. ## Verification - `pnpm --filter @paperclipai/paperclip-runner exec vitest run src/catalog src/semantic-tools src/tools src/eval/workflow-evals.test.ts src/protocol-actions src/evals/native-execution.test.ts src/drivers/acpx/permission-policy.test.ts`: 276 passed. - All runner generator checks pass: protocol manifest, capability contract, capability inventory, protocol coverage, semantic contracts, semantic action catalog, operation groups, replay goldens, workflow traceability. - Server: `vitest run` of `responsibilit*` route tests, `responsibility-tools.test.ts` (new), `task-markdown.test.ts`, `task-context*`, `paperclip-runner-tool-authority.test.ts`, `runner-api.test.ts`, onboarding first-task tests and `user-facing-wording-guidance.test.ts`: 20 files, 2620 tests passed. - `node scripts/typecheck-layers.mjs` for the server: passed. - New tests cover these items: the owner default for an agent and the 422 without a person, the `responsibilities_disabled` code on every route, the tool projections, an identifier lookup, the "turned off" mapping, the tool visibility switch, and the chat prompt block. ## Risks - Low risk. The routes keep their permission checks. Agents can still only read and propose in this phase. - An agent that sends no `ownerUserId` now gets the responsible person's list instead of a 422. Agents that name an owner see no change. - The chat prompt gets one more short block in standing chats. - The flag is pinned when a turn opens. If an admin changes it during a turn, the tool list changes on the next turn. The routes always check the current setting. ## Model Used Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and code 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 - [ ] 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: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
53fedd653b |
fix(connections): split GitHub Copilot into its own connector (#22238)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The Connectors catalog lets people give agents tools and AI accounts. > - GitHub showed repository access and GitHub Copilot authentication on one card. > - The card had an extra "Connect Copilot" button. Saved Copilot accounts showed in the GitHub account list. > - These are two different products. People must find each one by its own name. > - This pull request makes GitHub Copilot a separate connector. GitHub keeps repository and MCP access only. > - The benefit is a clear catalog. Each card opens its own setup, and saved accounts show on the correct card. ## Linked Issues or Issue Description **What existing behavior does this improve?** Discovery and setup of the GitHub and GitHub Copilot connectors. **Current behavior** The GitHub card says "Connect GitHub repository access or authenticate GitHub Copilot agents." It shows a "Connect Copilot" button next to its own Connect button. Saved Copilot accounts show in the GitHub account list. Agent connection search returns Copilot as a method of GitHub. The Copilot setup link that search gives to agents opens the GitHub tool setup. **Proposed behavior** GitHub and GitHub Copilot are two cards. GitHub says "Give agents access to GitHub repositories, issues, and pull requests." GitHub Copilot has its own logo and opens Copilot token setup. Saved Copilot accounts, including accounts saved before this change, show on the GitHub Copilot card. **Reason and benefit** People do not have to know that Copilot is behind the GitHub card. The catalog names the two products. The Copilot runtime keeps the same provider identity, token storage, grants, and model discovery. **Additional context** This follows the same pattern as the GitHub Code Review Bot split in #14750. Copilot setup was added in #15705. ## What Changed - Add a `github-copilot` app definition with the existing `copilot-token` method. Remove that method from `github`. Restore the GitHub description and the `developer` category. - Add the GitHub Octicons Copilot mark (MIT license, from `primer/octicons`) as light and dark brand assets. - Map the `github` AI provider to the `github-copilot` catalog entry in `aiConnectionCatalogSlug`. New Copilot accounts save under a "GitHub Copilot" application. - Remove the "Connect Copilot" button from the GitHub card. - Show saved AI accounts on the card for their provider. This includes Copilot accounts that were saved under the GitHub application. The connection page and its reconnect link use the same rule. - Redirect old `/apps/connect?source=github&method=copilot-token` links to `source=github-copilot`. Keep the other query values. - Keep the "My GitHub account" identity wording on the Copilot access step. - In connection search and connection requests, file AI accounts under their catalog entry. Accept the `github` provider for the `github-copilot` service. Copilot authentication recovery cards now open GitHub Copilot setup, not GitHub tool setup. - Keep older Copilot accounts and requests working. An older account saved under the GitHub application reconnects through GitHub Copilot, and an older Copilot draft resumes through GitHub Copilot. A recovery request saved with the `github` service name can complete. A Copilot request declined before this change stays declined in its continuation. Adoption accepts the `github` provider binding for a `github-copilot` request. - Move the rule that finds an AI account's catalog entry (`aiConnectionSourceSlug`) into `@paperclipai/shared`, so the UI and server use one copy. - Use the Copilot logo for Copilot in the AI account picker and account details. - Update the GitHub Copilot connection doc and the GitHub connections Storybook story. The GitHub and GitHub Copilot setup stories open **Change** before checking "Connect GitHub as", because that heading sits in the collapsed access section. ## Verification - New and updated tests fail on `master` and pass with this change: - `pnpm exec vitest run packages/shared/src/app-definitions.test.ts` - `pnpm exec vitest run ui/src/pages/apps/Browse.test.tsx ui/src/pages/apps/AppsConnect.test.tsx ui/src/pages/apps/AppDetail.test.tsx ui/src/pages/apps/app-connect-policy.test.ts ui/src/pages/apps/Connections.test.tsx` - `pnpm exec vitest run server/src/__tests__/connection-intents-service.test.ts server/src/__tests__/ai-connections.test.ts` - `pnpm exec vitest run ui/src/features/connections/ConnectionSetupFlow.oauth.test.ts` - Older-account tests cover reconnect, draft resume, completion of a request saved with `github`, a request declined before the split, and Copilot adoption. Each test fails without its fix. - The play functions of all 8 stories in `github-connections.stories.tsx` pass when rendered with `composeStories` in jsdom. - Brand checks: `node scripts/check-app-brand-assets.mjs`, `ui/src/lib/app-brand-assets.test.ts`, and `ui/src/pages/apps/AppLogo.brand-assets.test.tsx`. - Typecheck: `@paperclipai/shared`, `@paperclipai/ui`, and `@paperclipai/server`. - Manual check in `pnpm dev:once` with a local company: 1. Open Connectors and search for "GitHub". Two cards show: "GitHub" and "GitHub Copilot". GitHub has no "Connect Copilot" button. 2. Seed one GitHub tool account and one Copilot account under the GitHub application, as older installs have them. The GitHub tool account shows on GitHub. The Copilot account shows on GitHub Copilot. 3. Click Connect on GitHub Copilot. The "Connect GitHub Copilot" page opens with the Copilot logo and the token field. 4. Open `/apps/connect?source=github&method=copilot-token`. The page redirects to `source=github-copilot`. 5. Open GitHub setup. It offers repository access only. 6. Check the catalog in light and dark themes. ## Risks - Low risk. There is no database migration. Existing Copilot accounts keep their application and stored source. The UI and connection search group them by their AI provider. - New Copilot accounts save under a new "GitHub Copilot" application and record `github-copilot` as their source. Code that finds GitHub repository identities by `sourceTemplateKey === "github"` no longer sees new Copilot accounts. These are AI accounts, so this is the intended separation. - A pending Copilot recovery card from before this change keeps the `github` service slug. The server still resolves it to GitHub Copilot, and the card can complete. - Search for "github" now returns two results: GitHub and GitHub Copilot. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) through Claude Code, with tool use (shell, file edits, test runs, and a headless browser for the manual check). ## 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 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
1355f93546 |
fix(dispatch): schedule a clean loop-limit continuation with its person's work (#22312)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The heartbeat queue decides which queued run an agent starts next.
It puts system recovery in the lowest tier.
> - When a run hits the tool-call loop limit, the server queues a
continuation with the wake reason `issue_continuation_needed`. The
source run succeeded. It did not fail.
> - The queue classed that continuation as system recovery. While any
person-requested run was queued, it got no share. It started only when
the 60-minute aging bound expired.
> - In a restart-chaos wave, 4 of 7 loop continuations waited 60:00 to
60:28. One task broke the "no rest within budget" rule. One run then
resumed an hour-old sandbox, timed out and showed a Retry banner.
> - This pull request schedules a clean loop-limit continuation in the
tier of its task, so a person's task that continues its own work stays
with that person's work.
> - Real failure recovery keeps the recovery tier and the aggregate
share, so a failure loop cannot become high-priority churn.
> - The benefit is that a person's task continues within seconds, not
one hour, and the stale-sandbox Retry path is not reached.
## Linked Issues or Issue Description
Refs #21349
**What happened?**
A continuation queued after the tool-call loop limit waited for the
60-minute aging bound (`QUEUED_RUN_AGING_MS`) on an agent that had
person-requested runs queued. 4 of 7 loop continuations in one
restart-chaos full wave waited 60:00 to 60:28.
**Expected behavior**
A continuation of a person's task whose source run succeeded starts in
the same tier as that person's work. Failure retries stay in the
recovery tier.
**Steps to reproduce**
1. Queue a person's task on an agent with a concurrency limit of 1.
2. Let the run hit the tool-call loop limit, so the server queues an
`issue_continuation_needed` continuation with
`livenessContinuationReason: agent_tool_call_loop`.
3. Keep person-requested runs queued on the same agent.
4. The continuation waits until it is 60 minutes old.
**Paperclip version or commit**
`master` at
|
||
|
|
7eaf38130b |
fix(tasks): keep a due automatic retry working while it is dispatched (#22306)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - When a run fails for a reason that Paperclip retries by itself,
Paperclip saves a new run in the `scheduled_retry` state. The task shows
"retry scheduled" and does not show a Retry button.
> - When the retry time comes, the run stays `scheduled_retry` until the
dispatcher promotes it to `queued`. This takes a few seconds.
> - In that gap, the task view does not see a future retry time and does
not see a queued run. So it falls through to "failed, Retry available".
> - In a restart test wave, two tasks showed a Retry banner for about 4
seconds this way. Both then continued without a click. A person can
click Retry in that window and start a second, competing retry.
> - This pull request treats a due automatic retry the same way as a due
native resume: the task shows "working" while the dispatcher promotes
it, for the same 2 minute grace.
> - The benefit is that an automatic retry never shows a Retry button. A
retry that never starts still shows one Retry after the grace.
## Linked Issues or Issue Description
**What happened?**
After an automatic retry became due, the task showed "failed" with a
Retry button for one poll (about 4 seconds). Then the retry started by
itself. Two tasks in a 197-task restart test wave showed this. One retry
came from an environment provider timeout
(`environment_provider_unavailable`). The other came from a
`native_environment_blocker` retry.
**Expected behavior**
A task whose automatic retry is due and not yet dispatched shows that
Paperclip is working. It does not offer Retry.
**Steps to reproduce**
1. Make a run fail with a cause that Paperclip retries automatically
(for example a transient failure).
2. Watch the task while the retry time passes.
3. Before the dispatcher promotes the retry run to `queued`, the task
interruption shows `state: "failed"` and `canRetry: true`.
**Paperclip version or commit**
`master` at
|
||
|
|
1c67687998 | feat(runner): start a released Runner again as the next run (#22288) | ||
|
|
440f96247b |
fix(cloud): resolve or name the remaining online move blockers (#22294)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - A hosted server can move its durable data to shared storage while it serves work, and then run without a volume > - A bounded online pass moves the data, and a readiness check names what still blocks the move > - Some servers stay blocked after many passes, and the pass reports only `skills:blocked` or `native_harness:source_not_successful`, or reports nothing for run logs > - Operators cannot see why, so they cannot tell recoverable data from data that needs a maintenance step > - This pull request recovers the cases that are safe to recover online and gives every other case a precise code > - The benefit is fewer blocked moves and a clear next step for each one that stays blocked ## Linked Issues or Issue Description Refs #19719 **What happened?** A serving server that runs the online durable-data pass many times stays ineligible. The pass reports `skills:blocked` without a reason, `native_harness:source_not_successful` for several different causes, and no reason at all for run logs that stay on the local disk. **Expected behavior** The pass moves every item that it can move safely while the server serves work. For each item that stays, the pass reports a code that names the cause. **Steps to reproduce** 1. Install a catalog skill on a volume-backed server. Remove its installed files and do not keep a saved version. 2. Keep a settled native run whose local log file has no final size or digest and whose events do not prove full coverage. 3. Run the online durable-data pass. 4. See that the skill is reported only as `skills:blocked` and the run log stays local with no reason in the pass result. **Additional context** The settled native log archive path from #19719 had no online caller. ## What Changed - Skill installation conversion returns a `code` for each blocked installation (for example `source_files_unavailable`, `saved_version_incomplete`, `catalog_origin_unavailable`, `legacy_source_unsafe`, `source_changed`). The pass reports `skills:<code>`. An unknown cause stays `skills:blocked`. - A spent budget during conversion now stops the page. Before, it was reported as a blocked skill and the page moved past it. - A catalog skill whose files are gone converts from the bundled catalog package only when the catalog content hash equals the recorded origin hash and the last audit recorded the installed bytes as equal to that origin with no local changes. - A modified catalog skill whose reset origin is gone gets its origin version from the bundled catalog package only when the catalog content hash equals the recorded origin hash. - Native harness pre-copy replaces `source_not_successful` with `source_run_active`, `source_run_unfinished`, `source_coordinator_missing`, `source_coordinator_unsettled`, `source_session_not_selected` and `source_lease_missing`. The settled-source rules do not change. - The run evidence worker archives a settled native log by run id when the canonical import cannot prove event coverage. The existing settled-source guard still decides. The worker records the reasons from its last completed sweep, and the pass reports them as `run_logs:<code>` and `provider_traces:<code>`. - `migrateRunEvidence` accepts a `runId` filter. ## Verification - `cd server && npx vitest run src/__tests__/managed-skill-content.test.ts` (embedded PostgreSQL): new catalog recovery, hash mismatch, unproven install and budget abort tests fail before the change and pass after it. - `npx vitest run src/services/native-runtime/native-harness-online-preservation.integration.test.ts src/services/native-runtime/native-harness-backup-storage.integration.test.ts`: the new reason tests fail before the change and pass after it. - `npx vitest run src/__tests__/run-evidence-migration-work.test.ts src/services/native-log-archive.integration.test.ts`: the worker archive test fails before the change and passes after it. The integration test shows a real settled source that is blocked as `native_log_source_coverage_unproven` and then archived by run id. - `npx vitest run src/services/online-durable-data-migration.test.ts src/services/online-durable-data-migration-postgres.test.ts` - `pnpm --filter @paperclipai/server typecheck` ## Risks - A settled native log with unproven coverage now moves to the read-only historical archive instead of staying local. The archive keeps the exact bytes. It does not claim canonical event coverage. This is the same result that the offline path gives. - The catalog fallback reads bundled or pinned catalog bytes. Each file is checked against its pinned SHA-256, and the package must match the recorded origin hash. - Pass deferral codes change. Readers that match `native_harness:source_not_successful` must use the new codes. > 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 - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code execution in Claude Code. ## 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: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
170e1b0c07 |
feat(runner): pin Codex 0.170.0 and Agent SDK 0.3.328 so Fable 5.2 and GPT-6.2 run (#22278)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Paperclip Runner runs Claude and Codex agents from one shared provider pack. The pack pins an exact Claude Agent SDK (which bundles Claude Code) and an exact Codex CLI. > - #22222 added Claude Fable 5.2 (minimum Claude Code 2.1.321) and GPT-6.2 Sol and Astra (minimum Codex 0.169.1). The pack still bundles Claude Code 2.1.286 and Codex 0.160.0. > - Because of this, Paperclip Runner stops these models with a named version error, and native remote Codex accepts only `>=0.149.0 <0.161.0`. > - This pull request moves the provider pack to Agent SDK 0.3.328 (Claude Code 2.1.328) and Codex 0.170.0. It moves every constant that depends on these pins, and the remote Codex window to `<0.171.0`. > - The benefit is that Fable 5.2 and GPT-6.2 run on Paperclip Runner after a sandbox image with this pack is promoted. ## Linked Issues or Issue Description Refs #22222 (adds the models and the version floors; this pull request makes them runnable on Paperclip Runner). Refs #18488 (moves only the Codex pin to 0.166.0 and the window to `<0.167.0`; it is not updated since November 1 and has conflicts with `master`). Refs #18486 (GPT-6.1 Terra needs Codex 0.165.0; Codex 0.170.0 satisfies it). **Overlap with #18488.** #18488 changes the same Codex pin locations. This pull request uses a newer pin (0.170.0) and also moves the Claude runtime. If this pull request merges first, #18488 has no remaining change. I did not change the #18488 branch. ## What Changed - Claude runtime: `@anthropic-ai/claude-agent-sdk` 0.3.286 → 0.3.328 (Claude Code 2.1.286 → 2.1.328). This changes the root `pnpm.overrides`, `pnpm-workspace.yaml`, the ACPX `claude` profile, and the qualified Claude runtime in `installation-integrity.ts`, with new executable digests for Linux x64, Linux ARM64, macOS ARM64, and macOS x64. - Codex runtime: `@openai/codex` 0.160.0 → 0.170.0. This changes the runner dependency, the `codex-acp@1.6.2>@openai/codex` override, the `codex-acp` patch dependency line, the ACPX `codex` profile, and the qualified Linux x64 runtime with its new executable digest. - The ACP bridges do not change: `claude-agent-acp` 0.73.0 and the patched `codex-acp` 1.6.2. Their `commandDigest` values and profile versions do not change. - Generated declarations: `generated-profiles.ts` and `generated_acpx_profiles.rs` are regenerated with `generate:acpx-profiles`. - Remote native Codex window: `REMOTE_CODEX_MAXIMUM_VERSION_EXCLUSIVE` 0.161.0 → 0.171.0. The minimum stays at 0.149.0. Images with Codex 0.149.0 through 0.170.x are accepted. - Codex company observability: the qualified-version check moves to `codex-cli 0.170.0`. The `otel` configuration keys that Paperclip writes (`exporter`, `trace_exporter`, `metrics_exporter`) are present in the 0.170.0 configuration schema. The `OtelExporterKind`, `OtelHttpProtocol`, and `OtelTlsConfig` definitions are identical to 0.160.0. - Daytona runner image probes (`Dockerfile`, `Dockerfile.release`) expect `codex-cli 0.170.0` and `2.1.328 (Claude Code)`. The remote npm install spec in `server/src/adapters/registry.ts` is `@openai/codex@0.170.0`. - Tests: fixtures and assertions that mirror the pins use the new versions. The window tests accept 0.161.0 through 0.170.99 and reject 0.171.0. The ACPX gate tests now show that Fable 5.2 and GPT-6.2 are admitted. A new test mocks an older bundled runtime and keeps the named version-gap errors covered. The fallback test shows that GPT-6.2 stays on 0.170.0 and still falls back on 0.160.0. - Opt-in qualification scripts (`scripts/tests/native-cleanup-paginated-codex.mjs`, `native-provider-startup-codex.mjs`) require Codex 0.170.0. - Documentation: `docker/daytona-runner/README.md`, `doc/architecture/paperclip-runner-compatibility.md`, `doc/agent-observability.md`, `docs/deploy/environment-variables.md`, and the deferred item in `doc/adapter-model-audit-2026-11-18.md`. - `pnpm-lock.yaml` is not part of this pull request. The refresh bot regenerates it on `master`, as for the previous pin refreshes (#14942, #14993). ## Verification Sources, checked on 2026-11-19: - npm registry: `@openai/codex@0.170.0` (published 2026-11-18T03:45Z) and `@anthropic-ai/claude-agent-sdk@0.3.328` (published 2026-11-18T23:13Z, `claudeCodeVersion` 2.1.328). Both are the `latest` tags. - [Codex releases](https://github.com/openai/codex/releases) 0.161.0 through 0.170.0. The notes record no app-server protocol break. 0.169.0 keeps project configuration disabled for `codex exec` in untrusted directories; Paperclip's CLI path already uses `--skip-git-repo-check`, and the native path uses `app-server`. - [Claude Code changelog](https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md) 2.1.287 through 2.1.328. See "Risks" for the headless changes that I reviewed. Digests and package shape: - I downloaded each platform archive with `npm pack`, which verifies registry integrity, and computed the SHA-256 of the executable. As a method check, the same command on the 0.3.286 Linux x64 archive gives the digest that is on `master` (`fe503f65…`). The Codex 0.160.0 archive also gives the `master` digest (`12eb3e81…`). - The extracted executables report `codex-cli 0.170.0` and `2.1.328 (Claude Code)`. - The Codex 0.170.0 Linux x64 archive no longer contains `codex-resources/zsh/bin/zsh`. Paperclip does not reference that path. - The Agent SDK 0.3.328 `optionalDependencies` have the same platform set as 0.3.286. The Codex 0.170.0 `optionalDependencies` use the same `npm:@openai/codex@<version>-<platform>` aliases. - Bridge link check: I installed `@agentclientprotocol/claude-agent-acp@0.73.0` with an override to Agent SDK 0.3.328 and imported its entry module. Node linked all of the named SDK imports, and the import completed. Real Codex qualification (no model turn, no credentials): - `PAPERCLIP_TEST_CODEX_BINARY=<installed 0.170.0 Linux x64 binary> node --import ./server/node_modules/tsx/dist/loader.mjs scripts/tests/native-cleanup-paginated-codex.mjs` passed: `green: true`, with the expected red control and paginated `thread/resume` through the real 0.170.0 `app-server`. The installed binary digest matches the pinned digest. Focused suites (Linux x64, Node 25.9.0, local `pnpm install --no-frozen-lockfile`): - `cd packages/paperclip-runner && pnpm run typecheck:typescript` passed, including `check:acpx-profiles`. - `npx tsc --noEmit` passed in `packages/adapters/codex-local` and `packages/adapters/claude-local`. - `packages/adapters/codex-local`: 625 passed. `packages/adapters/claude-local`: 419 passed, 1 skipped. - `node --test`: `acpx-codex-package-contract` 9 passed, `controlled-evals/controller` 77 passed, `scripts/acpx-patch-packaging` 26 passed, `scripts/__tests__/grok-public-install-sandbox` 27 passed. - `server`: `acpx-qualification`, `codex-runtime-compatibility`, and `codex-model-fallback` 110 passed. `native-session-executor` 1541 passed, 1 failed. The failure (`compares export process compatibility … db.transaction is not a function`) also fails on unchanged `master` on this host. - `packages/paperclip-runner` vitest (`installation-integrity`, `qualified-profiles`, `codex-security-config`, `native-execution`, `native-backend-factory`): 283 passed, 25 failed. All 25 failures are in `installation-integrity.test.ts` with "ACPX provider lifetime guardian failed to start". The same 25 tests fail on unchanged `master` on this host (master fails 30 here). Rust (toolchain 1.97.1 from `rust-toolchain.toml`, Linux x64): - `cargo test -p paperclip-runner-core --lib`: 658 passed, 2 failed, 4 ignored. `warm_run_attachment_reuses_the_provider_ingress_listener` also fails on unchanged `master` on this host. `reaping_stops_a_dead_runners_provider_and_its_escaped_tool_job` is flaky here: on this branch it passed 2 of 3 reruns. - `cargo test -p paperclip-runner-core --test acpx_warm_attachment --test native_provider_backend`: 7 and 45 passed. - The new and changed saved-session tests pass: `a_session_saved_by_the_previous_agent_runtime_is_refused_by_name`, `unrestorable_saved_sessions_keep_strict_bindings_and_name_their_class`, and `a_settled_session_saved_by_the_previous_acpx_release_continues`. `rustfmt --check` passes. - `server`: `native-session-resume.test.ts` and `acpx-qualification.test.ts` 110 passed, 2 skipped. Both new resume cases run and pass. Not run here: - `native-provider-startup-codex.mjs`, because it needs a compiled `paperclip-runnerd`. The trusted CI runner workflow covers startup and session-resume probes. - The Docker image build and any live model turn. A live Fable 5.2 and GPT-6.2 test follows the staging image rollout. ## Saved sessions from the previous release This change keeps the ACPX bridge command digests and profile versions. It changes `agentRuntimeVersion` in the `claude` and `codex` ACPX profiles. That field is part of the saved session identity. The previous release saved sessions with Agent SDK 0.3.286 or Codex 0.160.0. This build refuses those saved sessions. It does not migrate them. - **Next run (the usual case):** the saved provider descriptor names the old runtime. `rebindNativeSessionCheckpoint` does not match it, so the next run starts a fresh provider session in the same workspace with the complete handoff prompt. No run fails. The earlier provider conversation does not carry over. - **A run in flight at the deploy (settled or mid-turn):** the runner restore refuses the saved descriptor with the permanent class `provider_state_incompatible`. The server reports it as `native_provider_state_incompatible` and stops automatic retries. The runner opens no provider and keeps the saved state bytes and the workspace. The next run on the task starts a fresh provider session. - **Native Codex (`codex_app_server`) and OpenCode** sessions do not record this field, so their resume decision does not change. After a new image is promoted, native Codex resumes a saved thread with Codex 0.170.0 instead of 0.160.0. This pull request does not test that cross-version thread resume. New tests: - `acpx_provider_backend.rs`: `a_session_saved_by_the_previous_agent_runtime_is_refused_by_name` covers settled Claude and Codex sessions and a Claude turn interrupted mid-run by the deploy. `unrestorable_saved_sessions_keep_strict_bindings_and_name_their_class` has a new `agent_runtime_release` case. Each case checks the named class, that no provider session opens, and that the saved bytes do not change. - `native-session-resume.test.ts`: "a session saved by the previous Claude or Codex ACPX runtime" checks that a same-release session resumes, and that a session saved with Agent SDK 0.3.286 or Codex 0.160.0 starts fresh in the same workspace. ## Risks - Medium. Every Paperclip Runner Claude and Codex run uses the new executables. The digests, generated profiles, image probes, and window must agree. They agree locally, and CI runs the Rust and runner suites again. - Claude Code 2.1.287 through 2.1.328 change some headless defaults. I checked each one against Paperclip: - 2.1.302: `-p` and Agent SDK sessions with no permission mode start in `default` mode on third-party providers. Paperclip always sets a mode (`bypassPermissions` or `default`), so this does not apply. - 2.1.299: MCP allow rules now match only the whole server name. Paperclip already writes `mcp__<server>__*` and exact `mcp__paperclip__<tool>` rules. - 2.1.302: fork subagents are on by default in `-p` and the Agent SDK, as in the terminal. This pull request keeps the upstream default and does not set `CLAUDE_CODE_FORK_SUBAGENT=0`. Reviewers can ask to keep them off. - 2.1.299 and later: stdio MCP connections negotiate MCP protocol 2026-07-28 first and fall back to the older protocol for servers that do not answer. - Agent SDK 0.3.328 is less than one day old. If a regression appears, revert this pull request to return to 0.3.286 and Codex 0.160.0. - Sandbox images built before this change still carry Codex 0.160.0 and Claude Code 2.1.286. They stay accepted. On those images, Fable 5.2 and GPT-6.2 keep the existing named errors and fallbacks until a new image is promoted. - Until the refresh bot updates `pnpm-lock.yaml` on `master`, a local `--frozen-lockfile` install fails, as with the previous pin refreshes. > 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 - Anthropic Claude, model ID `claude-opus-5-5`, through Claude Code with tool use (shell, file edit, `gh`) and code execution. The context window and reasoning mode are not reported in this session. - The registry archives, digests, release notes, configuration schemas, and changelog were read directly. No model output was used as a source for those facts. ## 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 - [ ] 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: devinfoley <139239+devinfoley@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
90d985b8b9 |
perf(heartbeat): skip unused session and holder reads for queued input (#22282)
## Thinking Path > - Paperclip saves comments on a task while an agent is busy. > - A second comment can join an existing queued run. > - Only a new run records the starting session, yet admission read it before choosing a run. > - Admission can also bind an existing run and then use the previous holder's agent name. > - Read the session at insertion. Use the selected holder's key to decide whether the existing run can accept the comment. ## Linked Issues or Issue Description **What existing behavior does this improve?** Admitting board assignments and saved task comments. **Subsystem affected** Server task admission. **Current behavior** Adding a comment to queued work reads a task session it does not use. A replaced execution holder can leave its old key in this admission decision. **Proposed behavior** Read the default session in the transaction that creates a run. Use the selected run's execution-agent key when evaluating queued input. **Additional context** Builds on #22268, #22279 and #22280. ## What Changed - Keep explicit resume lookup early because it determines task scope. - Use the stored execution key if present. Scope the fallback agent lookup to the company. - When binding an existing run, use the same normalized key for the issue write and the coalescing decision. ## Verification All 280 tests passed across the PostgreSQL wake-queue adapter, heartbeat queue, heartbeat run-state and responsible-user suites at |
||
|
|
3dc6ccd8d8 |
perf(wake-queue): reuse the task row locked by admission (#22280)
## Thinking Path
> - Paperclip schedules agent work for a task.
> - Admission locks the task before it decides what to run.
> - The lock query returned only the identifier. The policy and recovery
check then read the same task again.
> - Return the fields those decisions need from the lock query.
> - Refresh the task after a callback that can change it. Keep recovery
and workspace authority current.
## Linked Issues or Issue Description
**What existing behavior does this improve?**
Admitting board assignments and saved task comments.
**Subsystem affected**
Server task admission.
**Current behavior**
Admission reads the task again while it holds the row lock. A comment
also queries the bound workspace when the locked task has none.
**Proposed behavior**
Use the company-scoped locked row. Check workspace preservation when the
task has a bound workspace.
**Additional context**
Builds on #22272 and #22279. Related work in #21954 changes workspace
binding.
## What Changed
- Return the admission projection from the row lock. Repeat the locking
read after durable authorization or an initial miss.
- Use the task projection only for the same company and task. Keep every
recovery-action, ownership and lease read.
- Cover changes inside durable authorization and a concurrent insert
after the initial lock missed.
## Verification
All 261 tests passed in the wake-queue Postgres adapter,
execution-blocker-read and heartbeat queue suites. On
|
||
|
|
5506359bbb |
perf(wake-queue): skip recovery lookup when no saved receipt can be adopted (#22279)
## Thinking Path
> - Paperclip assigns tasks and saves input for agents.
> - One admission can adopt previously deferred comments.
> - Admission reads the task's recovery state before creating the run.
> - It repeated that lookup even when there were no deferred receipts to
adopt.
> - Check for scoped receipts first. Verify the recovery hold when at
least one exists.
## Linked Issues or Issue Description
**What existing behavior does this improve?**
Admitting board assignments and saved task comments.
**Subsystem affected**
Server task admission.
**Current behavior**
An empty candidate set triggers a second recovery lookup on the ordinary
assignment and comment paths.
**Proposed behavior**
Check recovery only when the candidate lookup returns rows.
**Additional context**
Builds on #22268 and #22272. Related recovery work in #20163 addresses
terminal tasks.
## What Changed
- Query the same receipt scope under the existing issue lock.
- Keep the handoff owner, receipt order, and reconstruction exception.
- Exercise empty and nonempty exact scopes with an active recovery hold
and verify the lock from a competing database session.
## Verification
162 tests passed across the PostgreSQL wake-queue adapter,
issue-wake-admission, and heartbeat comment batching. A local
occupied-slot benchmark on merged base
|
||
|
|
f0caee6f95 |
Use one automatic goal steering decision for task comments (#22277)
## Thinking Path
> - Paperclip can deliver a saved task comment to an agent already
working on a goal.
> - Both posting a comment and editing a task with a comment perform
this decision.
> - Each handler previously checked eligibility, queued the same
command, waited for its result, and decided whether to wake the agent.
> - Separate copies make changes to the fallback rules difficult to
verify.
> - Both routes now call one wake-queue use case for automatic goal
steering.
## Linked Issues or Issue Description
**What existing behavior does this improve?**
Automatic goal steering after saving a comment on a task.
**Subsystem affected**
Server task admission.
**Current behavior**
The comment POST and issue PATCH each implement live steering and its
fallback.
**Proposed behavior**
One use case returns whether the current runner acknowledged the
comment. The routes continue through their existing boundary wake logic
when delivery is unavailable or fails.
**Additional context**
Builds on #22276. The explicit board Steer click and automatic goal
steering have separate acknowledgement contracts.
## What Changed
- Keep the assignee, self-comment, and external-conversation guards
together with the active goal decision.
- Preserve the comment-derived command ID, the route's selected agent,
and completion-error reporting.
- Drive both HTTP routes with a single comment through success,
unavailable transport, and rejected completion.
## Verification
On
|
||
|
|
8af66f48e9 |
Admit explicit queued steering with durable acknowledgement in wake-queue (#22276)
## Thinking Path
> - A board user can send a queued message into an active agent turn.
> - The server must know which queue, issue and run the user selected.
> - A provider can accept a message even when the client loses the HTTP
response.
> - The route previously handled authorization, replay, delivery,
database writes and response construction in one block.
> - Wake-queue can own the steering operation and its acknowledgement
while the route keeps the board access decision.
## Linked Issues or Issue Description
**What existing behavior does this improve?**
Explicit same-turn delivery of a queued board comment or interaction.
**Subsystem affected**
Server task admission.
**Current behavior**
The issue route issues SQL, interprets the provider acknowledgement and
updates the wake, run and identity.
**Proposed behavior**
The route calls one steering command. The command decides replay, checks
the revision and the selected entry, and leaves an uncertain delivery
pending. The adapter handles identity reservation, the issue and wake
locks, and persistence after acknowledgement.
**Additional context**
Builds on the board queue extraction. Related earlier work in #13160
locked the target run while waiting for a provider. Today's runner
writes its acknowledgement to that row.
## What Changed
- Use the shared board queue read and lock for pending messages and
acknowledgement replay.
- Keep the target run available while waiting for the provider. Re-read
and lock the scoped run after acknowledgement and preserve concurrent
result updates.
- Leave HTTP access, activity logging, response redaction and error
translation with the route.
## Verification
On
|
||
|
|
d23a690cdf |
refactor: share the board queue snapshot and lock in wake-queue (#22273)
## Thinking Path > - Paperclip users can inspect queued messages, interrupt a task, or steer the active run. > - All three operations need the same view of pending comments, approvals and first-turn inputs. > - The HTTP routes owned the code that loaded and locked this state. > - A separate move makes the later steering transaction easier to review. > - The same callers now use the board queue reader and lock in wake-queue. ## Linked Issues or Issue Description **What existing behavior does this improve?** Reading the board queue and locking its current state for Interrupt and Steer. **Subsystem affected** Server task admission. **Current behavior** Local functions in the issue route select the ordered queue and apply its locking rules. **Proposed behavior** The existing route handlers call the same implementation through the wake-queue boundary. **Additional context** Depends on #22272. This supplies the current board view for the steering extraction discussed in #13160. ## What Changed - Move the existing board snapshot and lock into a Postgres adapter. - Use the shared reader from GET, Interrupt and Steer, including acknowledgement replay. ## Verification Fifteen focused Postgres route tests passed on the extracted implementation. They cover live queue reads, Interrupt, acknowledgement replay, concurrent run updates, stale targets and timeouts. Run `pnpm exec vitest run server/src/__tests__/issue-queued-comments-routes.test.ts` and `node scripts/check-module-boundaries.mjs`. Review the move with `git diff --color-moved`. ## Risks A change to these shared reads could affect which messages users see or whether a pending input can be interrupted. The move preserves the queries, lock order, rich interaction entries and caller-specific live probe behavior. ## Model Used OpenAI GPT-6.2 Sol (`gpt-6.2-sol`) implemented the change. OpenAI Codex directed the work, reviewed the diff, and ran qualification. ## 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> |
||
|
|
ebb98120dc |
Own the issue admission lock and dispatch after commit in wake-queue (#22272)
## Thinking Path
> - Paperclip admits work for a task while other agents and users may
also act on it.
> - A fresh run and a wake behind an active execution both require the
same issue lock.
> - Heartbeat previously opened that transaction and passed handles
across the module boundary.
> - The wake-queue module can bind both admission operations to the
locked company and issue.
> - The result of the database commit determines whether to emit a
queued event, dispatch a run, or return a saved result.
## Linked Issues or Issue Description
**What existing behavior does this improve?**
The transaction and handoff used by task-bound wake admission.
**Subsystem affected**
Server task admission.
**Current behavior**
Heartbeat opens the transaction, builds a scope for the busy path, and
dispatches based on the result. Its contention handler can reach
buffered side effects after a rollback.
**Proposed behavior**
Wake-queue owns the lock and the durable acknowledgement. The
application hands off a committed result. A rolled-back contention
attempt returns without publishing its buffered effects.
**Additional context**
Depends on #22268 and #22266.
## What Changed
- Bind the busy and fresh admission operations to a single company and
issue in Postgres. Remove the transaction scope object.
- Keep specialized heartbeat gates and continuation writes on the
acquired transaction.
- Buffer the workspace preflight activity publication until the
transaction commits.
- Centralize the handoff for new, coalesced, replayed, deferred, skipped
and durable results.
## Verification
On
|
||
|
|
eca7f85778 |
Admit saved task comments with the fresh issue run (#22268)
## Thinking Path
> - Paperclip agents take work from assigned tasks and from user
comments.
> - A fresh task run can include saved comments when the current agent
or a confirmed former assignee owns them.
> - Connected chat messages and resolved interactions have separate
authority and session requirements.
> - Heartbeat previously decided which receipts to adopt between the
three calls that saved a new run.
> - One wake-queue use case now selects the receipts and commits the
same run and comment lineage.
## Linked Issues or Issue Description
**What existing behavior does this improve?**
Assignment and comment continuation when a task needs a fresh run.
**Subsystem affected**
Server task admission.
**Current behavior**
Heartbeat chooses the comment receipts to consume, reads their source,
and builds the final run context.
**Proposed behavior**
One application operation admits the run. Its Postgres adapter loads
eligible company and agent receipts under the issue lock. The caller
supplies the responsible user and records the specialized continuation.
**Additional context**
Builds on #22266. The existing release and queued-comment boundaries are
in #13136 and #13145.
## What Changed
- Keep exact resumed receipts separate from ordinary board comments.
Adopt a prior assignee’s comments only when the interrupted run proves a
handoff.
- Use the same canonical comment ID codecs for admission and dispatch.
- Test the assignment path with one or two saved comments and
independent chat and interaction receipts.
## Verification
On
|
||
|
|
f324238f73 |
Move fresh issue run and receipt writes into wake-queue (#22266)
## Thinking Path > - Paperclip manages AI agents at work. > - Assigning a task or resuming it from a comment can create a queued run. > - The wake-queue module handles admission behind an active execution. Heartbeat also writes the receipt and run when a new execution is needed. > - These writes share the issue lock. Splitting them across transactions would allow duplicate or partially bound work. > - This change puts the fresh writes in the wake-queue module under the existing lock. ## Linked Issues or Issue Description **What existing behavior does this improve?** Creating a queued run for an assigned or continued task. **Subsystem affected** Server task admission. **Current behavior** Heartbeat constructs the receipt and run, handles retry lineage, and ties adopted receipts to the run. **Proposed behavior** Wake-queue owns receipt promotion, fresh-run construction, and receipt binding. Heartbeat still selects saved comments and orders recovery effects inside the same transaction. **Additional context** Earlier module boundaries were introduced in #13136 and #13145. ## What Changed - Move fresh receipt, run, and binding writes to a transaction-bound Postgres adapter. - Keep explicit continuation and reconciled retry lineage in the application layer. - Scope receipt updates by company and durable promotion by agent. Cover both predicates with a database test. ## Verification On commit |
||
|
|
12fc89b1f7 |
fix(cloud): let an online move proceed when Cloud supplies the database listener (#22263)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Hosted Paperclip servers can move from a server with a volume to a volume-free server, which allows deploys without downtime > - Before the move, Core checks that the volume-free configuration is complete > - That check requires `PAPERCLIP_DATABASE_LISTEN_URL` on the running volume server, but only the volume-free replacement uses it, and Cloud supplies it when it configures that replacement > - Many older servers never had the setting, so they cannot move online even when all their data is ready > - This pull request stops an unset listener from blocking, and keeps a listener that points at another database as a blocker > - The benefit is that older servers can move online ## Linked Issues or Issue Description **What existing behavior does this improve?** The online move refuses a volume server that has no `PAPERCLIP_DATABASE_LISTEN_URL`. **Subsystem affected** Server: ephemeral enrollment readiness (`server/src/services/ephemeral-enrollment.ts`). **Current behavior** The eligibility read and preparation report `volume_free_database_listener_required` for every server that has no listener setting. **Proposed behavior** An unset listener does not block. A listener that does not match the runtime database still blocks with the same name. **Reason and benefit** The replacement server receives the listener from Cloud. On staging, this check alone blocks 18 servers whose data is otherwise ready. **Breaking changes** None. The startup contract for a running volume-free server is unchanged. ## What Changed - `services/ephemeral-enrollment.ts`: when the only configuration failure is the listener, and the listener is unset, the readiness check passes. The listener check is the last check in `assertEphemeralServerConfig`, so all earlier settings were already valid. - `services/ephemeral-enrollment.test.ts`: tests for an unset listener (eligible, and preparation succeeds) and a mismatched listener (still blocked). ## Verification - `npx vitest run src/services/ephemeral-enrollment.test.ts src/routes/ephemeral-enrollment.test.ts`: 29/29 pass. ## Risks - Low. Cloud's online arming passes `PAPERCLIP_DATABASE_LISTEN_URL` with the replacement's variables. If the replacement did not get the setting, the existing startup contract would still refuse to boot it, and the move would not complete. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use (shell, file edits, browser). ## 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: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
9b16044bf1 |
fix(cloud): move idle local workspaces in the online durable-data pass (#22270)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - A hosted server can move to volume-free storage only when no durable data stays on its local volume > - The online durable-data pass moves that data while the server keeps serving, one bounded and resumable pass at a time > - The pass does not move local execution workspaces, so servers with local workspaces stay ineligible (`workspaces_require_migration`) > - Online-safe owners for workspaces already exist: the online remote workspace migration and the online workspace operation reconciliation > - This pull request adds workspace phases to the pass that call those owners, and defers busy or unsupported workspaces with a reason > - The benefit is that idle workspaces move with no outage, and operators can see which workspaces cannot move and why ## Linked Issues or Issue Description **What happened?** The online durable-data pass never moves local execution workspaces. A server with local workspaces keeps the `workspaces_require_migration` blocker after every pass. **Expected behavior** The pass moves each idle local workspace to shared storage through the online owner. It defers a busy or unsupported workspace and reports the reason. **Steps to reproduce** 1. Run the online durable-data pass on a server that has a local `local_fs` execution workspace. 2. Read the pass result and the eligibility blockers. 3. The workspace stays local and `workspaces_require_migration` stays. **Deployment mode** Hosted server that moves from a local volume to volume-free storage. ## What Changed - Add two phases to the online durable-data pass, after `runtime_skill_assets` and before the native phases: - `workspace_operations`: pages companies that have local workspaces and calls `reconcileOnlineWorkspaceOperations` for each. It counts `workspaceOperations` and defers each held operation as `workspace_operations:<reason>`. - `workspaces`: pages local workspaces (same filter as the eligibility check), deepest path first so nested workspaces go before their parents. For each workspace it reads `inventoryRemoteWorkspaceMigration`. If the workspace is eligible, it calls `migrateRemoteWorkspace` in online mode (never `writersStopped`) with the pass signal and a 1 s source-lock wait. - A workspace that the owner refuses is deferred with each owner reason as `workspaces:<reason>`, for example `workspaces:active_execution`, `workspaces:task_binding_required`, `workspaces:workspace_provider_unsupported`, `workspaces:workspace_source_busy`, or `workspaces:execution_rows_busy`. An unknown error becomes `workspaces:owner_failed` and its message is not echoed. The page continues with the next workspace. - Both phases use a cursor and a limit that the pass can halve after a budget timeout, like the other phases. - Add `listLocalWorkspaceCompanies` and `listLocalWorkspaces` next to `localWorkspaceDependencyWhere`. - The pass stops waiting for a workspace owner at the budget. It reports `workspaces:owner_busy` until that owner settles. ## Verification - `cd server && npx vitest run src/services/online-durable-data-migration.test.ts src/services/online-durable-data-migration-postgres.test.ts` - Unit tests with injected owners: phase order, online mode and lock wait, deferral codes, owner refusal under locks, cursor resume across budget-limited calls, and page halving that keeps finished workspaces. Seven tests fail without the change and pass with it. - Embedded PostgreSQL test with the real owners: an idle managed-project workspace moves to a committed snapshot and its files restore from it. A workspace with a running task run is deferred as `workspaces:active_execution`, and its record, files, and operations stay unchanged. The test fails without the change and passes with it. - Embedded PostgreSQL test for the workspace and company cursors: ten workspaces in two companies, with equal and different path lengths, across pages of three. Each workspace appears once, deepest first. - `pnpm verify` selected 2934 of 3802 test files (almost the full suite). It was not run to the end. Required CI covers the full suite. ## Risks - A workspace move that takes longer than one pass budget (60 s) stops at the budget. The workspace keeps its in-progress move marker, so new runs for that workspace are refused until a later pass resumes the move. The pass resumes the same page on the next call. If one workspace times out twice at page size 1, the pass reports `workspaces:stalled` and goes on; the next cycle resumes it again. A very large workspace can therefore stay blocked for runs across passes. The operator online workspace tool can resume it with a longer deadline. - A workspace with no proven online source uses the owner's lifecycle lock, which waits without a timeout. The pass does not wait for it past the budget. The pass returns at the budget, and the owner stops at its next abort check after it gets the lock. Until that owner settles, later passes skip the workspace phase and report `workspaces:owner_busy`, so two moves never run at the same time. - Workspaces that can never move online (for example unsupported providers or workspaces without a task binding) are reported each pass and are not changed. This change makes no product decision for them. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), via Claude Code with tool use and code 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 - [ ] 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: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
067f7a0815 |
feat(telemetry): send product lifecycle events and agent run failure cause (#22250)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - First-party telemetry tells the team which product steps people finish > - Telemetry did not record when a model is connected, when a task is created, completed, or blocked, when a plan is created or approved, or when an artifact is created > - Telemetry also did not tell why an agent run failed, so failures could not be grouped by cause > - This pull request syncs the new telemetry contract and sends these events from the server once per real change > - The benefit is a product funnel and a failure breakdown that use only enums, booleans, and counts ## Linked Issues or Issue Description **Subsystem affected** Server telemetry (`packages/shared/src/telemetry`, `server/src/services/product-telemetry.ts`) and the emit sites in the issue, document, work product, interaction, and AI connection services. **Problem or motivation** The team cannot measure the main product path. There is no event for a new model connection, a new task, a completed task, a blocked task, a new plan, an approved plan, or a new artifact. `agent.task_run` tells that a run failed, but not why. The signup funnel also must know when the onboarding wizard created the first task. **Proposed solution** Register the events in the telemetry backend. Sync the generated contract here. Add typed helpers. Send each event once, after the transaction that makes the change commits. Use fixed enums for every kind, reason, and cause. **Alternatives considered** A post-commit action queue on the issue service only. The native status path and many other callers use an external transaction without that queue, so most agent completions would not send an event. A generic after-commit hook on the database client covers every caller. **Roadmap alignment** This is telemetry for existing features. It adds no new product feature. **Additional context** This change depends on paperclipai/telemetry-backend#150, which is merged. Deploy that backend change before this change ships. Until then, the collector rejects the new event names. ## What Changed - Sync `generated/paperclip-telemetry.ts` from the backend branch as a direct copy. Regenerate `posthog-direct/enum-fallbacks.generated.ts` with `scripts/generate-posthog-direct-fixtures.mjs`. The loader golden file did not change. - Add `afterTransactionCommit()` to `@paperclipai/db`. It runs a callback after the outermost transaction commits. It drops the callback on rollback. Outside a transaction it runs the callback at once. A callback that throws never fails the committed work. - Add helpers `trackModelConnected`, `trackTaskCreated`, `trackTaskCompleted`, `trackTaskBlocked`, `trackPlanCreated`, `trackPlanApproved`, and `trackArtifactCreated`. Add `failureCause` to `trackAgentTaskRun`. Assign the new events to `operational_enum_count` retention. - Add `server/src/services/product-telemetry.ts`. It sends each event after commit inside `withTelemetryCompany()`, so Cloud direct delivery gets `company_id` for background writes. - Emit sites: - `model.connected`: `aiConnectionService.save`, for a new connection only. A reconnect sends nothing. `first_for_company` is true when the company had no earlier model connection. - `task.created`: `issueService.create`, after the insert. A deduplicated create, a company import, and a chat conversation send nothing. `created_by_kind` is `routine` for routine runs, `onboarding` for the onboarding wizard's first task, and otherwise `user`, `agent`, or `system`. - `task.completed` and `task.blocked`: `issueService.update`, when the status changes to `done` or `blocked`. The same status again sends nothing. - `plan.created`: `documentService.upsertIssueDocument`, for the first revision of the `plan` document. - `plan.approved`: the accept path of a `request_confirmation` that targets the task's `plan` document. - `artifact.created`: `workProductService.createForIssue` (`direct`), the promotion route (`promotion`), and a run file deliverable (`run_deliverable`). - `agent.task_run.failure_cause`: `emitAgentTaskRun`, for `failed`, `timed_out`, and `interrupted` runs only. - `blocked_reason` mapping: unfinished blocking tasks give `waiting_on_task`. Otherwise an unblock owner of a person or the board gives `waiting_for_person`, and an agent owner gives `waiting_for_agent`. A system write with neither gives `needs_recovery`. A person or agent write with neither gives `unspecified`. - `failure_cause` mapping (stored `errorCode`, with `resultJson.providerFailure.category` for generic provider and adapter codes): - `missing_access`: auth and permission codes (`acpx_auth_required`, `provider_auth_failed`, `user_secret_missing`, `github_access_denied`, `github_repo_not_accessible`, `permission_denied`, `project_access_denied`, `configuration_incomplete`, `connection_unavailable`, `signing_secret_unconfigured`), and provider category `authentication` or `permission`. - `provider_limit`: `provider_quota`, `native_provider_usage_limit`, `native_provider_overloaded`, `github_rate_limited`, `ai_connection_busy`, and provider category `rate_limit`, `quota_exhausted`, or `overloaded`. - `provider_error`: `native_provider_model_rejected`, `provider_transport_failed`, `codex_transient_upstream`, `provider_failed`, `provider_tool_definition_invalid`, and the other provider categories. - `waiting_for_person`: `execution_reconciliation_required`, every code in `EXECUTION_RECONCILIATION_CAUSES`, `issue_waiting_for_response`, and `issue_continuation_waiting_on_review`. - `task_changed`: the task was reassigned, paused, closed, blocked, or stopped by a person (`operator_interrupted`, `cancelled`, `interrupted`, `issue_*` lifecycle codes, `agent_paused`, `queued_comment_discarded`). - `platform_error`: process, server, workspace, sandbox, runner, and storage codes (`process_lost`, `server_shutdown_interrupted`, `setup_failed`, `workspace_*`, `environment_provider_unavailable`, `controller_lease_lost`, and others). - `agent_error`: `adapter_failed` without a provider failure, `invalid_output`, `invalid_response`, `tool_error`, `acpx_turn_failed`, `test_run_failed`, `prompt_injection_blocked`, `tool_execution_outcome_unknown`, `timeout`. - `unknown`: any other code, or no code. - On Cloud direct delivery, every new emit site names the responsible person with `withTelemetryActor()` and `resolveTelemetryPerson()`, as `agent.task_run` does: the task creator, else the task's responsible user, else the run owner. `task.created` uses the creating user, else the agent's on-behalf user. `model.connected` uses the user who owns the connection. A live request still wins. The self-hosted collector envelope does not change. - `failure_cause` builds on the run failure code sets in `continuation-cause.ts`. A test fails when a code in those sets has no telemetry code. The provider failure category decides only for `adapter_failed`, `provider_failed`, or no code. - Work product providers outside `paperclip`, `github`, `vercel`, and `s3` are sent as `custom`. - The dispatch workspace check and execution recovery write `blocked` directly. They call the same after-commit helper, with the task's real blockers and unblock owner. The blocker read runs in a savepoint in the issue dependency layer, so a failed read never aborts the block write. - Update the telemetry README with the emit rules, the after-commit rule, and the `failure_cause` source. - Refresh `tests/runner-e2e/source-sdk-public-inputs.json`, because its check reported a change. ## Privacy Review Privacy review requested. Every new dimension is a fixed enum, a boolean, or a count. No dimension carries a title, a body, a plan step, a connection or account name, an email, a URL, a repository name, a prompt, an error message, or an endpoint address. `failure_cause` is a code that the server picks. The run's error text is never sent. The tests check that a provider message and a connection name do not reach the event. ## Verification - `pnpm vitest run packages/shared/src/telemetry/`: 7 files pass, including the new `product-events.test.ts` (helper payloads, omitted optional values, collector envelope with only registered dimensions, retention class). - `packages/db/src/after-transaction-commit.test.ts`: 4 pass (after commit, rollback drop, savepoint, outside a transaction). - `server/src/__tests__/product-telemetry.test.ts`: 14 pass. They check that each event fires once with the right kind and company scope, that a rollback sends nothing, that a repeated status sends nothing, that a later plan revision sends nothing, and that a reconnect sends nothing. - `server/src/__tests__/agent-task-run-telemetry.test.ts`: 35 pass, including the `failure_cause` mapping table and the emit path. - `server/src/__tests__/issue-thread-interactions-service.test.ts -t Plan`: `plan.approved` fires for a plan confirmation and not for an unrelated confirmation. - `server/src/__tests__/posthog-direct-telemetry.test.ts`: the Cloud direct path sends `company_id`, `user_id`, and `attributed_via` for background lifecycle events, an event with no person stays on the workspace, and `failure_cause` passes through. A self-hosted test checks that a person scope leaves the collector events unchanged. - Existing telemetry tests (connector, interaction, run finalizer, heartbeat, AI connection): 299 pass. - `pnpm --filter @paperclipai/shared typecheck`, `pnpm --filter @paperclipai/db typecheck`, and `pnpm --filter @paperclipai/server typecheck`: pass. - `pnpm verify` returned exit 2 (global CI input changed). Required CI supplies the broad coverage. ## Risks - Merge order: merge and deploy paperclipai/telemetry-backend#150 first. If this change ships first, the collector quarantines the new events. The product behavior does not change. - `afterTransactionCommit` uses the existing open-transaction marker in the database client. A callback that a savepoint registers runs when the outer transaction commits, even if that savepoint rolled back. - `task.blocked` adds one small indexed read inside the update transaction, only when a task enters `blocked`. - `failure_cause` adds one small read for a failed run when the caller did not pass the error code. It runs off the run's critical path, as before. - Low risk otherwise. No schema migration. No change to existing event dimensions. > 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 - Anthropic Claude Opus 5.5 (`claude-opus-5-5`), through Claude Code, with tool use (shell, Git, tests). ## 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: Claude Opus 5.5 <noreply@anthropic.com> |