{"record":{"id":"d0da3ef50319d2ba","repo":"Budibase/budibase","slug":"unable-to-allocate-teams-app-package-version","errorCode":null,"errorMessage":"Unable to allocate Teams app package version","messagePattern":"Unable to allocate Teams app package version","errorType":"http","errorClass":"HTTPError","httpStatus":409,"severity":"error","filePath":"packages/server/src/api/controllers/ai/agents.ts","lineNumber":311,"sourceCode":"        ...agent,\n        MSTeamsIntegration: {\n          ...agent.MSTeamsIntegration,\n          appPackageVersion,\n        },\n      })\n      return { agent: updatedAgent, messagingEndpointUrl, appPackageVersion }\n    } catch (error) {\n      if (\n        db.isDocumentConflictError(error) &&\n        attempt < TEAMS_APP_PACKAGE_VERSION_RETRIES - 1\n      ) {\n        continue\n      }\n      throw error\n    }\n  }\n\n  throw new HTTPError(\"Unable to allocate Teams app package version\", 409)\n}\n\nexport async function fetchTools(ctx: UserCtx<void, ToolMetadata[]>) {\n  ctx.body = await sdk.ai.agents.getAvailableToolsMetadata()\n}\n\nexport async function fetchAgents(ctx: UserCtx<void, FetchAgentsResponse>) {\n  const agents = await sdk.ai.agents.fetch()\n  ctx.body = { agents: agents.map(toAgentResponse) }\n}\n\nexport async function createAgent(\n  ctx: UserCtx<CreateAgentRequest, CreateAgentResponse>\n) {\n  const body = ctx.request.body\n  const createdBy = ctx.user?._id!\n  const globalId = db.getGlobalIDFromUserMetadataID(createdBy)\n  const projectIds = await resolveProjectIds(body.projectIds)","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/agents.ts#L293-L329","documentation":"After a semver bump, the function attempts to persist the new app package version by calling sdk.ai.agents.update inside a retry loop over deployment targets. If every attempt fails (caught errors lead to 'continue') and the loop is exhausted, the function throws this 409 HTTPError indicating it could not allocate a Teams app package version.","triggerScenarios":"All iterations of the update loop fail — e.g. concurrent updates from multiple calls racing on the same agent, sdk.ai.agents.update throwing repeatedly (conflict/optimistic-locking or API failure), then control falls past the loop to the final throw.","commonSituations":"Two users/automations deploying the Teams app for the same agent simultaneously; transient CouchDB write conflicts during every retry; agent document deleted mid-loop.","solutions":["Retry the operation — the 409 signals a conflict, likely a concurrent deployment of the same agent","Ensure only one deployment per agent runs at a time (serialize at the caller, add a lock)","Check server logs for the underlying error from sdk.ai.agents.update that caused every iteration to fail","Verify the agent still exists and MSTeamsIntegration is intact, then redeploy"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Ensure no concurrent deployment is in flight for this agent before calling\nconst lockKey = `teams-deploy:${agent._id}`\nif (await cache.get(lockKey)) throw new Error(\"A Teams deployment is already in progress for this agent\")\nawait cache.store(lockKey, true, { ttl: 60 })","typeGuard":null,"tryCatchPattern":"try {\n  await allocateMSTeamsAppPackageVersion({ agent, messagingEndpointUrl })\n} catch (err) {\n  if (err instanceof HTTPError && err.status === 409) {\n    // wait for the competing deployment to finish, then retry once\n    await new Promise(r => setTimeout(r, 2000))\n    await allocateMSTeamsAppPackageVersion({ agent, messagingEndpointUrl })\n  } else { throw err }\n}","preventionTips":["Serialize deployments per agent with a lock or queue","Avoid triggering Teams deployment from multiple places concurrently","Log the underlying sdk.ai.agents.update errors inside the loop for diagnosability","Back off and retry 409s with jitter"],"tags":["concurrency","conflict","msteams","server"],"backgroundTag":"concurrent-update-conflict","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}