Fix retry gate and spend hydration tests

This commit is contained in:
Dotta committed 2026-06-06 17:28:12 +00:00
1 parent a012591479
commit d0d44d9ae2
2 files changed
+47 -24

No files matched your search

@@ -55,6 +55,27 @@ describe("monthly spend hydration", () => {
it("recomputes agent spentMonthlyCents from the current utc month instead of returning stale stored values", async () => {
const dbStub = createSelectSequenceDb([
[{
id: "agent-1",
companyId: "company-1",
name: "Budget Agent",
role: "general",
title: null,
reportsTo: null,
capabilities: null,
adapterType: "claude-local",
adapterConfig: {},
runtimeConfig: {},
budgetMonthlyCents: 5000,
spentMonthlyCents: 999999,
metadata: null,
permissions: null,
status: "idle",
pauseReason: null,
pausedAt: null,
createdAt: new Date(),
updatedAt: new Date(),
}],
[{
id: "agent-1",
companyId: "company-1",
+26 -24
View File
@@ -5977,30 +5977,32 @@ export function heartbeatService(db: Db, options: HeartbeatServiceOptions = {})
};
}
const invokability = await getAgentInvokability(agent);
if (!invokability.invokable) {
const contextSnapshot = parseObject(run.contextSnapshot);
const issueId = readNonEmptyString(contextSnapshot.issueId);
await appendRunEvent(run, await nextRunEventSeq(run.id), {
eventType: "lifecycle",
stream: "system",
level: "warn",
message: "Scheduled retry suppressed because the agent is not invokable",
payload: {
retryReason,
scheduledRetryAttempt: nextAttempt,
maxAttempts,
reason: invokability.reason,
invalidOrgChain: invokability.invalidOrgChain,
...invokability.details,
},
});
return {
outcome: "not_scheduled" as const,
reason: "Scheduled retry suppressed because the agent is not invokable",
errorCode: "agent_not_invokable" as const,
issueId,
};
if (retryReason !== MAX_TURN_CONTINUATION_RETRY_REASON) {
const invokability = await getAgentInvokability(agent);
if (!invokability.invokable) {
const contextSnapshot = parseObject(run.contextSnapshot);
const issueId = readNonEmptyString(contextSnapshot.issueId);
await appendRunEvent(run, await nextRunEventSeq(run.id), {
eventType: "lifecycle",
stream: "system",
level: "warn",
message: "Scheduled retry suppressed because the agent is not invokable",
payload: {
retryReason,
scheduledRetryAttempt: nextAttempt,
maxAttempts,
reason: invokability.reason,
invalidOrgChain: invokability.invalidOrgChain,
...invokability.details,
},
});
return {
outcome: "not_scheduled" as const,
reason: "Scheduled retry suppressed because the agent is not invokable",
errorCode: "agent_not_invokable" as const,
issueId,
};
}
}
const schedule =