A task is finished when it reaches done, not when a run ends
The two real goal tasks from July 9 each got exactly one session: the run completed, the agent never moved the task off backlog, and the heartbeat's "has a completed run" exclusion locked them out forever. The agents could not have closed them anyway — update_task_status requires a task_id the prompt never carried. The progress contract, made explicit end to end: - The task prompt now carries "Task id: ..." and tells the agent exactly how to end a session: done via update_task_status when the work is complete, in_progress with a note on what remains when it is not. - The heartbeat re-enqueues any open task with no run in flight — a completed run that left its task open earns a follow-up session, with the prompt stating how many prior sessions were spent so the agent continues instead of redoing work. The retry budget (3 non-transient runs) still bounds every task; a task that spends it parks with one log line naming it. - Scripted agents in the integration suites now close their tasks the way the contract expects real ones to.
This commit is contained in:
1 parent
2526633bfb
commit
9c85b5ee3c
4 files changed
+147
-14
No files matched your search
@@ -22,7 +22,7 @@ function call(name: string, args: Record<string, unknown>): ToolCall {
|
||||
return { id: `call_${randomUUID()}`, name, arguments: args };
|
||||
}
|
||||
|
||||
/** Scripts the CEO: staff two reports, delegate work, hand off the file in chat, then stop. */
|
||||
/** Scripts the CEO: staff two reports, delegate work, hand off the file in chat, close the kickoff, then stop. */
|
||||
function scriptedCeo(): (input: ProviderToolTurnInput) => Promise<AgentTurnResult> {
|
||||
const script: Array<{ text: string; toolCalls: ToolCall[] }> = [
|
||||
{ text: "Staffing.", toolCalls: [
|
||||
@@ -36,6 +36,7 @@ function scriptedCeo(): (input: ProviderToolTurnInput) => Promise<AgentTurnResul
|
||||
call("write_deliverable", { path: "plan/operating-plan.md", content: "# OrbitOps Operating Plan\n\n- Validate demand\n- Launch booking site\n" }),
|
||||
] },
|
||||
{ text: "Handing off the plan.", toolCalls: [] },
|
||||
{ text: "Closing the kickoff.", toolCalls: [] },
|
||||
{ text: "Team staffed, work delegated, plan written.", toolCalls: [] },
|
||||
];
|
||||
let index = 0;
|
||||
@@ -55,6 +56,17 @@ function scriptedCeo(): (input: ProviderToolTurnInput) => Promise<AgentTurnResul
|
||||
rawResponseJson: JSON.stringify({ id: `resp_${index}` }),
|
||||
};
|
||||
}
|
||||
if (index === 4) {
|
||||
// The prompt carries the task id so the agent can actually close its task.
|
||||
const firstUser = input.messages.find((message) => message.role === "user");
|
||||
const taskId = firstUser ? /Task id: (\S+)/.exec(firstUser.text)?.[1] : undefined;
|
||||
index += 1;
|
||||
return {
|
||||
text: "Closing the kickoff.",
|
||||
toolCalls: taskId ? [call("update_task_status", { task_id: taskId, status: "done" })] : [],
|
||||
rawResponseJson: JSON.stringify({ id: `resp_${index}` }),
|
||||
};
|
||||
}
|
||||
const turn = script[index] ?? { text: "done", toolCalls: [] };
|
||||
index += 1;
|
||||
return { text: turn.text, toolCalls: turn.toolCalls, rawResponseJson: JSON.stringify({ id: `resp_${index}` }) };
|
||||
@@ -150,6 +162,11 @@ describe("autonomous bootstrap run", () => {
|
||||
const run = state.taskRuns.find((r) => r.id === claimed!.id);
|
||||
expect(run?.state).toBe("completed");
|
||||
|
||||
// The CEO closed the kickoff task using the task id the prompt carries.
|
||||
const kickoffTask = connection.db.prepare("select status from tasks where id = (select task_id from task_runs where id = ?)")
|
||||
.get(claimed!.id) as { status: string };
|
||||
expect(kickoffTask).toEqual({ status: "done" });
|
||||
|
||||
// Stage 4 heartbeat: the CEO-delegated task (assigned to a hired, heartbeat-enabled
|
||||
// agent, with no run yet) is enqueued exactly once for autonomous execution.
|
||||
const enqueued = taskExecution.enqueueHeartbeatRuns();
|
||||
@@ -166,11 +183,26 @@ describe("autonomous bootstrap run", () => {
|
||||
|
||||
test("a goal created after onboarding reaches the CEO and runs autonomously", async () => {
|
||||
const connection = new DatabaseConnection(join(tmpdir(), `ac-goal-${randomUUID()}.db`));
|
||||
const providers = new ProviderService(connection.db, providerAdapters, testVault, undefined, async () => ({
|
||||
text: "Reviewed the goal and posted the operating plan.",
|
||||
toolCalls: [],
|
||||
rawResponseJson: JSON.stringify({ id: "resp_goal" }),
|
||||
}));
|
||||
// A minimal well-behaved agent: does its session, closes its task, then stops.
|
||||
const providers = new ProviderService(connection.db, providerAdapters, testVault, undefined, async (input: ProviderToolTurnInput) => {
|
||||
const firstUser = input.messages.find((message) => message.role === "user");
|
||||
const taskId = firstUser && firstUser.role === "user" ? /Task id: (\S+)/.exec(firstUser.text)?.[1] : undefined;
|
||||
const alreadyClosed = input.messages.some(
|
||||
(message) => message.role === "tool" && message.results.some((result) => result.toolName === "update_task_status"),
|
||||
);
|
||||
if (taskId && !alreadyClosed) {
|
||||
return {
|
||||
text: "Reviewed the goal; closing the kickoff.",
|
||||
toolCalls: [call("update_task_status", { task_id: taskId, status: "done" })],
|
||||
rawResponseJson: JSON.stringify({ id: "resp_goal_close" }),
|
||||
};
|
||||
}
|
||||
return {
|
||||
text: "Reviewed the goal and posted the operating plan.",
|
||||
toolCalls: [],
|
||||
rawResponseJson: JSON.stringify({ id: "resp_goal" }),
|
||||
};
|
||||
});
|
||||
const onboarding = new OnboardingService({ db: connection.db, saveProviderCredential: (input) => providers.saveCredential(input) });
|
||||
const organization = new OrganizationService(connection.db);
|
||||
const taskExecution = new TaskExecutionService(connection.db, providers);
|
||||
|
||||
Reference in new issue
Block a user