Skip to content

The open-source app everyone uses to manage agents at work

fix(built-in-agents): allow first-time setup of a needs_setup built-in under board-approval policy (#10129)

Devin Foley176a9e8230b1
diff --git a/server/src/__tests__/built-in-agents.test.ts b/server/src/__tests__/built-in-agents.test.ts
index 51325c7899..b276d846e1 100644
--- a/server/src/__tests__/built-in-agents.test.ts
+++ b/server/src/__tests__/built-in-agents.test.ts
@@ -361,6 +361,41 @@ describeEmbeddedPostgres("built-in agents", () => {
});
});
+ it("completes first-time setup of a needs_setup built-in without a fresh board approval", async () => {
+ const companyId = await seedCompany({ requireApproval: true });
+ const builtIns = builtInAgentService(db);
+
+ // A hired-but-unconfigured built-in row: exists (its hire was already
+ // sanctioned) but its adapter config is still empty → `needs_setup`.
+ const seeded = await builtIns.ensure(companyId, "briefs");
+ expect(seeded.status).toBe("needs_setup");
+
+ // Configuring the adapter for the first time must apply directly instead of
+ // throwing "adapter changes require board approval".
+ const result = await builtIns.provision(companyId, "briefs", {
+ adapterType: "codex_local",
+ adapterConfig: { model: "gpt-5.4" },
+ budgetMonthlyCents: 2500,
+ }, { requestedByUserId: "board-user" });
+
+ expect(result.approval).toBeNull();
+ expect(result.state).toMatchObject({
+ status: "ready",
+ agentId: seeded.agentId,
+ agent: {
+ status: "idle",
+ adapterType: "codex_local",
+ adapterConfig: { model: "gpt-5.4" },
+ budgetMonthlyCents: 2500,
+ },
+ });
+
+ const rows = await db.select().from(agents).where(eq(agents.companyId, companyId));
+ expect(rows).toHaveLength(1);
+ const noApprovals = await db.select().from(approvals).where(eq(approvals.companyId, companyId));
+ expect(noApprovals).toHaveLength(0);
+ });
+
it("rejects adapter types outside the built-in definition allowlist", async () => {
const companyId = await seedCompany();
diff --git a/server/src/services/built-in-agents.ts b/server/src/services/built-in-agents.ts
index fa08e0f034..3a6ffa22e8 100644
--- a/server/src/services/built-in-agents.ts
+++ b/server/src/services/built-in-agents.ts
@@ -1683,7 +1683,23 @@ export function builtInAgentService(db: Db) {
};
}
- if (input.adapterType !== undefined || input.adapterConfig !== undefined) {
+ const providesAdapterSetup = input.adapterType !== undefined || input.adapterConfig !== undefined;
+
+ // A built-in row that has never completed adapter setup (incomplete
+ // config, i.e. `needs_setup`) is still first-time configuration, not a
+ // reconfiguration of a live agent. Its existence was already sanctioned
+ // when the row was created — e.g. the auto-provisioned Reflection Coach
+ // hire approval resolves (`activatePendingApproval`) to an idle row whose
+ // adapterConfig is still empty. Completing that setup applies directly, as
+ // it does when board approval is not required, instead of dead-ending on a
+ // fresh board-approval requirement the operator can never satisfy.
+ if (providesAdapterSetup && !hasCompleteAdapterConfig(existing.adapterType, existing.adapterConfig)) {
+ return { state: await ensure(companyId, key, input), approval: null };
+ }
+
+ // Changing the adapter of an already-configured (`ready`/`paused`)
+ // built-in agent is a genuine reconfiguration and stays gated.
+ if (providesAdapterSetup) {
throw conflict("Built-in agent adapter changes require board approval before they can be applied.", {
code: "built_in_agent_reconfiguration_requires_approval",
key: definition.key,