Skip to content

FE-1139: Simulation architecture documentation#8951

Open
kube wants to merge 16 commits into
cf/token-format-v2from
cf/fe-1139-simulation-architecture-docs
Open

FE-1139: Simulation architecture documentation#8951
kube wants to merge 16 commits into
cf/token-format-v2from
cf/fe-1139-simulation-architecture-docs

Conversation

@kube

@kube kube commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

🌟 What is the purpose of this PR?

Adds engineering architecture documentation for the Petrinaut simulation subsystem: five self-contained HTML pages (zero build step — open index.html in any browser) with hand-built diagrams that markdown can't express — a byte-exact EngineFrame memory map, a worker-protocol sequence diagram, lifecycle state machines, and per-module data-flow pipelines. Goal: make the architecture legible enough to refactor against, with explicit answers to "where does the memory actually live" and "what are the protocols".

🔗 Related links

🚫 Blocked by

🔍 What does this change?

  • New libs/@hashintel/petrinaut-core/docs/architecture/:
    • index.html — overview: the two execution paths (Quick Simulation vs Experiments), the "where the memory actually lives" table, protocols at a glance, module map, design invariants, refactoring seams (e.g. triple frame retention).
    • engine.html — build/step lifecycle, EngineFrame v2 binary format with a byte-exact memory-map SVG (header fields, section offsets, packed token structs, alignment padding), token typing, determinism.
    • authoring.html — the user-code compilation pipeline, which surface compiles where and runs on which thread, sandboxing posture, deferred distribution sampling.
    • worker.html — full message protocol tables, an SVG sequence diagram of one simulation run, the ack/backpressure contract with play-mode profiles, lifecycle state machine.
    • monte-carlo.html — run model, double-buffer memory with byte-capacity growth, the in-worker metrics pipeline, experiment protocol.
  • Core pages are React-free: consumers are described as "the host application" against the public API (Simulation handle, SimulationFrameReader, experiment stores). The React integration (providers, playback ack policy, experiments rendering, uPlot timeline) moved to a new libs/@hashintel/petrinaut/ARCHITECTURE.md — deliberately not in that package's docs/ folder, which is the end-user guide read by the in-app assistant.
  • src/simulation/ARCHITECTURE.md and src/simulation/README.md cross-link the HTML set; the HTML pages link the source files they document (e.g. frames/internal-frame.ts).
  • Deliberately no Docusaurus / site generator: five internal pages whose value is the custom diagrams; a build pipeline adds nothing. GitHub Pages can serve the folder later if wanted (10-line workflow).

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing
    • (docs/ is outside the npm files whitelist; the only code-adjacent changes are markdown cross-links)

📜 Does this require a change to the docs?

The changes in this PR:

  • require changes to docs which are made as part of this PR
    • (this PR is documentation — internal engineering docs; the end-user guide is untouched)

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

⚠️ Known issues

  • The HTML pages are hand-maintained: they can drift from the code like any prose documentation. Each page links the source files it describes to keep verification cheap.

🐾 Next steps

  • Optionally serve docs/architecture/ via GitHub Pages.
  • Extend with an actual-mode/recording page if that subsystem grows.

🛡 What tests cover this?

  • None (documentation). All pages were parse-checked with jsdom, internal links verified to resolve, and rendered via Playwright screenshots during authoring.

❓ How to test this?

  1. Checkout the branch.
  2. open libs/@hashintel/petrinaut-core/docs/architecture/index.html
  3. Navigate the pill nav across the five pages; check the memory-map diagram on the Engine page and the sequence diagram on the Worker page against the code they link.
  4. Confirm the core pages describe consumers host-agnostically, and the React specifics live in libs/@hashintel/petrinaut/ARCHITECTURE.md.

📹 Demo

Open index.html — the pages are the demo.

Self-contained HTML pages (no build step) under
petrinaut-core/docs/architecture/: overview (execution paths, memory
map, protocols), engine (EngineFrame v2 binary format with byte-exact
memory-map diagram), authoring (user-code compilation), worker
(protocol sequence diagram, backpressure, lifecycle), and monte-carlo
(run model, double-buffer memory, metric pipeline).

The core pages are React-free — consumers are described as "the host
application" via the public API. The React integration (providers,
playback ack policy, experiments UI) is documented in a separate
ARCHITECTURE.md in @hashintel/petrinaut, outside docs/ which is the
end-user guide. Existing simulation READMEs cross-link the HTML set.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 3, 2026 13:56
@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
hash Ready Ready Preview, Comment Jul 6, 2026 6:36pm
petrinaut Ready Ready Preview, Comment Jul 6, 2026 6:36pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
hashdotdesign-tokens Ignored Ignored Preview Jul 6, 2026 6:36pm

@cursor

cursor Bot commented Jul 3, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Documentation-only changes (HTML, CSS, markdown); no simulation runtime, auth, or publishable library behavior is modified.

Overview
Introduces internal engineering architecture docs for Petrinaut’s headless simulation stack, aimed at answering where memory lives, what crosses thread boundaries, and how quick sim vs Monte Carlo differ.

A new petrinaut-core/docs/architecture/ set includes shared architecture.css and five browser-openable HTML pages: overview (two execution paths, memory table, invariants, refactoring seams), engine (EngineFrame v2 with byte-map SVG), authoring (compilation pipeline and sandboxing), worker (protocol tables, sequence diagram, ack/backpressure, lifecycle), and monte-carlo (double-buffer runs, in-worker metrics, experiment protocol). Core pages stay host-agnostic; React-specific wiring is split out.

libs/@hashintel/petrinaut/ARCHITECTURE.md is new and documents providers, playback ack modes, experiment metric rendering, and dev tooling—kept outside end-user docs/ so the in-app assistant guide is untouched.

src/simulation/ARCHITECTURE.md and src/simulation/README.md now link to the HTML overview; the HTML pages link back to source files (e.g. internal-frame.ts).

Reviewed by Cursor Bugbot for commit 81e85ae. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added 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 labels Jul 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds internal engineering architecture documentation for the Petrinaut simulation subsystem, centered on a set of self-contained HTML pages in @hashintel/petrinaut-core (plus a separate React-integration boundary doc in @hashintel/petrinaut) so contributors can reason about frame formats, worker protocols, lifecycle, and Monte Carlo execution without a docs build pipeline.

Changes:

  • Introduces five standalone HTML architecture pages + shared CSS under libs/@hashintel/petrinaut-core/docs/architecture/ (overview, engine, compilation, worker/protocol, Monte Carlo).
  • Adds a new libs/@hashintel/petrinaut/ARCHITECTURE.md documenting how the React layer consumes the headless core.
  • Cross-links the new HTML docs from existing petrinaut-core/src/simulation/* markdown entrypoints.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
libs/@hashintel/petrinaut/ARCHITECTURE.md New internal doc describing React integration points and responsibilities (providers, playback/ack policy, experiments rendering).
libs/@hashintel/petrinaut-core/src/simulation/README.md Adds a prominent link to the new illustrated HTML architecture docs.
libs/@hashintel/petrinaut-core/src/simulation/ARCHITECTURE.md Adds a prominent link to the new illustrated HTML architecture docs.
libs/@hashintel/petrinaut-core/docs/architecture/index.html New overview page: execution paths, memory ownership map, protocol summary, and module map.
libs/@hashintel/petrinaut-core/docs/architecture/engine.html New engine page: stepping lifecycle and EngineFrame v2 binary format overview with diagrams.
libs/@hashintel/petrinaut-core/docs/architecture/authoring.html New compilation/authoring page: user-code compilation pipeline, surfaces, execution locations, sandboxing notes.
libs/@hashintel/petrinaut-core/docs/architecture/worker.html New worker/protocol page: message tables, sequence diagram, backpressure/ack contract, lifecycle diagram.
libs/@hashintel/petrinaut-core/docs/architecture/monte-carlo.html New Monte Carlo page: run model, bounded buffering strategy, metrics pipeline, protocol summary.
libs/@hashintel/petrinaut-core/docs/architecture/architecture.css Shared styling for the HTML architecture docs and their diagram primitives.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libs/@hashintel/petrinaut-core/docs/architecture/index.html Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/worker.html Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/worker.html Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/engine.html Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/authoring.html Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread libs/@hashintel/petrinaut-core/docs/architecture/index.html Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/worker.html Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/worker.html Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Comment thread libs/@hashintel/petrinaut/ARCHITECTURE.md Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/index.html Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/index.html Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/index.html Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/index.html Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/worker.html Outdated
kube and others added 2 commits July 6, 2026 16:37
Module-map link labels referenced stale architecture-*.html filenames;
code-context snippets used Unicode −/≥ that break copy/paste; the
initialMarking description said name-keyed where it is keyed by place
ID; and the transfer-list refactoring note ignored that
computeNextFrame() re-reads the latest frame, so a naive transfer would
detach the stepping buffer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
kube and others added 2 commits July 6, 2026 17:01
getPlaceTokens takes only a place since the layout became
SDCPN-derived; getPlayModeBackpressure covers compute modes only
(viewOnly is enforced by the playback provider pausing and never
acking, not by a core profile); the initialMarking type reads
`TokenRecord[] | number` to match InitialPlaceMarking.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 6, 2026 15:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread libs/@hashintel/petrinaut-core/docs/architecture/worker.html Outdated
Comment thread libs/@hashintel/petrinaut-core/docs/architecture/worker.html Outdated
kube and others added 2 commits July 6, 2026 17:09
The init table now shows maxTime as number | null, and the sequence
diagram uses the actual protocol field name initialMarking.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
oxfmt 0.50 checks HTML, and the hand-written pages failed CI's
repo-wide lint:format on this and every stacked PR above. Indentation
only — pre blocks are byte-identical.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 6, 2026 17:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread libs/@hashintel/petrinaut-core/docs/architecture/engine.html
kube and others added 2 commits July 6, 2026 19:19
There is one format; the header's version word (2) stays documented as
the wire constant readers assert, but section titles and asides no
longer read as if a v1 coexists.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 6, 2026 18:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment on lines +31 to +35
<dt>Inputs</dt>
<dd>
SDCPN snapshot, <code>InitialMarking</code>, parameter values, seed, dt,
maxTime, extensions
</dd>
Comment on lines +93 to +97
<strong>1 · maxTime?</strong>
<small
>If <code>currentTime >= maxTime</code>, return
<code>"maxTime"</code> without computing.</small
>
Comment on lines +55 to +58
<small
>owns <code>InitialMarking</code>, parameter values,
seed/dt/maxTime; calls <code>createSimulation()</code></small
>
Comment on lines +20 to +21
element name), parameter values, seed, `dt`,
`maxTime`. When a scenario is compiled, its marking and parameter overrides

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Development

Successfully merging this pull request may close these issues.

2 participants