Skip to Content
Qube
Design history

Design: task board Done semantics, None-schedule tasks, AI task drafts, tool group titles

Date: 2026-10-29. Status: approved sections 1–4, pending spec review.

Date: 2026-10-29. Status: approved sections 1–4, pending spec review.

1. Problem

  1. Manually triggering a recurring task never lands it in Done. Root cause: isDone in components/shared/scheduling-tab.tsx only understands intervalMinutes. Real recurring tasks use wall-clock schedules (hour/minute/weekdays/monthDay, e.g. the daily 6 AM report in production data has no intervalMinutes), so they stay in To do forever after running.
  2. There is no way to create a task without a time: a reminder / backlog item the agent should just do at the next heartbeat, still visible in Settings.
  3. The New task dialog forces manual field entry (name, instructions, timing) before anything exists.
  4. Finished tool-group titles say used 1 tool for a single tool, and show a connector action label instead of a count for connector-only groups.

2. Decisions (from brainstorming)

  • Done detection trusts persisted nextRunAt instead of recomputing windows.
  • Task drafts are generated by a new server endpoint with the default model.
  • Scheduling none means a schedule-less task card + a heartbeat reminder; heartbeat fulfils it with a full task run.
  • Single finished tool shows its friendly label; connector-only groups show used N apps for any N including 1.

3. Done column + manual re-runs

3.1 Rule

Extract board status into lib/scheduler/board-status.ts as isTaskDone(task, now):

  • once: Done iff lastRunAt != null.
  • interval (any shape: intervalMinutes, wall-clock, weekly, monthly): Done iff lastRunAt != null && nextRunAt != null && now < nextRunAt.
  • none: Done iff lastRunAt != null, else To do.

SchedulingTab uses this instead of its local isDone. Manual trigger sets lastRunAt = now and advances nextRunAt, so a finished run lands in Done inside its own period for every recurring shape.

3.2 Re-triggering Done tasks

triggerTask currently returns early for any Done task. Change to block only finished one-shots:

if (!task) return;
if (task.schedule.kind === "once" && isTaskDone(task, Date.now())) return;

Recurring and none tasks stay re-runnable; fresh timestamps keep them Done. The in-flight runningRef guard is unchanged.

3.3 Acceptance

  • Daily/weekly/monthly recurring tasks appear in Done after a run (manual or scheduled) until nextRunAt passes, then return to To do.
  • Re-triggering a Done recurring task runs it again and it stays Done.
  • One-shot behavior is unchanged.

4. none schedule kind

4.1 Model

  • TaskScheduleKind becomes "interval" | "once" | "none".
  • ScheduledTask.nextRunAt becomes number | null. createTask with none stores schedule: { kind: "none" } and nextRunAt: null.
  • updateTask: switching to none sets nextRunAt: null; switching away recomputes it via the existing rules.
  • updateTaskRunTime: explicit none branch — set lastRunAt, keep nextRunAt: null.

4.2 Scheduler must ignore null nextRunAt

  • Tick due filter: t.enabled && t.nextRunAt != null && t.nextRunAt <= now. (null <= now is true in JS — the explicit check is the whole fix.)
  • handleMissedExecutions skips tasks with null nextRunAt.
  • Board recap (heartbeat-brief) renders null as manual, e.g. manual — runs from the board.

4.3 Agent tools + HTTP API

  • schedule_task schemas (zod in lib/pi/agent-tools.ts, TypeBox in lib/pi/durable-scheduler.ts): accept "none" in scheduleKind. The recurring-cue creation gate is unchanged (none without a cue is still rejected on the agent path; the settings UI saves via HTTP directly).
  • POST /api/scheduler/tasks create/update accept scheduleKind: "none".
  • trigger on a none task runs executeTask with the task's stored permissions, then updateTaskRunTime → card moves to Done.
  • On trigger of a none task, best-effort remove its linked heartbeat reminder (section 4.4) so the next heartbeat does not run it twice.

4.4 Heartbeat fulfilment (full task run)

  • Saving a none task (HTTP create) also writes a heartbeat checklist entry via addPendingAction, containing a machine marker plus human text, e.g. [manual-task:<taskId>] <name> — <instructions, truncated>.
  • In executeHeartbeat, after consumeDueActions, split dues into manual-task refs (marker present, task still exists, enabled, kind none, lastRunAt == null) and regular dues. Regular dues flow through the existing path unchanged.
  • Each linked manual task runs via executeTask(task) — full scheduled-task powers, the task's own permission flags — then updateTaskRunTime and, on success, recordAnnouncement exactly like a scheduled run. Success consumes the reminder (already consumed; do not requeue). Failure requeues the reminder through the existing requeueDueActions path.
  • none fulfilment requires heartbeat enabled; the New task dialog says so.

4.5 Board presentation

  • Run segmented control gains None. With none selected, timing inputs are hidden and canCreate requires only name + instructions.
  • Dialog copy for none: never auto-runs; card stays until dragged to In progress or deleted; also picked up by the next heartbeat with full powers; lands in Done when finished.
  • Done-column persist protection stays interval-only; finished none cards follow one-shot overflow cleanup.
  • Log/recap lines show manual instead of a next-run time.

5. AI task drafts in the New task dialog

5.1 Endpoint

New POST /api/scheduler/draft:

  • Request: { prompt: string, current?: DraftInput } where DraftInput is the current form values for edit passes.
  • Uses createPiModelClientForRequest with the configured default model (works for ChatGPT defaults via the request proxy), ~60 s timeout.
  • System prompt demands one JSON object: { name, instructions, scheduleKind: once|interval|none, intervalMinutes?, runAt?, hour?, minute?, weekdays?, monthDay? }, plus current date/time and timezone. Guidance: explicit timing wins; recurring language → interval or wall-clock fields; one-off/reminder with no timing → none; ambiguous → sensible default, never an empty schedule.
  • Pure helpers in lib/scheduler/task-draft.ts (buildDraftPrompt, validateDraft): non-empty name/instructions, known kind, ranges (hour 0–23, minute 0–59, weekdays 0–6, positive intervalMinutes, runAt parses to a future time). Invalid → 4xx with message.
  • No persistence, no side effects. Draft failures never create tasks.

5.2 Dialog flow (SchedulingTab create dialog)

Three states, same morph animation as DocComposer idle ↔ three-dots:

  1. prompt — title, description, single pill input (placeholder e.g. “Describe the task — timing optional…”). This is the initial state every time the dialog opens.
  2. generating — the pill morphs to the three-dot animation while the draft endpoint runs (first draft and every edit).
  3. review — today's fields prefilled from the draft (Name, Instructions, Once/Recurring/None incl. timing inputs), pill pinned at bottom for follow-up edits, green tick button right of the pill = save (same handleCreate path as today, then close + refresh).
  • Each edit sends current draft + edit text; the model returns a full replacement draft. All fields stay hand-editable at any time.
  • The AI never saves: only the green tick persists.
  • No usable default model or draft failure → today's fully-manual form, unchanged, with the existing Create button.
  • New presentational PromptPill (components/shared/prompt-pill.tsx) carries the idle/dots states; DocComposer is not refactored in this change.

6. Finished tool-group titles

In ToolGroupWithTitle (components/examples/base.tsx), live (running) titles are unchanged. Finished titles:

  • Extract pure finishedGroupTitle({ labels, visibleCount, connectorOnly, connectorAppCount }) into a tested module (e.g. components/assistant-ui/tools/group-title.ts).
  • connectorOnly (every visible tool resolves to connector meta, via getConnectorMetaForTool or the existing mcp_tool_call/connect_service arg inference) → used ${connectorAppCount} app(s), icons unchanged before the text. Applies for any count, including exactly one app.
  • Else single visible tool → its friendly label (labels[last]), never used 1 tool and never a raw id.
  • Else mixed/multi non-connector → today's behavior (last label when connector icons present, otherwise used N tools).
  • Hidden inline tools (TodoWidth, present_file) and reasoning parts keep today's counting rules.

7. Tests

  • board-status: once done, interval done/not-done across boundary, wall-clock daily done/not-done, manual re-run timestamps stay Done, none before/after run.
  • task-store: create/update none, nextRunAt: null round-trip, updateTaskRunTime none-branch, kind switching.
  • Scheduler tick + missed-execution skip null nextRunAt (regression: null <= now is true).
  • task-draft: prompt builder contents, validator accept/reject matrix.
  • Draft route: thin-handler tests with mocked model client (success, invalid JSON, no default model).
  • group-title: single tool → label; connector-only 1/2/3 apps → counts; mixed → legacy behavior; hidden tools excluded.
  • Heartbeat manual-task split: ref extraction, success consumes, failure requeues, already-done/missing/disabled tasks skipped.
  • Existing suites (tool-labels, durable-scheduler, agent-proactivity, scheduler/announcement tests) stay green; extend where schemas changed.

8. Rollout + risks

  • One spec, implemented as separate commits per section (3 → 4 → 5 → 6).
  • Data migration: none. Existing persisted tasks have numeric nextRunAt; only new none tasks store null. Readers must tolerate both (typed).
  • Key risk: heartbeat executing none tasks with full powers (sends allowed per instructions). Mitigations: task permissions UI unchanged and enforced by createTaskPermissionChecker; instructions are user-authored; run only when heartbeat enabled; outcome announced once.
  • Secondary risk: model-generated schedules misfire (wrong time). Mitigations: server-side validation, full review step before save, manual override.
Edit on GitHub

On this page