mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-28 21:46:15 +01:00
fix: allow concurrent agent runs on one Anthropic subscription connection (#13445)
## Thinking Path > - Paperclip manages AI agents and their work. > - Agent runs use provider connections and subscription credentials. > - File-backed subscriptions need a lease while a run writes new credentials. > - Anthropic subscriptions pass a token and do not write a credential file. > - The current lease blocks concurrent Anthropic runs without protecting shared state. > - This pull request limits the lease to file-backed subscriptions and tests both paths. > - The result lets Anthropic runs share one connection safely while file-backed credentials remain serialized. ## Linked Issues or Issue Description **What existing behavior does this improve?** This change improves concurrent use of one subscription connection. Anthropic runs no longer wait for a lease that protects no shared file. **Subsystem affected** server/ — REST API and orchestration services, with related server tests and connection documentation. **Current behavior** The server takes a connection lease for every subscription invocation. The lease blocks a second Anthropic run while the first runtime remains open. **Proposed behavior** The server takes the lease only when the subscription writes a provider authentication file back to the grant. Anthropic runs can proceed at the same time. **Reason and benefit** Anthropic passes its token through an environment variable and writes no file. Removing this unnecessary wait improves concurrency and preserves credential safety for OpenAI and xAI. **Breaking changes** None. OpenAI and xAI keep the existing lease and retry behavior. ## What Changed - Limit the AI credential lease to subscriptions that write a provider authentication file. - Add coverage for concurrent Anthropic runs and hired-agent runs. - Keep the existing OpenAI contention assertions as a sensitivity control. - Update the AI connection documentation to describe the lease boundary. ## Verification - Run `server/src/__tests__/ai-connections.test.ts`. - Run `server/src/__tests__/agent-hire-ai-connections.test.ts`. - Run `server/src/__tests__/heartbeat-ai-subscription-contention.test.ts`. - Run the server type check. - Review the pull request checks after GitHub starts continuous integration. ## Risks The main risk is an incorrect provider classification. The write-back condition remains unchanged, and OpenAI contention tests keep the file-backed lease behavior under test. No schema or API contract changes occur. ## Model Used OpenAI GPT-5. Exact runtime model ID and context window are not exposed in this execution. The model used tool calls, shell commands, and GitHub operations. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
52d120f68d
commit
ee81cee76d
4 files changed
+73
-19
No files matched your search
@@ -243,10 +243,15 @@ export async function prepareManagedAiRuntime(
|
||||
runnerProvider: input.config.provider,
|
||||
acpxAgent: input.config.acpxAgent,
|
||||
});
|
||||
const release =
|
||||
selection.attribution.method === "subscription"
|
||||
? await acquireCredentialLease(db, selection.grant.id)
|
||||
: async () => {};
|
||||
const subscriptionFile =
|
||||
selection.attribution.method === "subscription" &&
|
||||
input.binding.provider !== "anthropic";
|
||||
// A file-backed subscription runs one credential rotation at a time, so it
|
||||
// needs the lease. Anthropic writes no file back, so two runs share no
|
||||
// mutable state and can run at the same time without the lease.
|
||||
const release = subscriptionFile
|
||||
? await acquireCredentialLease(db, selection.grant.id)
|
||||
: async () => {};
|
||||
let home: string | undefined;
|
||||
try {
|
||||
const selectedGrantId = selection.grant.id;
|
||||
@@ -291,9 +296,6 @@ export async function prepareManagedAiRuntime(
|
||||
'cli_auth_credentials_store = "file"\n',
|
||||
{ mode: 0o600 },
|
||||
);
|
||||
const subscriptionFile =
|
||||
selection.attribution.method === "subscription" &&
|
||||
input.binding.provider !== "anthropic";
|
||||
if (subscriptionFile) await writeFile(authFile, value, { mode: 0o600 });
|
||||
else env[capability.envKey] = value;
|
||||
if (
|
||||
|
||||
Reference in new issue
Block a user