mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 01:24:30 +01:00
## Thinking Path > - Paperclip manages AI agents and the skills they need for work. > - First-agent setup assigns the bundled operating and onboarding skills. > - An environment plugin can initialize those skills inside a transaction. > - Another request could share that transaction's refresh promise and read before its commit. > - The hire then rejected valid default skills as unknown references. > - This pull request scopes shared refresh work to each database handle and makes concurrent bundled creation idempotent. ## Linked Issues or Issue Description **What happened?** First-agent onboarding on a fresh hosted stack failed with `Invalid company skill selection (unknown references: ...)` after the user entered a Claude API key. The failure occurred during skill assignment, before a provider connection could be verified. The environment plugin initialized the bundled library inside its skill-install transaction. The hire request awaited the same company-wide refresh promise. That promise settled before the outer transaction committed. The hire's separate connection then read an empty library and returned HTTP 422. **Expected behavior** A hire resolves committed bundled skills even when another installer is active. A failed competing transaction must not leave the hire dependent on rolled-back work. Concurrent callers must retain one installed skill per key. **Steps to reproduce** 1. Create a company with no initialized skill library. 2. Start bundled inventory initialization inside a transaction and hold its commit. 3. Resolve first-agent skill selections through the ordinary database handle while initialization is active. 4. Let initialization finish, while the outer transaction is still open. 5. Observe the unknown-reference error from the separate connection. The added real-PostgreSQL regression controls these boundaries without real-clock sleeps. **Paperclip version or commit** Observed on `79dadd86551e4deb254163dd1f952f2908f1d351`. Reproduced locally on `79ef76757879`. **Deployment mode** Hosted Docker deployment. The underlying transaction race also applies to other deployments. Related: #22477 repaired a different first-agent skill upload failure. Searches of open and closed skill/onboarding and skill/transaction changes found no duplicate of this repair. ## What Changed - Store in-flight inventory refreshes by database handle and company. Service instances on the same handle still share work. Other connections and transactions refresh through their own visibility boundary. - Take the existing skill publication advisory lock before the bundled-create recheck. Reuse a concurrent installation once it is visible. Keep normal user-created skill conflict handling intact. - Recheck a shipped release under the skill-row lock before inserting its version. Reuse a matching release and reject a concurrent snapshot with different contents. - Keep the fix in the existing inventory and import owner. No schema, provider, UI, or public API changes are required. - Add commit and rollback regressions that hold the installer open until the competing caller attempts publication. Preseed the folder metadata and use inline packages for this specific creation race so unrelated folder and object-store locks do not settle the race first. - Add concurrent release-seeding cases for matching and corrupted snapshots. Existing tests cover shared refreshes, separate actor visibility, and revoked project access. ## Verification - The original commit/rollback regressions reproduced the unknown-reference HTTP 422 before the repair. - Review regression, red: both concurrent release-seeding cases reproduced PostgreSQL `23505` on `company_skill_versions_skill_release_idx` before the release recheck was added. - Creation-race test: removing the bundled-create recheck makes the tightened commit case fail with HTTP 409. The protected code passes. This proves the test reaches the concurrent-creation boundary. - Green: all six inventory-concurrency cases pass, including commit, rollback, matching release reuse, corrupt release refusal, same-handle coalescing, and separate actor visibility. - Final revision: `5ac8f4d7acc1a2fe5111935d892c5d57ef54b5a6`. All 277 tests passed across nine focused files: company skill service, runtime concurrency, runtime selection, environment skills, plugin-managed skills, managed content, agent skill routes, package upload, and bundled release validation. - `pnpm --filter @paperclipai/server typecheck` passed, including source and test layers, on the final source. - Test command: `pnpm exec vitest run server/src/__tests__/{company-skills-runtime-concurrency,company-skills-service,company-skills-runtime-selection,environment-skills,plugin-managed-skills,managed-skill-content,agent-skills-routes,skill-package-upload}.test.ts server/src/services/bundled-skill-release-validation.test.ts`. - `node scripts/check-test-budget.mjs --files server/src/__tests__/company-skills-runtime-concurrency.test.ts` and `git diff --check` passed. - Environment: local macOS arm64 with real embedded PostgreSQL. Tests use controlled gates rather than real-clock sleeps. - The previous head, `088b8f8822d5bc218f4e5e7cfcf61c510de0776d`, passed all 270 focused tests, server source/test typechecks, and [CI](https://github.com/paperclipai/paperclip/actions/runs/46488494810). The 4/5 review identified the release race and the test gap addressed here. The final revision has now passed fresh CI and review; the results are recorded below. - `pnpm verify --explain` selected 1,981 tests, with 1,978 retained conservatively. Focused local checks cover this repair; required CI supplies the broader typecheck, build, test, Runner, and browser coverage. - Staging diagnosis used the served Core SHA, bounded request logs, and read-only database queries. The logs and row timestamps match the reproduced transaction race. - Test code and service behavior document this internal invariant; no user-facing command or API contract changed. - A deployed onboarding retry with the fixed revision has not been run. This PR does not deploy the repair or validate the user's provider credential. - Current-head [Greptile review](https://github.com/paperclipai/paperclip/pull/23308#issuecomment-7288511940) is 5/5 on `5ac8f4d7acc1a2fe5111935d892c5d57ef54b5a6`. Both prior review threads are resolved. - Final [CI run, attempt 2](https://github.com/paperclipai/paperclip/actions/runs/46491251884/attempts/2) completed successfully on `5ac8f4d7acc1a2fe5111935d892c5d57ef54b5a6`. Scope: typecheck/release registry, build, native Runner checks, general tests, serialized server suites, and all 16 browser shards. GitHub reports the branch as clean and mergeable. - Attempt 1 lost the runners for [browser shard 5](https://github.com/paperclipai/paperclip/actions/runs/46491251884/job/142104554848) and [browser shard 12](https://github.com/paperclipai/paperclip/actions/runs/46491251884/job/142104554842). Those interrupted attempts are not passes. GitHub initially rejected targeted retries while the parent workflow was running. Both shards passed in attempt 2. ## Risks Different database handles now perform their own inventory refresh. The bundled-create lock prevents duplicate publication when these refreshes overlap. Same-handle coalescing and the existing access checks remain effective. The change does not relax unknown-skill validation or normal edit/create conflicts. No migration is needed. ## Model Used OpenAI GPT-6.1 Sol (`gpt-6.1-sol`) through the Codex harness, with xhigh reasoning effort 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 (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>