On this page
Compatibility and known limitations
Manual contents | Lifecycle | Troubleshooting | Alphabetical API index
Use this appendix when reading older model code or deciding whether an old helper is suitable. It consolidates compatibility advice; the linked references retain the exact signatures, examples, and detailed contracts. No runtime behavior is changed by this appendix.
1. Current lifecycle contract
Patch-and-agent applications use the aligned lifecycle by default. The
top-level Project.lifecycle setting defaults to "aligned" and may be
included explicitly. Project format version is separate configuration
metadata. For initialization, reset, and birth behavior, read the
lifecycle contract.
What the runtime does not infer
- Synchronization commits a custom Store; it does not define its reset policy. Main and Patch overrides do not automatically restore every inherited Store.
- Store values are not cloned. Use a reset factory for fresh mutable values.
- Setup repeats after world reset. Register stable listeners once in init or construction, not on every setup.
- Recreated turtles can leave registrations/resources on surviving owners. Models must define disposal.
- A configured agent population of size zero still requires agent initialization. Main init cannot assume that population already exists.
See state ownership and Store contracts.
External clients
External clients must supply awaitAgents: true when agents will follow. For
agent worlds, the first cellinit is a population-request handshake, not final
display data. After setup, agentinit supplies agents and worldinit supplies
final patch/display state; do not request agents again on worldinit.
Patch-only initialization uses cellinit after setup.
Use the browser/runtime protocol; do not implement a reset-before-first-run workaround.
2. Shared neighborhood contracts
The query contracts are independent of lifecycle initialization.
| Current contract | Consequence for older model rules |
|---|---|
| Wrapped grid queries use modulo normalization and unique patch results | Large/tiny-world queries no longer count repeated images as separate neighbors |
| Visitors call once per distinct patch, matching collection forms | Do not expect duplicate callback effects at seams |
| block includes the center; ring/blockX exclude it | Choose explicitly whether the focal patch belongs in a calculation |
| Grid distance is a nonnegative safe integer | Fractional, negative, nonfinite, and other invalid distances throw RangeError; decide the model's rounding policy before calling |
| ring(0)/blockX(0) are empty; block(0) is the focal patch | A zero-radius input has defined behavior, not an implicit first ring |
| nhood4 respects boundaries and requires square topology | Use topology-neutral neighbors for hex; do not assume four hex side neighbors |
| Local turtle queries deduplicate, hide newborn/dying entries, and exclude the caller | Count results agree with the corresponding unique-other-turtle query |
| Radius/annulus queries use Euclidean distance with shortest wrapped displacement | Do not substitute square/hex graph rings for physical-radius selection |
| Object-form APIRoot.distance reads both axes | Results are raw coordinate distances, not automatically wrapped or hex-scaled |
These are intentional shared API contracts. See query contracts and neighborhood stabilization evidence. In particular, choose a scientific meaning for a fractional grid-distance input rather than silently truncating it to make an exception disappear.
3. Scheduling and population caveats
These limitations remain relevant with the current lifecycle as well.
| Caveat | Recommended practice |
|---|---|
| C/A and A/C currently omit mapped patch/turtle shift hooks, although Store commitment still occurs | Do not depend on those hooks in slash modes; test a design with another visit mode or put proposal work in the appropriate step rule |
| doTurtleShift is not consulted by current scheduler maps | Do not use it as an on/off switch for turtle hooks |
| Persistent and transient patch passes can both visit a patch; visitAll can make multiple passes scan everything | Choose one activation policy for a simple model; do not assume visitAll means exactly once per tick |
| Intermediate slash-mode shifts can insert births and remove deaths | Test same-tick opportunities explicitly; C/A is not equivalent to C_A |
| A dying turtle remains in the population until shift but disappears from local queries earlier | Return after die when the current rule should stop; distinguish population size from query visibility |
| step and shift are internal phases, not browser Step | Use browser controls; update is the normal post-commit reporting hook |
| Main statusToJson consumes output/reporting queues | Do not call it as a harmless diagnostic snapshot |
See shift-hook limitations, activation controls, and birth/death timing.
4. Older entry points and safer choices
This is a triage table, not a promise that every unlisted helper is certified. Some names are merely internal; others are defective or have surprising contracts. Consult the reference before replacing one: a similar name does not imply equivalent semantics.
| Entry point / issue | Prefer / consult |
|---|---|
| Main base initAgents has an effective legacy overload, not a usable empty hook | Override it and call initializeTurtles with your Turtle class; do not call super.initAgents as a no-op. Population initialization |
| Main dt numeric field shadows the prototype dt method | Read this.dt, do not call it. Time/control |
| Main nlDiffuse has unresolved boundary/loop limitations | Use the explicit synchronous Heat model; preserve its conservation and boundary checks |
| askTurtles/filterBreed depend on legacy breed/filter machinery | Explicitly filter an array of turtles with instanceof and iterate it. Collection scans |
| Turtle forward returns a heading; fd is defective; initDynamics uses obsolete Store-style assumptions | Use pending movement and explicit built-in/custom initialization, not these as movement or cloning APIs. Movement reference |
| nextX_val/nextY_val and XVal/YVal listeners refer to absent Stores | Use joint velocity operations and XVel/YVel interfaces. State, notifications |
| Turtle link lacks the coordinates required by Main poke | Leave insertion/index changes to runtime-managed births and movement. Index operations |
| patchAtAngle contains boundary/geometry defects | Use checked patch_ahead or explicit patch queries with a known geometry policy. Sensing |
| Trails, sniffer, and sniffCone have sampled-path and swallowed-error limitations | Use explicit checked queries/rules; these helpers are not general collision or physical sensing APIs. Legacy sampling |
| Coords.equals calls numeric internals as functions; hexify mutates and is not idempotent | Compare public numeric coordinates explicitly; distinguish raw addresses from physical coordinates. Coordinate contracts |
| NLRoot.filter matrix overload passes columns, not patches; class/iterator dispatch has caveats | Use patches.toList().filter(predicate) or an explicit array conversion. Filter overloads |
| max_one_of_value spreads tuple elements, unlike min_one_of_value | Use an explicit scalar aggregation with a chosen empty policy. Extrema |
| Random interval truthy-defaults mishandle zero bounds; random and irandom have separate generators | For ordered real bounds use low + (high - low) * NLRoot.random(); do not assume Reset rewinds a common seed. Random helpers |
| normalize does not validate finite input; negative Infinity can loop forever | Validate finiteness before calling; do not use nonfinite headings. Geometry |
| APIRoot.shuffle mutates and returns undefined; NLRoot.shuffle returns the mutated array | Choose the declaring class deliberately. Sampling |
| AgentSet constructor is not an iterable initializer; toString returns an array; sorting policies differ | Use supplied query results, explicit iteration, and the documented collection shape. Agent collections |
Immediate built-in assignments replace reset baselines; current setters retain them; next setters propose for later commitment. Do not repair a legacy helper by manually shifting private Stores. See read/set/propose.
5. Project, Reset, and saved settings
| Surprise | Deliberate policy |
|---|---|
| Numeric default speed 0 (and size 0) falls back to 1 | Apply explicit public state in setup/step for a stoppable model; use visibility controls rather than zero size |
| A speed/theta input binding updates existing turtles, but Reset can restore captured starts | If today's input must govern Reset, read it explicitly in setup and in the intended live rule |
| Changing an input used for initial population count does not resize on ordinary Reset | Reinitialize with current inputs, or design births/deaths; do not mistake a count binding for a live resize command |
| Nonempty explicit turtle starts override count; IDs are not durable identities | Verify starts and population, and rebuild references after world reset |
| dt advances simulation time, not automatic trajectory distance scaling | Scale the model rule explicitly when that is the intended unit policy |
| Agent boundary and cell boundary are independent | Test motion and sensing at edges separately |
| Saved/shared presets may override Project starts or inputs | Inspect the loaded preset before diagnosing a failed code change |
| hardReset or a model-specific Reset override changes ordinary Reset behavior | Check the actual Project and override; ordinary reset advice is not a promise about custom run controls |
Format version 0.2 is used by the guide; a newer value can produce a compatibility warning. Save/relaunch for code changes. Ordinary Reset is not recompilation, full configuration reload, or random-stream replay. Use the Project reference, especially its live change / Reset / relaunch table.
6. Adapting older model code
Applications use the aligned lifecycle. When working with older model code:
- Capture startup state, a small controlled trajectory, outputs, input effects, births/deaths, and repeated reset. Record existing failures separately.
- Move work to constructor/init/local reset/setup according to ownership. Preserve scientific rules, draw order, visit mode, and phase boundaries.
- Keep stable registrations on surviving owners; dispose turtle-owned resources on replacement/death. Review early overridden setters before moving fields.
- Remove manual lifecycle orchestration and duplicate built-in updater calls. Review initial and birth customization callbacks.
- Compare time zero, steps, zero-agent worlds, parameter changes, two resets, and initial rendering. Distinguish intended reset repairs from trajectory parity; do not silently accept new behavior.
7. Evidence and limits
The existing focused suites provide executable evidence:
- Guide examples: actual Markdown examples, state/phase contracts, selected legacy defects, declaration inventories, alphabetical lookup, and relative file/heading links including this appendix.
- Aligned lifecycle: hook order, stable ownership, births, factories/errors, reset, and browser protocol.
- Compatibility: characterization of older execution behavior and helper contracts.
- Neighborhoods: shared query contracts, boundaries, uniqueness, radii, and selected affected callers in both copies.
- Utility edge cases: sampling validation and string-tokenization contracts.
Run these from the repository root:
node --test testing/nlapi-guide.test.mjs testing/nlapi-aligned-lifecycle.test.mjs testing/nlapi-compatibility.test.mjs testing/nlapi-neighborhoods.test.mjs testing/nlroot-utilities.test.mjs
These headless checks do not certify every saved/external model, statistical distribution, host iterator API, SD/Stock/collision branch, or browser layout/launch flow. A characterized defect is not a supported modeling feature, and documenting it is not repairing it. Use a small, measurable model check before relying on a behavior outside the verified guide path.