Skip to main content
Back to Community & Earn Hub

Visualizing Multi-Branch Coding Agent Sessions: Event-Sourced DAGs, Rollback Checkpoints, and Lightweight Harnesses

@aarav_sharma2 days ago·1 min read 2169 views
Visualizing Multi-Branch Coding Agent Sessions: Event-Sourced DAGs, Rollback Checkpoints, and Lightweight Harnesses

Why Linear Chat Transcripts Fail Modern Coding Agents

A single-threaded markdown chat log made sense when an assistant answered one question at a time. Today's coding harnesses—whether lean native UIs or multi-agent CLI runners—branch constantly:

  • Parent orchestrator spawns 3 parallel subagents across separate git worktrees.
  • One branch fails pytest, rewinds to checkpoint T-4, and tries an alternative patch.
  • Another branch compacts context mid-run.

Flattening that execution tree into a linear scroll hides where tokens were wasted and makes post-mortem debugging painful.


Event-Sourced Session DAG Schema

Instead of logging unstructured strings, emit immutable JSONL events keyed by (session_id, node_id, parent_node_id) with a Git tree snapshot on every file mutation:

python
from dataclasses import dataclass, asdict
import json
import time
import uuid


@dataclass
class AgentTurnNode:
    session_id: str
    node_id: str
    parent_node_id: str | None
    agent_role: str
    tool_name: str
    git_tree_sha: str | None
    tokens_in: int
    tokens_out: int
    status: str  # "ok" | "error" | "reverted"
    ts_ms: int = 0

    def to_jsonl(self) -> str:
        payload = asdict(self)
        payload["ts_ms"] = self.ts_ms or int(time.time() * 1000)
        return json.dumps(payload)


def record_step(log_path: str, parent_id: str | None, role: str, tool: str, tree_sha: str | None) -> str:
    node_id = uuid.uuid4().hex[:8]
    node = AgentTurnNode(
        session_id="sess_91a",
        node_id=node_id,
        parent_node_id=parent_id,
        agent_role=role,
        tool_name=tool,
        git_tree_sha=tree_sha,
        tokens_in=1420,
        tokens_out=310,
        status="ok",
    )
    with open(log_path, "a", encoding="utf-8") as f:
        f.write(node.to_jsonl() + "\n")
    return node_id

Takeaway

Once every agent turn carries parent_node_id and git_tree_sha, you get interactive session graphs, one-click branch rollbacks, and exact per-subtree cost attribution for free—even inside a sub-50MB native harness.

2 Comments

Discussion

@sarah_jenkins2 days ago

Attaching git_tree_sha to every mutating tool node is a game changer—replaying or diffing two competing agent branches becomes trivial when every step points to a real Git tree object.

@ethan_miller2 days ago

Also love the shift back toward lean native/CLI harnesses. A 20MB binary that streams structured JSONL DAG events beats a sluggish 2GB Electron shell every day.

Join the developer discussion

Sign in or create a free account to comment (+10 pts) and tag helpful AIStoreHub repositories.