Skip to content
1 min read · 198 words

Function: branchKey()

ts
function branchKey(b: BranchId): string;

Defined in: src/batteries/orchestration/ops.ts:322

The canonical, INJECTIVE string form of a BranchId route.

Parameters

ParameterTypeDescription
bBranchIdThe route to render.

Returns

string

The length-prefixed, separator-free canonical string.

Remarks

branchKey keys OutputTable, identifies NodeRef.branchId, orders join contributors, and makes duplicate arrivals idempotent — so a collision would overwrite one node's output with another's or merge unrelated barriers. It MUST therefore be injective.

Naive delimiter-joining is NOT injective: an edge id containing the delimiter (a>b) collides with two segments (a, b), and an id shaped like join:x(y) collides with a join segment. So the rendering is LENGTH-PREFIXED, concatenated with no separator:

  • an edge segment renders as `e${id.length}:${id}`;
  • a join segment renders as `j${nodeId.length}:${nodeId}(${of.map(len-prefixed).join('')})`.

Length-prefixing is injective regardless of content: a parser reads the length, then exactly that many characters for the id, so no delimiter can be forged and no two distinct routes render to the same string. The e/j prefixes keep edge and join segments disjoint, and the join's of ids are themselves length-prefixed so the closing ) is unambiguous.