Skip to content

Graph trace reconstruction: expose a replayable control/data-plane timeline #1529

Closed

Description

@likun666661

Context

Follow-up to #1341.

A real Desktop Graph Mode run with deepseek-chat gives us enough evidence to reconstruct most of the graph after the fact:

  1. The root supervisor committed schedule revision 1 with one local-read work item.
  2. The host provisioned a child Session/operator and admitted one activation.
  3. The child emitted message, tool-call/dispatch, tool-result, final-message, usage, and terminal records.
  4. The original root turn ended while the child was still running.
  5. After the child terminal record committed, the host injected a durable supervisor checkpoint as a second root turn.
  6. The supervisor observed the graph, read the child output, selected a committed result record, and closed the schedule in revision 2.

This is the architecture we wanted: subagents behave as operators, their runtime events behave as stream records, schedule decisions remain separate from the data path, and the main Agent supervises beside the graph instead of gating record delivery.

Evidence from the live run

Using the revision-1 schedule commit as T+0:

Time Event
T+0ms Root commits update_agent_graph revision 1
T+17ms Operator is provisioned and bound to an independent child Session
T+19ms Intent is claimed/admitted and the activation/run is established
T+48ms Child receives its input and begins producing records
T+1.94s Original root turn completes while the child is still running
T+2.48s Child emits an assistant message and dispatches Read
T+2.63s Read result commits as a record
T+4.60s Final message, usage, and terminal-completed records commit
T+4.65s Host injects a supervisor checkpoint into a new root turn
T+6.61s Supervisor calls view_agent_graph
T+8.59s Supervisor calls agent_output
T+14.57s Supervisor commits revision 2 with the selected message record and finishes the graph

The final client projection contained no omissions for this small graph and correlated:

  • schedule update → root Session / AgentRun / turn / tool call;
  • work → catalog agent;
  • provision → operator → child Session;
  • claim → activation → child AgentRun / turn;
  • runtime records → operator / activation / run;
  • terminal record → completed activation;
  • selected result record → schedule finish.

Important state semantics

The final projection simultaneously showed:

  • work.status = requested;
  • claim.admissionState = executing;
  • operator.currentActivation.status = completed.

These are not necessarily stale copies of one state. They represent different planes:

  • schedule intent — what control-plane work was requested;
  • admission — whether that intent was accepted for execution;
  • runtime activation — what actually happened.

A trace API/UI must preserve these distinctions instead of flattening them into one ambiguous status.

What cannot yet be reconstructed from one client snapshot

The current projection is already useful, but it is not a complete replay trace:

  1. recentActivity and recentControlDecisions are bounded. A larger graph may omit earlier history.
  2. The durable supervisor-wake lifecycle (parked → claimed → attempted → delivered/failed) is not included. The live run proves the wake through the injected second turn, but not every persisted wake transition or retry.
  3. Individual reconcile passes and their causes are not represented as timeline events.
  4. Records sharing the same millisecond do not expose a stable total-order sequence in the client model.
  5. A final snapshot describes the resulting state well, but not every intermediate projection transition.

Proposal

Expose a read-only, paginated, replayable Graph trace derived from the existing authoritative stores. This should be an observability projection, not a new scheduler or agent runtime.

A possible normalized event union:

type AgentGraphTraceEvent =
  | { kind: 'schedule_committed'; ... }
  | { kind: 'operator_provisioned'; ... }
  | { kind: 'intent_claimed'; ... }
  | { kind: 'activation_started'; ... }
  | { kind: 'record_committed'; ... }
  | { kind: 'activation_terminal'; ... }
  | { kind: 'reconcile_completed'; ... }
  | { kind: 'supervisor_wake_claimed'; ... }
  | { kind: 'supervisor_wake_attempted'; ... }
  | { kind: 'supervisor_wake_settled'; ... }
  | { kind: 'schedule_finished'; ... };

Every entry should carry, where applicable:

  • graphId;
  • stable chronological sequence/cursor plus timestamp;
  • root Session / AgentRun / turn;
  • operator / child Session / activation / child AgentRun;
  • work, record, schedule revision, and wake-attempt identities;
  • causal source (toolCallId, reconciliation reason, triggering record/snapshot);
  • redacted/bounded summaries rather than unrestricted prompt or tool payloads.

Possible product surface:

getAgentGraphTrace(rootSessionId, { cursor, limit })

The Desktop panel can initially render this as a compact chronological timeline. A JSON export would also make issue reports and offline diagnosis much more useful.

SQLite should remain the metadata/control-plane query authority. If required metadata has not been migrated or SQLite is unavailable, trace queries should fail explicitly rather than silently reconstructing a different answer by scanning JSONL.

Acceptance criteria

  • A completed run can be reconstructed chronologically without querying raw SQLite tables manually.
  • The trace proves whether the parent turn ended before child completion and correlates a later supervisor turn with its durable wake attempt.
  • Schedule intent, admission state, and runtime activation state remain distinct.
  • Pagination has a stable cursor/order and reports omissions explicitly.
  • Trace reconstruction remains valid after process restart.
  • Sensitive prompt/tool content is excluded or redacted by default.
  • No changes to normal graph scheduling, record delivery, or agent runtime semantics.

Open questions

  1. Should this be a query-time join across schedule metadata, runtime events, AgentRuns, and wake tables, or a dedicated SQLite trace projection?
  2. Which reconciliation transitions are valuable enough to persist, versus derivable noise?
  3. Should a selected result record link directly to a bounded agent_output summary, or only expose identities?
  4. How should timeline retention interact with session deletion, privacy/incognito mode, and telemetry policy?
中文版本

背景

这是 #1341 的后续讨论。

一次真实的 Desktop Graph Mode + deepseek-chat 运行已经证明,我们可以从现有 projection 反推出大部分 Graph 流程:主 Agent 提交 schedule、host 创建独立 child Session/operator、child 的消息与工具活动成为 records、child terminal 后 host 唤醒主 supervisor、supervisor 选择结果 record 并关闭 Graph。

这符合我们原本的架构设想:subagent 是 operator,runtime event 是 stream record,schedule control plane 与数据路径分离,主 Agent 在图旁边监督而不是阻塞 record 流动。

当前 trace 的能力与边界

现有 projection 可以关联:

  • schedule update 与 root Session/AgentRun/turn/tool call;
  • work 与 catalog agent;
  • operator 与 child Session;
  • claim/activation 与 child AgentRun;
  • runtime record 与 operator/activation/run;
  • terminal record 与 activation 完成;
  • selected result record 与最终 finish。

但单个最终 snapshot 还不是完整 replay trace:

  • recentActivity 和 recentControlDecisions 是有界的;
  • supervisor wake 的 parked/claimed/attempted/delivered/failed 生命周期没有进入 client projection;
  • reconcile pass 及其触发原因不可见;
  • 同毫秒 records 没有 client-visible 的稳定全序 sequence;
  • 最终状态不能完整表达所有中间 projection 变化。

另外必须保留三个不同层次的状态语义:

  • work.status 是 schedule intent;
  • claim.admissionState 是 admission;
  • operator.currentActivation.status 是实际 runtime 结果。

它们不能被 UI/trace viewer 压平成一个含糊的 status。

建议

基于现有权威 stores 提供一个只读、分页、可回放的 Graph timeline。它是 observability projection,不是新 scheduler,也不改 agent runtime。

Timeline 至少应覆盖 schedule commit、operator provision、intent claim、activation、record commit、terminal、reconcile、supervisor wake attempt/settlement、schedule finish,并携带稳定 cursor/sequence、各级 Session/Run/turn/operator/record/wake identity 以及因果来源。

Desktop 首版可以只渲染紧凑时间线,同时支持 JSON 导出,便于问题报告和离线诊断。

SQLite 继续作为 metadata/control-plane 查询权威;SQLite 不可用或未迁移时应直接报错,不通过扫描 JSONL 静默生成另一套答案。

Activity

  1. likun666661 commented on Jul 28, 2026

    @likun666661
    MemberAuthor

    The first implementation slice is now available in #1549.

    The PR chooses a query-time join over the existing authorities:

    • one transactionally consistent SQLite control-plane snapshot;
    • root/child AgentRun headers for supervisor and activation lifecycle;
    • immutable RuntimeEvents projected as reference-only Graph records;
    • deterministic chronological ordering plus validated cursor pagination;
    • explicit coverage.limitations for history the current schema does not persist.

    The subtle but important contract is that current admission/wake state is returned in page-level currentState, outside the pageable immutable event stream. A mutable state change therefore cannot invalidate a historical cursor, and current state is not misrepresented as complete transition history. Reconcile passes and overwritten admission/wake transitions can be added later as an append-only ledger without changing the v1 event semantics. activation_started is derived from the claimed child AgentRun's durable createdAt, before its first RuntimeEvent when necessary; terminal state remains RuntimeEvent-authoritative. This PR does not change scheduling, record delivery, or Agent runtime behavior.

    Desktop rendering/export remains a follow-up after the runtime read surface settles.

    中文

    第一个实现切片已经放在 #1549。

    这版选择基于现有权威数据源做 query-time join:SQLite 事务快照提供控制面 metadata,root/child AgentRun 提供 supervisor/activation 生命周期,immutable RuntimeEvent 投影成只含引用的 Graph record,再生成确定性排序和 cursor 分页。

    一个关键点是:当前表只保存 admission/wake 的最新状态,所以 mutable current state 独立放在 page-level currentState,不进入分页的 immutable event stream;状态变化不会让旧 cursor 失效,也不会伪装成完整 transition 历史。activation_started 则直接来自 claim 关联 child AgentRun 的 durable createdAt,不再等待第一条 RuntimeEvent,terminal 仍以 RuntimeEvent 为权威。缺失的 overwritten transition 和 reconcile pass 通过 coverage.limitations 明确暴露。

    这一 PR 不改变 schedule、record delivery 或 Agent runtime 行为。Desktop timeline/JSON export 等 runtime surface 稳定后再接。

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