Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/coding-agent/src/features/step-cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,10 @@ export class StepCronRuntime {
...(options.sessionCreated ? { sessionCreated: true } : {}),
...(options.title ? { title: options.title.slice(0, CRON_MAX_TITLE_LENGTH) } : {}),
...(options.status ? { status: options.status } : {}),
// `CronStatusReason` is part of the create options, not only the update
// patch: a host that imports a task whose bound session is already gone
// creates it paused, and the reason has to survive that same write.
...(options.statusReason ? { statusReason: options.statusReason } : {}),
...(options.inputs ? { inputs: { skills: [...(options.inputs.skills ?? [])] } } : {}),
...(options.model ? { model: { ...options.model } } : {}),
...(options.permissionPreset ? { permissionPreset: options.permissionPreset } : {}),
Expand Down
26 changes: 26 additions & 0 deletions packages/coding-agent/test/step-cron.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,32 @@ test("an unschedulable persisted recurrence does not block other jobs on restart
});

describe("desktop cron task fields", () => {
test("a task created paused for a missing session keeps its reason", () => {
// The record reader validates `statusReason`, so a host that creates a task
// already paused (an imported task whose session is gone) must have the
// reason written on creation, not only through a later update.
const now = Date.UTC(2026, 0, 1, 12, 0);
const directory = makeDirectory();
const file = path.join(directory, "tasks.json");
const first = new StepCronRuntime({ now: () => now, jitterRatio: 0, storagePath: file });
const created = first.create("0 9 * * *", "orphaned task", true, true, true, {
id: "orphan",
sessionId: "session-gone",
status: "paused",
statusReason: "session_missing",
origin: "desktop",
autoExpireMs: null,
jitter: false,
}).job;
expect(created.statusReason).toBe("session_missing");

const reloaded = new StepCronRuntime({ now: () => now, jitterRatio: 0, storagePath: file });
reloaded.start(directory, true);
const record = reloaded.list().find((job) => job.id === "orphan");
expect(record?.statusReason).toBe("session_missing");
expect(record?.status).toBe("paused");
});

test("creates a v2 task with task session metadata and updates it", () => {
const now = Date.UTC(2026, 0, 1, 12, 0);
const directory = makeDirectory();
Expand Down
Loading