mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 01:31:36 +00:00
fix(agents): keep not_required delivery status when completion_announced_at exists (#108710)
* fix(agents): keep not_required delivery status when completion_announced_at exists for expectsCompletionMessage=false runs createDeliveryFromTypedColumns unconditionally overrode status to 'delivered' when completion_announced_at was present, even for runs where expects_completion_message is false. This produced a contradictory delivery state where a run that does not require completion delivery was marked as delivered. Only set status to 'delivered' when expects_completion_message is true. For not_required runs that still have completion_announced_at recorded (for informational purposes), preserve announcedAt without overriding the status. * test(agents): cover tainted delivery rows --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -3,6 +3,8 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { executeSqliteQuerySync, getNodeSqliteKysely } from "../infra/kysely-sync.js";
|
||||
import type { DB as OpenClawStateKyselyDatabase } from "../state/openclaw-state-db.generated.js";
|
||||
import {
|
||||
closeOpenClawStateDatabaseForTest,
|
||||
openOpenClawStateDatabase,
|
||||
@@ -14,6 +16,8 @@ import {
|
||||
} from "./subagent-registry.store.sqlite.js";
|
||||
import type { SubagentRunRecord } from "./subagent-registry.types.js";
|
||||
|
||||
type SubagentRegistryDatabase = Pick<OpenClawStateKyselyDatabase, "subagent_runs">;
|
||||
|
||||
function createRun(overrides: Partial<SubagentRunRecord> = {}): SubagentRunRecord {
|
||||
return {
|
||||
runId: "run-one",
|
||||
@@ -121,6 +125,57 @@ describe("subagent registry sqlite store", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves announcedAt for not_required delivery when completion was announced", async () => {
|
||||
await withTempStateEnv(async () => {
|
||||
const run = createRun({
|
||||
expectsCompletionMessage: false,
|
||||
completion: { required: false },
|
||||
delivery: { status: "not_required", announcedAt: 300 },
|
||||
});
|
||||
|
||||
saveSubagentRegistryToSqlite(new Map([[run.runId, run]]));
|
||||
|
||||
const restored = loadSubagentRegistryFromSqlite();
|
||||
const restoredRun = restored.get(run.runId)!;
|
||||
expect(restoredRun.delivery?.status).toBe("not_required");
|
||||
expect(restoredRun.delivery?.announcedAt).toBe(300);
|
||||
expect(restoredRun.delivery?.deliveredAt).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it("repairs a tainted delivered status when completion is not required", async () => {
|
||||
await withTempStateEnv(async () => {
|
||||
const run = createRun({
|
||||
expectsCompletionMessage: false,
|
||||
completion: { required: false },
|
||||
delivery: { status: "not_required", announcedAt: 300 },
|
||||
});
|
||||
saveSubagentRegistryToSqlite(new Map([[run.runId, run]]));
|
||||
|
||||
const { db } = openOpenClawStateDatabase();
|
||||
const stateDb = getNodeSqliteKysely<SubagentRegistryDatabase>(db);
|
||||
executeSqliteQuerySync(
|
||||
db,
|
||||
stateDb
|
||||
.updateTable("subagent_runs")
|
||||
.set({
|
||||
payload_json: JSON.stringify({
|
||||
...run,
|
||||
delivery: { status: "delivered", announcedAt: 300, deliveredAt: 300 },
|
||||
}),
|
||||
})
|
||||
.where("run_id", "=", run.runId),
|
||||
);
|
||||
|
||||
const restoredRun = loadSubagentRegistryFromSqlite().get(run.runId)!;
|
||||
expect(restoredRun.delivery).toMatchObject({
|
||||
status: "not_required",
|
||||
announcedAt: 300,
|
||||
deliveredAt: 300,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("does not read or delete the retired JSON registry at runtime", async () => {
|
||||
await withTempStateEnv(async () => {
|
||||
const legacyRun = createRun({
|
||||
|
||||
@@ -89,13 +89,16 @@ function createDeliveryFromTypedColumns(
|
||||
...(row.pending_final_delivery_last_error !== null
|
||||
? { lastError: row.pending_final_delivery_last_error }
|
||||
: {}),
|
||||
...(row.completion_announced_at !== null
|
||||
...(row.completion_announced_at !== null && row.expects_completion_message === 1
|
||||
? {
|
||||
status: "delivered",
|
||||
announcedAt: row.completion_announced_at,
|
||||
deliveredAt: delivery?.deliveredAt ?? row.completion_announced_at,
|
||||
}
|
||||
: {}),
|
||||
: row.completion_announced_at !== null
|
||||
? { announcedAt: row.completion_announced_at }
|
||||
: {}),
|
||||
...(row.expects_completion_message === 0 ? { status: "not_required" } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user