Skip to content

RFC: durable task lifecycle and evidence model #559

Closed

Description

@somewan820

Context

#544 proposes moving Maka toward a durable, recoverable, observable, and orchestratable agent platform.

One suggested roadmap item is Task model hardening:

tighten task status, claim/review/done flow, artifact linkage, failure reason, owner, and assignee semantics.

This issue focuses on the smallest durable task model that can support long-running agent work, recovery, observability, and future workflow orchestration without turning tasks
into a UI-only checklist or a subagent dispatch queue.

Problem

Long agent work often contains many implicit tasks, but without structured runtime state, Maka cannot reliably answer:

  • what task is currently active?
  • which tasks are done, blocked, failed, or still pending?
  • what evidence proves a task is complete?
  • what caused a task to become blocked?
  • which run/tool/artifact produced the evidence?
  • after interruption or restart, which task state is still trusted?

Free-text checklists help the model reason, but they are not enough as a durable platform contract.

Goals

Define a minimal durable task lifecycle model for Maka.

The model should:

  • provide a typed task record;
  • define allowed status transitions;
  • require evidence for completed / blocked / failed states;
  • link tasks to session/run/tool/artifact references;
  • support conservative resume behavior after interruption;
  • be observable through runtime events or trace projections;
  • stay independent from subagent dispatch;
  • stay independent from heavy project-management UI.

Non-goals

This issue does not aim to:

  • build a full workflow engine;
  • implement multi-agent assignment;
  • implement cron / automation scheduling;
  • replace existing AgentRun or RuntimeEvent models;
  • create a large project-management UI;
  • treat task status as stronger than filesystem, git, test, or tool evidence;
  • make tasks a permission boundary.

Proposed Task Record

type TaskStatus =
  | "pending"
  | "in_progress"
  | "blocked"
  | "completed"
  | "failed"
  | "cancelled";

interface AgentTask {
  id: string;
  sessionId: string;
  parentTaskId?: string;

  title: string;
  description?: string;

  status: TaskStatus;

  createdAt: string;
  updatedAt: string;

  owner?: "main_agent" | "user" | "system";
  assignee?: string;

  currentRunId?: string;
  relatedRunIds?: string[];
  relatedToolCallIds?: string[];
  artifactRefs?: string[];

  blockedReason?: string;
  failureReason?: string;
  completionEvidence?: string;

  resumeTrust?: "trusted" | "needs_revalidation" | "stale" | "repaired" | "untrusted";
}

This is intentionally small. Fields can be added later only when a concrete workflow needs them.

Status Semantics

Suggested status meanings:

  • pending: declared but not started.
  • in_progress: actively being worked on.
  • blocked: cannot continue without external input, missing dependency, permission, or failed prerequisite.
  • completed: finished with evidence.
  • failed: attempted and ended unsuccessfully with a reason.
  • cancelled: intentionally stopped and should not be resumed automatically.

Transition Rules

Suggested allowed transitions:

pending -> in_progress
pending -> cancelled

in_progress -> blocked
in_progress -> completed
in_progress -> failed
in_progress -> cancelled

blocked -> in_progress
blocked -> cancelled
blocked -> failed

failed -> pending
failed -> cancelled

completed -> in_progress   only if explicitly reopened
cancelled -> pending       only if explicitly reopened

Invalid transitions should be rejected or recorded as repair events.

Evidence Rules

Some statuses should require evidence:

  • blocked requires blockedReason.
  • failed requires failureReason.
  • completed requires completionEvidence.

Evidence should prefer durable references when possible:

  • tool call id;
  • run id;
  • file/artifact ref;
  • test command result;
  • user confirmation;
  • verifier/scorer result;
  • diff or patch ref.

A task marked completed should not override reality. If later filesystem/git/test evidence contradicts it, resume should mark it as needs_revalidation or reopen it.

Runtime Events

Task changes should be observable. Possible event types:

task_created
task_updated
task_started
task_blocked
task_completed
task_failed
task_cancelled
task_reopened
task_resume_classified
task_repaired

Each event should include:

  • task id;
  • session id;
  • run id if available;
  • previous status;
  • next status;
  • reason/evidence;
  • timestamp.

Resume Behavior

On resume or startup recovery, task state should be classified conservatively.

Suggested trust levels:

  • trusted: terminal state has durable evidence and linked events are intact.
  • needs_revalidation: state may still be correct but depends on external files, tests, or tool outputs that should be checked again.
  • stale: task was in progress when the run/session was interrupted.
  • repaired: recovery logic changed the task projection.
  • untrusted: event log is corrupt, missing, or internally inconsistent.

Examples:

  • completed with linked test result and unchanged artifact refs -> trusted.
  • in_progress when app crashed -> stale.
  • blocked due to permission prompt before restart -> needs_revalidation.
  • task references a missing run/tool/artifact -> untrusted.
  • recovery fixes an invalid transition -> repaired.

Relationship To Other Roadmap Items

This task model can become a shared foundation for:

  • resume: knowing what work can continue;
  • observability: explaining what happened;
  • dynamic workflow: adding dependencies and retry later;
  • cron / automation: scheduled runs can create or update tasks later;
  • multi-agent collaboration: assignment/handoff can build on task records later;
  • AHE / benchmark loop: task traces can become evidence.

But this issue should not implement those higher-level systems.

Possible PR Split

  1. RFC / docs only: define task record, statuses, transition rules, evidence rules, and resume classification.
  2. Type definitions and validators.
  3. Task event projection on top of existing runtime/session storage.
  4. Minimal task tool surface behind a feature flag:
    • task_create
    • task_update
    • task_list
    • optional task_get
  5. Basic UI/trace display for current task, blocked reason, and completion evidence.
  6. Recovery tests for interrupted, corrupt, stale, and contradictory task states.

Acceptance Criteria

  • A minimal task lifecycle contract is documented.
  • Task statuses and allowed transitions are clearly defined.
  • Completed / blocked / failed states require evidence or reason fields.
  • Task records can link to session/run/tool/artifact references.
  • Resume trust classification is defined.
  • The design does not treat tasks as subagent dispatch.
  • The design does not require a large project-management UI.
  • Future workflow, automation, and multi-agent work can build on the same task state model.
中文版本

背景

#544 提出 Maka 后续要朝着“长期可恢复、可观察、可编排的 agent 平台”演进。

其中一个 roadmap 项是 Task model hardening:

收紧 task 状态、claim/review/done 流程、artifact 关联、失败原因、owner 和 assignee 语义。

这个 issue 聚焦在一个最小可用的 durable task model:它应该能支撑长期 agent 工作、恢复、可观测性和未来 workflow 编排,但不应该变成 UI-only checklist,也不应该变成 subagent 派发队列。

问题

一次长 agent 工作里通常包含很多隐式任务,但如果这些进度没有结构化 runtime state,Maka 就很难可靠回答:

  • 当前正在做哪个 task?
  • 哪些 task 已完成、阻塞、失败或仍待处理?
  • 什么证据证明 task 已完成?
  • task 为什么被阻塞?
  • 哪个 run/tool/artifact 产生了相关证据?
  • 中断或重启后,哪些 task 状态仍然可信?

自由文本 checklist 可以帮助模型推理,但它不足以作为 durable platform contract。

目标

定义一个最小 durable task lifecycle model。

这个模型应该:

  • 提供类型化 task record;
  • 定义允许的状态流转;
  • 对 completed / blocked / failed 状态要求证据或原因;
  • 关联 session/run/tool/artifact references;
  • 支持中断后的保守 resume 行为;
  • 可以通过 runtime events 或 trace projections 被观测;
  • 独立于 subagent dispatch;
  • 独立于重型项目管理 UI。

非目标

这个 issue 不打算:

  • 构建完整 workflow engine;
  • 实现 multi-agent assignment;
  • 实现 cron / automation scheduling;
  • 替换现有 AgentRun 或 RuntimeEvent 模型;
  • 创建大型项目管理 UI;
  • 让 task status 的权威性高于 filesystem、git、test 或 tool evidence;
  • 把 task 当作 permission boundary。

建议的 Task Record

type TaskStatus =
  | "pending"
  | "in_progress"
  | "blocked"
  | "completed"
  | "failed"
  | "cancelled";

interface AgentTask {
  id: string;
  sessionId: string;
  parentTaskId?: string;

  title: string;
  description?: string;

  status: TaskStatus;

  createdAt: string;
  updatedAt: string;

  owner?: "main_agent" | "user" | "system";
  assignee?: string;

  currentRunId?: string;
  relatedRunIds?: string[];
  relatedToolCallIds?: string[];
  artifactRefs?: string[];

  blockedReason?: string;
  failureReason?: string;
  completionEvidence?: string;

  resumeTrust?: "trusted" | "needs_revalidation" | "stale" | "repaired" | "untrusted";
}

这个模型有意保持很小。只有当具体 workflow 需要时,再新增字段。

状态语义

建议状态含义:

  • pending:已声明,但尚未开始。
  • in_progress:正在处理。
  • blocked:因为外部输入、缺失依赖、权限、前置步骤失败等原因无法继续。
  • completed:已完成,并有证据。
  • failed:已经尝试,但以失败结束,并有失败原因。
  • cancelled:被主动取消,不应该自动恢复执行。

状态流转规则

建议允许的状态流转:

pending -> in_progress
pending -> cancelled

in_progress -> blocked
in_progress -> completed
in_progress -> failed
in_progress -> cancelled

blocked -> in_progress
blocked -> cancelled
blocked -> failed

failed -> pending
failed -> cancelled

completed -> in_progress   only if explicitly reopened
cancelled -> pending       only if explicitly reopened

非法状态流转应该被拒绝,或被记录为 repair event。

证据规则

部分状态必须带证据或原因:

  • blocked 需要 blockedReason。
  • failed 需要 failureReason。
  • completed 需要 completionEvidence。

证据应尽量使用 durable references:

  • tool call id;
  • run id;
  • file/artifact ref;
  • test command result;
  • user confirmation;
  • verifier/scorer result;
  • diff or patch ref。

task 被标记为 completed 不代表它可以覆盖现实状态。如果后续 filesystem/git/test evidence 与 completed 状态冲突,resume 时应该把它标记为 needs_revalidation,或者重新打开。

Runtime Events

task 变化应该可观测。可能的事件类型:

task_created
task_updated
task_started
task_blocked
task_completed
task_failed
task_cancelled
task_reopened
task_resume_classified
task_repaired

每个事件应该包含:

  • task id;
  • session id;
  • run id,如果可用;
  • previous status;
  • next status;
  • reason/evidence;
  • timestamp。

Resume 行为

在 resume 或 startup recovery 时,task 状态应该被保守分类。

建议 trust levels:

  • trusted:terminal state 有 durable evidence,且关联事件完整。
  • needs_revalidation:状态可能仍然正确,但依赖外部文件、测试或 tool output,需要重新检查。
  • stale:run/session 中断时 task 正在进行中。
  • repaired:恢复逻辑修改过 task projection。
  • untrusted:event log 损坏、缺失或内部不一致。

例子:

  • completed 有关联 test result,且 artifact refs 未变化 -> trusted。
  • app 崩溃时 task 是 in_progress -> stale。
  • task 因 permission prompt 阻塞,随后 app 重启 -> needs_revalidation。
  • task 引用了缺失的 run/tool/artifact -> untrusted。
  • recovery 修复了非法状态流转 -> repaired。

与其他 Roadmap 项的关系

这个 task model 可以成为以下能力的共同基础:

  • resume:判断哪些工作可以继续;
  • observability:解释发生了什么;
  • dynamic workflow:后续增加依赖和 retry;
  • cron / automation:scheduled run 后续可以创建或更新 task;
  • multi-agent collaboration:assignment/handoff 后续可以建立在 task record 上;
  • AHE / benchmark loop:task traces 可以成为 evidence。

但这个 issue 不应该实现这些更上层系统。

可能的 PR 拆分

  1. RFC / docs only:定义 task record、状态、流转规则、证据规则和 resume classification。
  2. 类型定义和 validators。
  3. 基于现有 runtime/session storage 的 task event projection。
  4. feature flag 下的最小 task tool surface:
    • task_create
    • task_update
    • task_list
    • optional task_get
  5. 基础 UI/trace 展示:当前 task、blocked reason、completion evidence。
  6. recovery tests:覆盖 interrupted、corrupt、stale、contradictory task states。

验收标准

  • 最小 task lifecycle contract 已文档化。
  • task 状态和允许的状态流转已清楚定义。
  • completed / blocked / failed 状态必须带 evidence 或 reason。
  • task record 可以关联 session/run/tool/artifact references。
  • resume trust classification 已定义。
  • 设计不把 task 当作 subagent dispatch。
  • 设计不要求大型项目管理 UI。
  • 未来 workflow、automation 和 multi-agent 工作可以构建在同一套 task state model 上。

Activity

  1. somewan820 commented on Jul 6, 2026

    @somewan820
    ContributorAuthor

    Implementation Plan

    Phase 1 — Contract and invariants

    Define the task lifecycle contract before wiring it into runtime behavior.

    Deliverables:

    • define AgentTask, TaskStatus, and ResumeTrust;
    • define required fields for each terminal or blocked state;
    • define allowed status transitions;
    • define invalid transition behavior;
    • define evidence requirements for completed, blocked, and failed;
    • document that task state does not override filesystem/git/test/tool truth.

    Acceptance criteria:

    • task lifecycle contract is documented;
    • status semantics are unambiguous;
    • evidence rules are explicit;
    • non-goals remain clear: no workflow engine, no multi-agent dispatch, no project-management UI.

    Phase 2 — Types and validators

    Add source-backed TypeScript types and pure validation helpers.

    Deliverables:

    • add task model types;
    • add transition validator;
    • add evidence validator;
    • add task update validator;
    • add fixtures for valid and invalid task records;
    • add unit tests for legal/illegal transitions.

    Possible APIs:

    canTransitionTaskStatus(from, to, options)
    validateTaskEvidence(task)
    validateTaskUpdate(previousTask, nextTask)
    classifyTaskResumeTrust(task, refs)

    Acceptance criteria:

    • invalid transitions are rejected;
    • blocked without blockedReason is invalid;
    • failed without failureReason is invalid;
    • completed without completionEvidence is invalid;
    • explicitly reopened completed / cancelled tasks are handled intentionally;
    • tests cover happy paths and negative cases.

    Phase 3 — Task event model

    Represent task lifecycle changes as observable events.

    Deliverables:

    • define task runtime event types:

      • task_created
      • task_updated
      • task_started
      • task_blocked
      • task_completed
      • task_failed
      • task_cancelled
      • task_reopened
      • task_resume_classified
      • task_repaired
    • define event payload shape;

    • add projection logic from task events to latest task state;

    • add tests for event replay and invalid event sequences.

    Acceptance criteria:

    • task changes can be reconstructed from events;
    • event replay is deterministic;
    • corrupt or invalid event sequences are detectable;
    • task events carry session/run references where available;
    • task events are compatible with existing runtime/session trace direction.

    Phase 4 — Storage / projection integration

    Persist task state through the existing session/run storage model without replacing AgentRun or RuntimeEvent.

    Deliverables:

    • choose storage location for task events or task projection;
    • append task events durably;
    • expose a task projection per session;
    • link task records to session/run/tool/artifact refs;
    • add recovery behavior for stale or incomplete task projections.

    Acceptance criteria:

    • tasks survive app restart or session reload;
    • task state can be listed by session;
    • task references do not require loading full tool output bodies;
    • missing referenced run/tool/artifact records are classified conservatively;
    • recovery never pretends an unfinished task completed.

    Phase 5 — Minimal task tool surface behind a feature flag

    Expose the smallest model-facing task tools only after the storage and validation contract exists.

    Deliverables:

    • add feature-flagged tools:

      • task_create
      • task_update
      • task_list
      • optional task_get
    • enforce validators inside tool handlers;

    • emit task events from tool operations;

    • return compact task summaries to the model.

    Acceptance criteria:

    • the model can create, update, and list tasks;
    • invalid task updates fail with actionable errors;
    • task tools do not bypass permission policy;
    • task tools do not imply subagent assignment;
    • tool output stays compact enough for long sessions.

    Phase 6 — Resume, trace, and UI/read-model polish

    Make task state useful for users and for recovery/debugging.

    Deliverables:

    • classify task resume trust on startup/session recovery;
    • show current task / blocked reason / completion evidence in trace or UI read model;
    • include task state in debug/export surfaces where appropriate;
    • add recovery tests for interrupted, stale, corrupt, and contradictory states.

    Acceptance criteria:

    • interrupted in_progress tasks are marked stale;
    • completed tasks with missing evidence are marked untrusted or needs_revalidation;
    • task state is visible enough for debugging long-running work;
    • UI remains lightweight and does not become a project-management system;
    • future workflow, automation, and multi-agent work can consume the same task state model.
  2. somewan820 commented on Jul 6, 2026

    @somewan820
    ContributorAuthor

    Implementation Notes

    This PR #567 hardens the existing session-scoped task ledger instead of introducing a second task/workflow system.

    Implemented:

    • Added durable lifecycle states: pending, in_progress, blocked, completed, failed, cancelled.
    • Added compact evidence fields for terminal/blocking states:
      • blockedReason
      • failureReason
      • completionEvidence
    • Added lifecycle transition validation, including explicit reopen semantics.
    • Added append-only task-events.jsonl and replay projection.
    • Preserved tasks.json as legacy/projection cache.
    • Added legacy import on first mutation via task_imported.
    • Made corrupt event logs authoritative for mutation paths: writes fail closed.
    • Added task_list / task_get.
    • Kept model-visible ledger surfaces free of resumeTrust.
    • Filtered resumeTrust: "untrusted" fallback cache tasks from model-visible outputs.
    • Documented the contract in docs/durable-task-lifecycle.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions