Reject stale built-in approval setup retries

This commit is contained in:
Dotta committed 2026-07-09 18:50:07 +00:00
1 parent bce8dacb21
commit 0aee005b1f
2 files changed
+22

No files matched your search

@@ -197,6 +197,17 @@ describeEmbeddedPostgres("built-in agents", () => {
},
});
await expect(builtIns.provision(companyId, "briefs", {
budgetMonthlyCents: 7500,
})).rejects.toMatchObject({
status: 409,
details: {
code: "built_in_agent_pending_approval",
key: "briefs",
agentId: result.state.agentId,
},
});
await db
.update(agents)
.set({
+11
View File
@@ -239,6 +239,10 @@ function builtInAgentNotConfiguredError(state: BuiltInAgentState) {
});
}
function hasProvisionSetupInput(input: BuiltInAgentProvisionInput) {
return input.adapterType !== undefined || input.adapterConfig !== undefined || input.budgetMonthlyCents !== undefined;
}
function rowIsBuiltInAgent(row: typeof agents.$inferSelect, key: string) {
const marker = readBuiltInAgentMarker(row.metadata);
return marker?.key === key;
@@ -368,6 +372,13 @@ export function builtInAgentService(db: Db) {
const existing = await findSingleAgent(companyId, definition);
if (existing) {
if (existing.status === "pending_approval") {
if (hasProvisionSetupInput(input)) {
throw conflict("Built-in agent setup is already pending board approval.", {
code: "built_in_agent_pending_approval",
key: definition.key,
agentId: existing.id,
});
}
const approval = await approvalSvc.findOpenHireApprovalForAgent(companyId, existing.id);
return {
state: state(definition, existing),