Skip to content

FE-2423: Store readable ids for net objects and migrate existing nets - #10706

Draft
kube wants to merge 10 commits into
mainfrom
cf/fe-2423-readable-ids-core
Draft

kube wants to merge 10 commits into
mainfrom
cf/fe-2423-readable-ids-core

Conversation

@kube

@kube kube commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Caution

Breaking file format change
Each object of a net has one readable id and no name. A parameter keeps name and loses variableName.
Files and stored documents in the older shape load and are migrated.
A build without this PR rejects a file saved by this one.

Summary

Before this PR, each object of a net had an id and a name. Arcs, scenarios and selections referenced the id, a UUID. Code read the name. A parameter had a third one, variableName.

This PR gives each object one id that arcs, references and code all read. An id is at most 32 characters, in the case of its kind, and unique within its net. Renaming an object rewrites every arc, reference and piece of code that names it. A net with a duplicate or malformed id does not run, and Diagnostics lists the problem. A document's own id stays a UUID.

Case Kinds Example
PascalCase place, transition, token type, differential equation, component, component instance, fusion RawMaterial
snake_case parameter, metric, scenario, dimension of a token type, scenario parameter infection_rate

File format

id holds what name held, in the case of the kind, and name is gone from every object but a parameter. A parameter's id holds what variableName held. A dimension has id in place of elementId and name, and a scenario parameter has id in place of identifier. Arcs, initial states, parameter overrides and code name an object by its id.

Example: one net saved by a build without this PR, then by this one
 parameters:
-  - id: param__infection_rate
+  - id: infection_rate
     name: Infection Rate
-    variableName: infection_rate
 places:
-  - id: place__susceptible
-    name: Susceptible
+  - id: Susceptible
 transitions:
-  - id: transition__infection
-    name: Infection
+  - id: Infection
     inputArcs:
-      - placeId: place__susceptible
+      - placeId: Susceptible
 scenarios:
-  - id: scenario__seasonal_flu
-    name: Seasonal Flu
+  - id: seasonal_flu
     scenarioParameters:
       - type: integer
-        identifier: population
+        id: population
     parameterOverrides:
-      param__infection_rate: '1.5'
+      infection_rate: '1.5'
Loading: older files are migrated, and a build without this PR rejects new ones
  • Older files and stored documents load and are migrated

    Each bundled example saved by a build of main loads with no id problem, no compile failure and no code left as it was.
    An id is the older name in the case of its kind. Two objects that end with one id get a number: Queue, then Queue2.

  • Saving a migrated file writes the new shape

    A file saved by this build loads with no migration, and saving it again writes identical text.

  • A build without this PR rejects a file saved by this one

    Invalid SDCPN file: places.0.name: Invalid input: expected string, received undefined.
    Same message for parameters.0.variableName, metrics.0.name and scenarios.0.scenarioParameters.0.identifier.

  • version stays 1

    Loader tells the older shape by its keys.

  • Loader reports what it changed

    parseSDCPNFile and parseSDCPNDocument return idMigration: each older id with its new one, and the code it could not rewrite.

  • A copy made by an older build does not paste

    Clipboard format is version 2, and a version 1 payload is refused.

Links

Changes

Ids: one case per kind, 32 characters, unique within a net
  • Each kind of object has one case

    PascalCase for what is drawn or defined, snake_case for what code reads as a value.

  • An id is unique within its net, across kinds

    Comparison is case-sensitive: place Queue and parameter queue share a net.
    A dimension is unique within its token type, a scenario parameter within its scenario, a component within the document.

  • A scenario parameter may take an id the net also has

    Scenario code reads it as scenario.<id>, apart from the net.

  • Words code reads as something else are no ids

    and, or, not, let, in, true, false, null, acc, and the members of Object.prototype.

  • A new object takes the first free id of its kind

    Place1, Transition1, Type1, parameter_1, dimension_1.
    A dropped instance takes the id of its component.

  • A paste numbers the ids that collide

    Queue becomes Queue2, and arrival_rate becomes arrival_rate_2.

Rename: one mutation changes an id and everything that names it
  • New renameEntity mutation

    Rewrites arcs, initial states, parameter overrides, ports, fusion members and code in one undo step.

  • Code is rewritten from its tokens, with no parser

    Covers input, state.places, parameters, scenario, metrics, token dimensions and the keys of a returned record.
    Comments and spacing stay as written.

  • A rename reports what it touched

    entityRenameEffects counts arcs and code rewritten, and names the code it could not follow.

  • An ad-hoc scenario's Variable follows its scenario parameter
Checks: a net with an id problem does not run
  • checkEntityIds lists duplicate and malformed ids of a document
  • Simulation refuses such a net

    "The net cannot run until its IDs are fixed.", followed by each problem.

  • Messages a user reads say "ID" and "dimension"
Migration: older documents get ids from their names on load
  • migrateLegacyEntityIds runs for files, stored documents and Actual mode recordings

    An older name becomes the id, formatted to the case of its kind and cut at 32 characters.

  • References and code follow in the same pass

    It goes through the rename engine, so a migrated net compiles as before.

  • migrateSDCPN is exported for hosts that store documents
Editor: ids on the canvas and in every list, edited in an ID field
  • Canvas, lists and tables show ids
  • Properties panels have an ID field in place of Name

    A parameter has both Name and ID.
    Dimensions table has an ID column, and the nets list edits a component's id.

  • An ID field commits through renameEntity

    A malformed or taken id shows its message and changes nothing.

  • Diagnostics has an IDs group, listed first

    Its problems count as errors, and Play is disabled while one stands.

  • Metric and scenario drawers have an ID field

    Saving a changed id renames first, then updates.

  • getItemType takes the net it looks in

    One id may exist in two nets of a document.

Brunch agent, flow nets and website: move to ids, with a rename tool
  • Brunch agent has a renameEntity mutation and a petrinaut_rename_entity tool
  • query_basis selects an object by its id alone
  • Flow nets take ids from the labels of their steps

    metadata.ids maps each flow key to its id, read by getFlowNetElementId.

  • Skill references, fixtures and website examples are saved in the new shape

    Demo models of the website have hand-picked ids where a name ran past 32 characters.

Known issues

  • Migration cuts a name over 32 characters mid-word

    The id stops at the 32nd character of the formatted name, and the older name is kept nowhere.

  • No host shows the code a migration could not rewrite

    It is in idMigration alone, which the website drops.

  • Simulation session does not follow a rename

    Unsaved initial marking, parameter values, the selected scenario, the open Simulate resource and a timeline's metric keep the older id.

  • Data outside the document keeps older ids

    Experiments stored by a host, shared links and stored Brunch conversations name objects that no longer answer.

  • User guide screenshots show names

    Pages are updated, images are pending.

More: scenario parameters, libraries, manifests, fusions
  • A code scenario's parameter has no rename in its form

    updateScenario changes the id and leaves the scenario's code.

  • A component library or an optimization manifest in the older shape is refused
  • On migration, a fusion with no place of its own net takes the id of its first port
  • A rename leaves the metadata.ids table of a flow net as it was

Next steps

  • Rename feedback in the editor, tracked as FE-2424

    A floating note under the ID field counts the arcs and code a rename will rewrite. Paste and migration report what they changed.

  • Session state of a simulation follows a rename
  • A title beside the id, for readers

Test coverage

Core: grammar, uniqueness, rename, migration, file round trip
  • validation/entity-id.test.ts, validation/check-entity-ids.test.ts:

    Case, length and reserved words per kind, formatting a name to an id, numbering, and each scope of uniqueness.

  • document/entity-ids.test.ts, document/rewrite-code-references.test.ts:

    A rename of each kind leaves nothing that names the older id, in arcs, references and code, JSX included.

  • file-format/legacy/migrate-legacy-entity-ids.test.ts:

    Ids from names, collisions, code rewritten, and the map returned.

  • file-format/parse-sdcpn-file.test.ts, serialize-sdcpn.test.ts, sdcpn-input.test.ts:

    An older file loads and saves in the new shape, and a new one saves to identical text.

  • clipboard/paste.test.ts:

    Pasted ids are numbered against the net, and references inside the paste follow.

  • Bundled examples saved by a build of main:

    Each one loads here, is migrated, compiles and reports no id problem.

Editor and dependents: rename hook, diagnostics, Brunch, flow nets
  • react/editing/use-rename-entity.test.tsx:

    Validation of a draft id per kind and scope, and one path to renameEntity.

  • diagnostics/entity-id-diagnostics.test.tsx, entity-id-selection.test.ts:

    IDs group, its messages, and the object a problem selects.

  • views/Notebook/notebook-view.test.tsx:

    A cell renames its entity from its ID field, and refuses a malformed or a taken id.

  • Existing suites of @hashintel/brunch-agent, @apps/brunch-agent, @apps/petrinaut-website, @local/flow-petri-net and the Brunch integration tests, moved to ids
  • Website in a browser:

    An example opens with ids, a rename updates list, arcs and URL, a malformed and a taken id are refused, and the simulation runs.

How to test

Rename: an id changes everywhere, a bad one is refused
  • Menu > Load example > Production Machines
  • Select place RawMaterial
  • Properties > ID > type Stock > Enter

    Expect Stock in the places list, on the arcs and in the URL

  • Properties > ID > type raw material > Enter

    Expect "The ID of a place is written in PascalCase" and no change

  • Properties > ID > type BadProduct > Enter

    Expect "The ID BadProduct is taken. Every ID is unique."

  • Press Play

    Expect simulation to run

Older file: a net saved before this PR opens with ids
  • Menu > Import > a file exported before this PR

    Expect ids in place of names on the canvas

  • Bottom panel > Diagnostics

    Expect "No errors detected in your model"

  • Menu > Export > YAML

    Expect no name under places, and placeId values that read as ids

Duplicate id: the net does not run
  • Edit an exported file so two places share one id
  • Menu > Import > that file
  • Bottom panel > Diagnostics

    Expect an IDs group naming both places

  • Hover Play

    Expect it disabled, reading "Fix errors to run simulation"

kube added 9 commits December 3, 2026 16:48
An id is readable and written in the case of its kind: PascalCase for what
is drawn or defined, snake_case for what is read as a value. It holds 32
characters at most and is never a word code reads as something else.

`validateEntityId` says whether a text is an id of a kind and why not,
`formatEntityId` writes any text as one, `uniqueEntityId` numbers an id a
net already has, and `newEntityId` gives the id a new entity starts with.
Nothing uses them yet.
…ments

Places, transitions, component instances, fusions, token types, differential
equations and components take a PascalCase id. Parameters, metrics, scenarios,
token attributes and scenario parameters take a snake_case id. The id is what
structure and code both refer to, and no object keeps a name beside it except
a parameter, whose name stays as a label.

- An id is unique within its net, across kinds. A document with an invalid or
  shared id is reported by checkEntityIds, is not valid for checkSDCPN and
  does not build a simulation.
- renameEntity changes an id and rewrites every arc, reference and piece of
  code that names it.
- A document saved before this change is detected by its shape and migrated
  on load: names become ids in the case of their kind, collisions are
  numbered, and code that read a name is rewritten. The file format version
  stays 1.
- Compiled artifacts of a component's item are keyed by component and item,
  and a token type is resolved in the net that holds the place, since two
  nets can each hold an object of one id.
Every field that edited a name edits the id through one rename, which the
selection and the open net follow. Id problems are listed in Diagnostics
and keep a simulation from starting.
The migration cut a name over 32 characters mid-word and numbered the
ids that collided. Each such id is replaced by whole words through
Core's rename, so arcs, references and code follow, and the
descriptions that cite a renamed parameter name it by its new id.
@kube kube self-assigned this Dec 3, 2026
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hash Ready Ready Preview Dec 3, 2026 6:35pm UTC
petrinaut Ready Ready Preview Dec 3, 2026 6:35pm UTC
petrinaut-docs Ready Ready Preview Dec 3, 2026 6:35pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
hashdotdesign-tokens Ignored Ignored Preview Dec 3, 2026 6:35pm UTC

Request Review

@github-actions github-actions Bot added area/apps > hash* Affects HASH (a `hash-*` app) area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team type/eng > backend Owned by the @backend team area/tests New or updated tests area/apps area/apps > hash.design Affects the `hash.design` design site (app) labels Dec 3, 2026
}
return;
}
holder[key] = after;
Comment on lines +190 to +193
return new RegExp(
`(?:\\.|["'\`])${escaped}(?![A-Za-z0-9_$])|(?<![A-Za-z0-9_$.])${escaped}\\s*[:,}]`,
"u",
).test(code);
Comment on lines +190 to +193
return new RegExp(
`(?:\\.|["'\`])${escaped}(?![A-Za-z0-9_$])|(?<![A-Za-z0-9_$.])${escaped}\\s*[:,}]`,
"u",
).test(code);
tokens.push({ kind: "other", from, to: position });
} else if (wordStart.test(char)) {
let index = position + 1;
while (index < code.length && wordPart.test(code[index]!)) {
});
} else if (/[0-9]/u.test(char)) {
let index = position + 1;
while (index < code.length && /[0-9A-Za-z_.]/u.test(code[index]!)) {
jsx &&
char === "<" &&
(code[position + 1] === ">" ||
wordStart.test(code[position + 1] ?? "")) &&
return false;
}
index += 1;
while (index < code.length && wordPart.test(code[index]!)) {

/** A name as a property after a dot, or in brackets where it is no identifier. */
const asMember = (name: string, quote = '"'): string =>
identifier.test(name) ? `.${name}` : `[${quote}${name}${quote}]`;
Comment on lines +215 to +221
const formatted = formatEntityId(kind, desired);
const isFree = (candidate: string) =>
!taken.has(candidate) && !isReservedEntityId(candidate);
if (isFree(formatted)) {
return formatted;
}
const numbered = /^(.*?)(_?)(\d+)$/u.exec(formatted);
@kube
kube added this pull request to stack #10711 December 3, 2026 19:34

This branch was successfully deployed

3 active deployments
Preview – hash — 977f8404 Deployed Dec 3, 2026 by vercel[bot]
Preview – petrinaut — 977f8404 Deployed Dec 3, 2026 by vercel[bot]
Preview – petrinaut-docs — 977f8404 Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/apps > hash.design Affects the `hash.design` design site (app) area/apps > hash* Affects HASH (a `hash-*` app) area/apps area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests type/eng > backend Owned by the @backend team type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

2 participants