# Conversation and call edges

| Edge | Answers | Values | Read by |
| --- | --- | --- | --- |
| `predecessor` | Who I follow in chat order | One inbound per node. `"ROOT"` on the session's first node and explicit root forks; `None` on spawn branch roots. | `linear_history`, `get_branch`, `_annotate_spawn_origin`, `turn_groups`, rewind |
| `caller` | Who invoked me to execute | `"ROOT"` or empty on chain-level turns. A node inside an Agent method's execution subtree names another call. | `_rebuild_runtime_cards`, `aggregate_tool_messages`, `turn_groups` |

Schema: `openprogram/state/store/session/nodes.py`. Time order is `seq`, never an edge. `reads` is a third edge: the nodes whose content shaped an LLM prompt.

## Branch walk

`get_branch` follows `predecessor` only, with no `caller` or `seq` guesses. A node with no predecessor must be a legal end, or the data is broken and the walk raises.

- **Legal ends**: Spawn branch root, the ROOT node, a code node opening a run branch, the session's first node, a compaction summary covering the session start
- **Chat display**: `active_branch_chain` filters the tool-aggregated rows to the ids `get_branch` returned; a stale or empty head falls back to a predecessor walk or all rows
- **Attach pointers**: Hang off a message by `predecessor` without joining the chain and are written with `advance_head=False`, so they never move the head; `splice_attach_pointers` inserts them inline

## Node and chat message

|  | DAG node | Chat message |
| --- | --- | --- |
| Serves | Runtime: `render_context` | Display: message list, tool-call cards |
| Tool calls | One node per tool | Folded into the assistant's `tool_calls[]` |
| Thinking | In the `extra` field | Extracted into `blocks[]` |
| Shape | `{role, name, input, output, predecessor, caller, seq}` | `{role, content, tool_calls, blocks, predecessor, caller}` |
| Built | At write | At load, by `aggregate_tool_messages` |

`_msg_adapter.py` takes `predecessor` from the top-level `Call` field only, so a stray metadata copy cannot override it.

**Code**

| File | Holds |
| --- | --- |
| `openprogram/state/store/session/_msg_adapter.py` | Node to message |
| `openprogram/state/store/session/session_store/branches.py` | `get_branch` |
| `openprogram/runtime/context/git/dag.py` | `linear_history`, `active_branch_chain` |
| `openprogram/interfaces/server/persistence.py` | `aggregate_tool_messages` |
| `openprogram/interfaces/server/transcript/turn_index.py` | `turn_groups`, `splice_attach_pointers`, the branch view |
| `openprogram/interfaces/server/ws_actions/session/load.py` | `handle_load_session` |
| `openprogram/interfaces/server/ws_actions/session/transcript.py` | `_rebuild_runtime_cards`, `_annotate_spawn_origin` |

## Implementation status

Implemented. Session nodes carry no `parent_id` or `called_by`; a `parent_id` elsewhere in the code belongs to other records, such as run control and channels.
