Documentation

Docs / Reference

ADR 0045 - Flow graph endpoint

Status: Accepted (delegated review, 2026-11-03)

Context

The developer decided (2026-11-03, the T016 task record (internal), "Graph views", and the T016f task record (internal)) on a Flow tab in the API detail pane: for the selected HTTP route or Tauri IPC command, who calls it and what it runs, one or two hops each way. VISION's precision principle governs it: every drawn edge is a stored edge with its stored provenance and confidence, or an explicitly marked non-edge (a near miss's recorded candidate). Nothing is inferred to fill a gap.

The existing endpoints cannot supply this graph (T016f F1): /api/v0/api/endpoint (ADR 0042) gives the callers, their owners and near misses, but not the callers of an owner, the handler's callees, any calls edge, or the other targets of a conditional call. The store interface already offers what is needed (Edges, NodesByIdentity, Nodes, FileHashes, Runs), so no store, contract or extractor change is made.

Measured at task-writing time (T016f F2, F4; Langflow 68,069 nodes and kftray 6,648 nodes): calls edges are all fact 1.0 with one evidence span; function, method and class nodes carry no scope attribute; most Langflow call sites sit in functions nested in hooks, and 100 of 148 routes with callers get hop-2 callers only through the enclosing function; call sites per route max 3, hop-1 callees max 20, hop-2 callees max 39, largest two-hop neighbourhood 57 nodes. These figures were not re-measured in T016f1's implementation run (see Known gaps).

Options considered and decisions

1. Data source

2. Hops

3. Roles and the enclosing step (UQ1)

Nodes appear once with every role they have (roles, in table order) and their smallest hop:

role hop rule
endpoint 0 the requested node
handler 0 the stored node named by handler (states as in /endpoint)
call 1 the callers of /endpoint (scope and root apply)
owner 1 source of each call's stored contains edge (first by identity, as /endpoint's owner)
enclosing 1 source of a caller owner's stored contains edge, when it is a function or method; one step, never further
other_target 1 other targets of a call's stored call edges (a conditional call)
near_miss 1 the near misses of /endpoint
near_miss_owner 1 source of each near miss's stored contains edge (the same rule as owner)
callee 1, 2 targets of the handler's stored outgoing calls; then of those callees'
caller 2 sources of stored incoming calls of each caller owner and enclosing function

UQ1: option B, decided by the developer (2026-11-03), with these safeguards:

Rejected: A (owner callers only: Langflow's upstream hop 2 would be mostly empty), C (drawing the enclosing function's callers into the owner card: the drawn edge would target a node it does not target in the index).

4. Edges

5. Non-edges

6. Caps

Fan-out 25 calls neighbours per node and direction; the node's omitted.callers / omitted.callees count the neighbours the cap cut that no returned edge reaches. They are computed after the induced subgraph and any hop-2 drop: a cut neighbour can still be returned another way (a handler callee cut at hop 1 that another callee calls, so it appears at hop 2 and the handler's edge to it is induced; a hop-2 caller reached from two expanded nodes), and then it is not hidden and not counted. 200 callers and 200 near misses (calls_cap, near_misses_cap; counts stay uncut); 300 nodes and 600 edges in total, beyond which hop 2 is dropped whole (hop2_dropped), including roles and cuts that only hop 2 gave. Order inside a cap: file, span start, identity. truncated is null or {nodes_omitted, edges_omitted, reasons}. Under calls_cap and near_misses_cap, nodes_omitted counts only the cut call and near-miss nodes (not their owners or enclosing functions, which may be shared with returned calls, nor other targets or hop-2 callers they would have led to), and edges_omitted counts, for cut calls, only their stored edges to the endpoint. Under hop2_dropped both count the removed hop-2 nodes and the edges touching them. Rejected: no caps (an unbounded response for a hub function), paging (the graph is drawn whole).

Hop 1 is never cut, so it can exceed the totals alone; then the reason hop1_over_totals is reported (with hop2_dropped too if hop-2 nodes were removed first). It adds nothing to nodes_omitted or edges_omitted, since nothing is left out; the returned nodes and edges show the excess. Worst case of hop 1 after the calls caps: 2 (endpoint and handler)

7. Scope of hop-2 nodes

8. UI, dependencies and size (T016f2)

To be added by T016f2 (React Flow and ELK versions, licence handling per UQ2, which is still open, the same-origin worker under the unchanged CSP, the lazy chunk, the raised embedded-size bound with measurements).

Consequences

Known gaps

Review notes (delegated review, 2026-11-03)

Revision R1: tables and nested functions (T026 AG-C3, AG18)

Status: Accepted (delegated review, 2026-11-19; this revision only).

Context: the Architecture section's chain (ADR 0079) folds long chains with "Open in Flow tab", and the developer decided the Flow tab gains a Tables column (T026 AG18). Langflow's PATCH /api/v1/flows/{flow_id} reaches its write to flow only through the handler's nested update_flow.operation (chain row CH7), which §3's roles did not follow.

Options: (a) a separate tables endpoint the tab joins with /flow (two reads that can see two index states, ADR 0042's 409 logic twice); (b) additive fields and roles on /flow (chosen); (c) the chain endpoint in the Flow tab (another graph shape and other caps).

Decision (additive; every existing node, edge, count and cap is unchanged when a handler has no nested function and reaches no table):

Consequences: goldens gain may_also_use: [] and tables_beyond (no other change on the existing fixtures); a crafted snapshot flowtables (internal/server/flow_tables_test.go) has a golden on SQLite and Postgres with equal bodies. Known gaps: the hop-3 count does not follow the callees the fan-out cap cut at hop 1 or 2 (the UI names them as not read); contains to lambdas or closures stored as other kinds is not followed; test-scope functions are not filtered (§7).

Report a problem with this pageSource: docs/adr/0045-flow-graph-endpoint.md