Debugging: rule-author observability contract#

The language-level contract for what a rule author can see and do when diagnosing their rules — the sibling doc to [LTES]. Where [LTES] describes how behaviour is asserted, this doc describes how behaviour is understood: interactively, with full inspection of engine state, with time-travel through a session, with breakpoints on the events that matter.

The integrator-facing surface that exposes it is [NDBG] — the read-only engine APIs and the DAP mapping a DS debug adapter serves them over. This doc is the language-level commitment: every conforming runtime must expose this surface, however it chooses to present it.

What this is not#

  • Not an IDE or CLI spec. Concrete tools live with the reference runtime; other runtimes pick their own presentation.

  • Not a re-statement of TESTING's introspection primitives. DEBUGGING builds on the same primitives but adds interactivity (step / pause / break) and navigability (walk backwards, diff two instants).

  • Not a production-diagnostics spec. Debugging is a rule-author-time concern; production monitoring is runtime territory.


The debugging commitment [LDEB.1]#

[LDEB.1.4] Design invariant, sibling to [LTES]'s: every decision the engine makes about a rule must be inspectable by the rule author. Pattern matches, joins, test-CE results, activation priority, firing order, justification chains, retraction causes, timer activations, cross-tier emissions — all visible. An opaque engine decision is a debugging-surface bug.

Determinism and legibility [LDEB.1.5]#

[LDEB.1.5.2] DS is always deterministic (see [LDET] for the full guarantee). The same rules driven by the same event trace produce exactly the same firing order, every time. Firing order and every computed value are platform-independent: every transcendental is correctly rounded, so no low-order float bit is left to vary ([LDET.3.4.1]).


see also: LDET.3.4.1

Three debugging modes [LDEB.2]#

[LDEB.2.1] Rule authors debug in three distinct modes. Each uses the same observability substrate but has different interaction shapes.

1. Live debugging [LDEB.2.2]#

[LDEB.2.2.1] The rule author is connected to a running engine. Facts are arriving; rules are firing. The author can:

  • [LDEB.2.2.2] Watch working memory in real time.

  • [LDEB.2.2.3] Tap the operator log stream.

  • [LDEB.2.2.4] Attach breakpoints; the engine pauses when the breakpoint fires; state is inspectable while paused; the author resumes when ready.

  • [LDEB.2.2.5] Inject facts into working memory ad-hoc (assert Person ...) to reproduce a condition.

  • [LDEB.2.2.6] Mutate adapter-mock responses to steer downstream behaviour.

[LDEB.2.2.7] Live debugging is the fastest way to reproduce a scenario interactively. It does not require rebuilding or redeploying anything.

2. Replay debugging [LDEB.2.3]#

[LDEB.2.3.1] The rule author is walking a recorded session: an event trace captured from a previous run (production, test, live-debug), per the recording primitive in [LTES]. The author can:

  • [LDEB.2.3.2] Replay at full speed, stepped speed, or step-by-step.

  • [LDEB.2.3.3] Set the clock to any instant within the recording.

  • [LDEB.2.3.4] Inspect state at any instant.

  • [LDEB.2.3.5] Step backwards — re-examine the prior state without re-driving from the start.

  • [LDEB.2.3.6] Diff two instants: "what changed in working memory between T=5_s and T=6_s?"

  • [LDEB.2.3.7] Branch: "from this instant, what if the next event had been different?" (runs forward under modified inputs).

[LDEB.2.3.8] Replay debugging is the only way to diagnose production incidents the author cannot reproduce interactively. It requires the lossless-recording guarantee from [LTES].

3. Static debugging [LDEB.2.4]#

[LDEB.2.4.1] The rule author is inspecting a rule set without running it. The author can:

  • [LDEB.2.4.2] See the full Rete network compilation: which patterns share alpha memories, which joins exist, which tests are attached to which rules.

  • [LDEB.2.4.3] See reachability: given a schema, which rules can match? Given a rule, which schemas can reach it?

Deferred: not binding in this edition.

  • [LDEB.2.4.4] See cross-rule interactions: rule A emits fact X which rule B matches on; is there a potential flicker cycle?

Deferred: not binding in this edition.

  • [LDEB.2.4.5] See dead code: rules whose LHS is structurally unsatisfiable given the schema set.

Deferred: not binding in this edition.

  • [LDEB.2.4.6] See coverage: from a recorded or test-run session, which rules fired, which activations fired per rule, which branches went untaken.

Deferred: not binding in this edition.

[LDEB.2.4.7] Static debugging catches bugs before the author even runs their rules.


Required observability surface [LDEB.3]#

[LDEB.3.1] Every runtime must expose the following, at the granularity below. [LTES] enumerates the observable-event kinds; this doc specifies the shape the debugger can query them in.

Working memory [LDEB.3.2]#

  • [LDEB.3.2.1] Full enumeration: every fact currently in working memory at the current instant, grouped by schema, with all slot values visible.

  • [LDEB.3.2.2] Per-schema enumeration: "give me every Person fact."

  • [LDEB.3.2.3] Pattern-filtered enumeration: "give me every fact whose entity_id matches /^sensor\.kitchen_/." Regex is DS's string matching ([LREG.10.11]).

see also: LREG.10.11

  • [LDEB.3.2.4] Fact lineage: for any fact, who asserted it (rule name, activation id, adapter id if adapter-originated) and when (clock instant).

  • [LDEB.3.2.5] Fact TTL / retention: how long until auto-retract, if any.

Rete network [LDEB.3.3]#

  • [LDEB.3.3.1] Network topology: the graph of alpha memories, beta joins, test CEs, and activation agendas for the current rule set.

  • [LDEB.3.3.2] Per-node occupancy: for any node, what facts / partial matches currently live in its memory.

  • [LDEB.3.3.3] Match path for a fact: given a fact, the sequence of network nodes it passed through and at which nodes it survived vs was filtered out.

  • [LDEB.3.3.4] Activation path for a rule: given a firing activation, the complete chain of pattern and join matches that produced it, with the bound slot values at each step.

Activations [LDEB.3.4]#

  • [LDEB.3.4.1] Pending-activation agenda: activations waiting to fire, ordered by the spec's firing-priority rule.

  • [LDEB.3.4.2] Recently-fired activations: last N activations (or all within a clock window), each with its rule, bindings, fire instant, duration, actions executed.

  • [LDEB.3.4.3] Refracted activations: activations suppressed by refraction, with "suppressed because this activation already fired at T=…".

  • [LDEB.3.4.4] Superseded timers: after <dur> as <expr>: timers superseded by a same-key re-fire (per [LRST]), with the superseding key as reason.

Deferred: not binding in this edition.

Logical-fact justification [LDEB.3.5]#

  • [LDEB.3.5.1] Justifier chain: for any logical fact, the set of activations currently justifying it, with their rule and bindings.

  • [LDEB.3.5.2] Justifier history: how many times has this fact flipped retract → reassert? when was each flip?

Deferred: not binding in this edition.

  • [LDEB.3.5.3] Retraction cause: when a logical fact retracts, the cause its withdrawal records ([RFCS.7a.2], [LLOG.9.4]).

see also: LLOG.9.4, RFCS.7a.2

Time-bound evaluation [LDEB.3.6]#

  • [LDEB.3.6.1] Tick log: every $ClockTick assert/retract cycle with clock instant and which rules' time-bound LHS tests re-evaluated.

Deferred: not binding in this edition.

  • [LDEB.3.6.2] Timer agenda: pending cooldown expirations, upcoming in clock-order.

  • [LDEB.3.6.3] Timer agenda, continued: pending after timers and retain expirations, in the same clock order as [LDEB.3.6.2].

Deferred: not binding in this edition.

see also: LDEB.3.6.2

Adapter interaction [LDEB.3.7]#

  • [LDEB.3.7.1] Call log: every call issued: adapter, domain, method, args, correlation id, clock instant. Response / error arrival instant and content when received.

  • [LDEB.3.7.2] In-flight calls: calls that have been issued but not yet received a response, with elapsed time.

  • [LDEB.3.7.3] Adapter-mock state (test mode): which mocks are registered and what they return.

Cross-tier flow [LDEB.3.8]#

  • [LDEB.3.8.1] Emission log: facts crossing tier boundaries with source tier, destination tier, clock instant, TTL.

Deferred: not binding in this edition.

  • [LDEB.3.8.2] Back-pressure state: recent firings of a schema's cross-tier overflow <policy> ([LLSU.8.1]) — which policy fired, on which schema, at which instant.

Deferred: not binding in this edition.

see also: LLSU.8.1

Compile-time artefacts [LDEB.3.9]#

  • [LDEB.3.9.1] Warnings and errors produced when the current rule set was compiled, with source location.

  • [LDEB.3.9.2] Lint hints for patterns covered by the language spec's linter surface (see per-feature §Resolved entries across the unified specs).


Interactive-control surface [LDEB.4]#

[LDEB.4.1] A runtime in debug mode exposes interactive controls to an attached debugger (CLI, IDE, TUI — presentation is runtime choice).

Execution control [LDEB.4.2]#

  • [LDEB.4.2.1] Pause — halt at the end of the current rule-fire cycle. State is inspectable; no new facts asserted or retracted.

  • [LDEB.4.2.2] Step — advance one rule fire, or one clock tick, or one event-trace event. Step granularity is author-chosen.

  • [LDEB.4.2.3] Resume — continue to the next breakpoint or until the user pauses again.

  • [LDEB.4.2.4] Set clock (test / replay mode) — jump the clock to a specific instant.

  • [LDEB.4.2.5] Rewind (replay mode) — move the replay point backwards to a prior instant.

  • [LDEB.4.2.6] Snapshot — capture the full inspectable state at this instant for later comparison.

Deferred: not binding in this edition.

Breakpoint model [LDEB.4.3]#

[LDEB.4.3.1] Breakpoints pause the engine when specified conditions are met. Conditions the spec commits to supporting:

Breakpoint kind

Fires when

On rule fire

a specific rule activates

On rule fire w/ predicate

a specific rule activates AND a given where-style predicate on its bindings matches

On after or on response body

that body of a specific rule fires

On fact assert

any fact of a schema is asserted

On fact assert w/ predicate

schema + slot-value match

On fact retract

any fact of a schema retracts, with retraction cause visible

On cache op

cache-set / cache-get for a specific key

Further kinds are [LDEB.4.3.3]'s.

see also: LDEB.4.3.3

[LDEB.4.3.3] Further breakpoint kinds, beside [LDEB.4.3.1]'s:

Breakpoint kind

Fires when

On rule not-fire

a specific rule's LHS matched but was suppressed (refraction, mode)

On logical-fact flip

a logical fact retracts or reasserts

On call

any call to a service, or one matching adapter/domain/method

On adapter response

any response fact ([LCRS.4.3.1]) or CallError, or one by correlation id

On timer expiry

a cooldown or retain timer expires

On tick

every tick, or the N-th tick

On cross-tier emit

any fact crossing a tier boundary

Deferred: not binding in this edition.

see also: LCRS.4.3.1, LDEB.4.3.1

[LDEB.4.3.2] Breakpoints support enable/disable, hit-count conditions (pause on the 5th hit), and tracepoints (log-only, no pause).

Watches [LDEB.4.4]#

[LDEB.4.4.1] A watch expresses an ongoing interest in a piece of state; the debugger surfaces the value at every pause and on change.

  • [LDEB.4.4.2] Fact watch — "show me the value of slot X on fact Y at every pause."

  • [LDEB.4.4.3] Pattern watch — "show me every fact matching Sensor where entity_id ~ /_temp$/ at every pause."

  • [LDEB.4.4.4] Aggregation watch — "show me the current value of mean(t) for series Y at every pause."

  • [LDEB.4.4.5] Activation watch — "show me the pending agenda at every pause."


Rete-network introspection model [LDEB.5]#

[LDEB.5.1] Rule authors don't need to be Rete experts, but the engine must make Rete state legible at a conceptual level so authors can diagnose match failures.

What's exposed [LDEB.5.2]#

[LDEB.5.2.1] For a compiled rule set, the debugger presents:

  • [LDEB.5.2.2] The network as a graph. Each pattern in a rule's LHS maps to an alpha node; joins between patterns map to beta nodes; where tests map to test-CE nodes; the root of each rule is its agenda.

  • [LDEB.5.2.3] Node labels use the author's source terms: rule name, schema name, slot names. Not engine-internal names.

  • [LDEB.5.2.4] Node occupancy reports the current fact set at each node in authorable form: one row per (partial) match, with bound variable values.

  • [LDEB.5.2.5] Join filter annotations report why a partial match survived or didn't: "join on p.entity_id = m.entity_id — passed" / "failed: p.entity_id was 'x', m.entity_id was 'y'."

Level of detail [LDEB.5.3]#

[LDEB.5.3.1] Three levels of detail the author can choose:

  • [LDEB.5.3.2] Summary — one-line-per-rule activity counts, good for "which rules are even active."

  • [LDEB.5.3.3] Per-rule — the rule's own subgraph with node occupancy; good for "why didn't this one rule fire."

  • [LDEB.5.3.4] Match trace — for a specific fact, trace its path through the entire network; good for "where did this fact get dropped."

What's not exposed [LDEB.5.4]#

[LDEB.5.4.1] The runtime may hide:

  • [LDEB.5.4.2] Internal Rete engine data structures (hash tables, free lists, memory management) that don't correspond to any author-visible decision.

  • [LDEB.5.4.3] Compiler internals unrelated to rule matching (IR form, intermediate lowering stages).

  • [LDEB.5.4.4] Performance counters that aren't about correctness (unless the author explicitly enables them).

[LDEB.5.4.5] Hidden is hidden: authors don't see it, and tests don't assert against it. This keeps the introspection contract portable across runtimes that implement Rete differently.


Time-travel debugging [LDEB.6]#

[LDEB.6.1] Replay mode ([LDEB.2]) allows bidirectional navigation through a recorded session.

see also: LDEB.2

Primitives [LDEB.6.2]#

  • [LDEB.6.2.1] Seek — set the replay point to a specific clock instant.

  • [LDEB.6.2.2] Step forward / backward — advance / retreat by one event (event trace entry, rule fire, clock tick — author's choice of granularity).

  • [LDEB.6.2.3] Run to breakpoint — continue forward until a breakpoint fires.

  • [LDEB.6.2.4] Run to time — continue forward until the clock reaches a specified instant.

[LDEB.6.2.5] At every replay point, the full observability surface is available: working memory, Rete node occupancy, agenda, etc.

Branching [LDEB.6.3]#

  • [LDEB.6.3.1] Fork from instant T — run forward from T under modified inputs (changed event trace, changed adapter-mock response, different clock step). Compare outcomes against the original recorded outcome.

[LDEB.6.3.2] Branching is the primary debugging-vs-testing distinction: testing asserts a scenario passes; debugging lets the author explore alternate scenarios interactively without writing tests first.

Determinism requirement [LDEB.6.4]#

[LDEB.6.4.1] Replay and branching rely on the foundational determinism guarantee in [LDET]: given the same event trace and rule set, the same observable outcomes are produced, bit-for-bit. The debugger exploits this to trust that stepping backwards shows the same state the author saw going forwards, and that forking from an instant under modified inputs diverges only because of the modification.


Live-session debugging [LDEB.7]#

[LDEB.7.1] In live mode the engine is actually running — facts arrive from real adapters, the clock is wall time, etc. The debugger tees into that stream.

Deferred: not binding in this edition.

What works the same [LDEB.7.2]#

  • [LDEB.7.2.1] Observability surface is identical.

  • [LDEB.7.2.2] Breakpoints fire.

  • [LDEB.7.2.3] Pause / resume works.

What differs [LDEB.7.3]#

  • [LDEB.7.3.1] Live debugging moves forward. To diagnose something that has already happened, the author replays the recorded session.

  • [LDEB.7.3.2] Wall-clock advances during pause. Real-world facts may arrive while paused. They queue; the engine processes them on resume.

Deferred: not binding in this edition.

  • [LDEB.7.3.3] Injected facts go to the real engine. An author asserting a test fact in live mode is modifying real working memory. The adapter states what it did and asks for no confirmation ([NDBG.14.13.2]).

see also: NDBG.14.13.2

Side effects in live debugging [LDEB.7.4]#

[LDEB.7.4.1] Breakpoints and watches are passive — they observe but don't mutate. Step and resume do not issue side effects beyond what the engine would issue anyway. Explicit author actions (fact injection, mock installation) are the only ways live debugging mutates runtime state.


Interaction with tests [LDEB.8]#

[LDEB.8.1] Test runs can be debugged with exactly the same machinery: a failing test scenario becomes a recorded session the author replays, sets breakpoints in, inspects. The event-trace format from [LTES] is the recording medium for both.

[LDEB.8.2] A common loop:

  1. [LDEB.8.3] Run tests. One fails.

  1. [LDEB.8.4] Debugger attaches to the failed run's recorded session.

  1. [LDEB.8.5] Author replays to the point of failure, steps backward to find the divergence, inspects Rete state at the wrong activation, identifies the rule bug.

  1. [LDEB.8.6] Edit rule, re-run tests, confirm green.

[LDEB.8.7] No separate debugging-only session format; replay is replay.


Interaction with live operators [LDEB.9]#

[LDEB.9.1] A running production system has operators, not rule-authors. Operator tooling (metrics, alerts, ops dashboards) is out of scope here — it's a runtime concern. But the spec commits to the debugging surface being available in production, not only in test:

  • [LDEB.9.2] An operator with appropriate access may attach a debugger to a live engine.

Deferred: not binding in this edition.

  • [LDEB.9.3] Attaching must not affect engine behaviour unless the operator explicitly mutates state (injects a fact, sets a breakpoint that pauses, etc.).

  • [LDEB.9.4] Passive observation (watches, log tap, Rete-network inspection) has no side effects on rule firing or latency beyond the cost of shipping the observation data.

[LDEB.9.5] This is the same surface rule authors use, just with production discipline around when it's safe to intervene.


What the reference runtime must provide [LDEB.10]#

[LDEB.10.1] Concretely for the reference runtime at ../../runtime/:

  • [LDEB.10.2] Debug-mode engine entry point that enables full observability, breakpoint registration, and interactive control.

  • [LDEB.10.3] Debugger protocol — a stable, documented protocol over which external tools (CLIs, IDE plugins) communicate with the engine in debug mode. Protocol MUST be versioned.

  • [LDEB.10.4] Reference CLI debugger — a command-line tool that speaks the debugger protocol, provides at least the pause/step/resume/watch/break surface, and works against live, replay, and static debugging modes.

  • [LDEB.10.5] Rete-network visualiser — at minimum a textual / graphviz output. Must present nodes in author-facing terminology.

  • [LDEB.10.6] Event-trace recorder (shared with [LTES]) that produces replayable sessions in the committed format.

  • [LDEB.10.7] Time-travel replayer that drives the engine through a recorded session with full interactive control.

  • [LDEB.10.8] Static-analysis surface covering reachability, dead rules, cross-rule interaction graph.

[LDEB.10.9] See [NDBG] for concrete protocol details, CLI syntax, and UI choices.


Debugging requirements [LDEB.13]#

  1. [LDEB.13.3] Required debugger scope. Live and replay modes, breakpoints, watches, working-memory enumeration and the activation log are required. Rete visualisation and branching are additional surface, not part of the required minimum.

  1. [LDEB.13.4] Recording is a capability, not a policy. The language requires the runtime to be able to record a session for replay; when recording is on is a deployment decision, not a language one. Recording every session has a cost the operator owns.

  1. [LDEB.13.5] Test-file debugging uses the production machinery. A test run is short and fully recorded, but it is debugged through the same surface as a production session.