Introspection and the debug adapter

Contents

Introspection and the debug adapter#

The integrator-facing debugging surface, in two halves. First, the read-only introspection APIs an inspector calls on a running engine: working-memory queries, schema / rule metadata, DS-source mapping, Rete-network topology, match tracing, refraction, and truth-maintenance justifiers. Second, the DAP wire protocol the DS debug adapter (ds dap) exposes them through — session lifecycle, execution control, breakpoints, variable inspection, the custom ds/* requests, and the reverse-execution contract. An integrator building its own inspector calls the engine APIs directly; one running the DS adapter gets the same surface over DAP without writing C.

What this is not#

  • Not the rule-author debugging guide — see [LDEB], which states the language-level observability commitments. This doc states how they are delivered.

Debugging is an integration concern: a subprocess and a wire format are not things DS itself has.


Backend and pause contract [NDBG.1]#

[NDBG.1.1] These accessors read the native Rete engine's structures. They are read-only — none mutate engine state. On a backend that does not expose a Rete network they return DS_OK with no results (no callbacks fired, count 0); code defensively against the empty case rather than assuming a populated network. ds_engine_new gives every engine a Rete network or fails, so a libds.h caller meets neither these no-network answers nor ds_engine_mem's DS_ERR_UNSUPPORTED ([NDBG.2.1]).

see also: NDBG.2.1

[NDBG.1.2] Several reads are only meaningful while the engine is paused — that is, between pumps, when the integrator's driver has stopped advancing the engine and working memory is quiescent. Specifically: live occupancy in ds_engine_rete_network ([NDBG.4.1]) and ds_engine_get_justifiers ([NDBG.5.2]). Reading them mid-pump yields a torn snapshot. A debugger tracks its own paused state and gates these reads on it (the DAP bridge does exactly this).

The engine gates it too, and more broadly: the only way to be on the pump's stack is from inside a callback, and every ds_engine_* call from there returns DS_ERR_STATE ([RARC.13.16]) — reads included. So a mid-pump read is refused rather than torn. A debugger's own paused-state tracking stays worth having, because it keeps the debugger from asking a question it will be told to stop asking.

see also: NDBG.4.1, NDBG.5.2, RARC.13.16

[NDBG.1.3] Pointer lifetimes split two ways. Callback-based enumerators (rete_network, rete_match_trace, refracted_activations) pass strings valid only for the callback's duration — copy what you keep. Inside such a callback, every call on the engine being enumerated returns DS_ERR_STATE ([RARC.13.17]); act on what you copied after the enumerator returns. View accessors (rule_meta, line_span, ds_source, the ds_schema_get_* family) return engine-owned, engine-lifetime borrows. ds_engine_get_justifiers is the exception that allocates caller-owned arrays ([NDBG.5]).


see also: NDBG.5, RARC.13.17

Working memory and schema / rule metadata [NDBG.2]#

[NDBG.2.1] Working-memory inspection — counts, the per-fact accessors, and the ds_engine_for_each_fact visitor — is specified in [NFCT.6]. ds_engine_mem additionally returns a byte-level breakdown of the Rete structures (ds_engine_mem_t); it returns DS_ERR_UNSUPPORTED on a non-Rete engine.

Its counts of facts, network nodes, alpha matches and beta tokens describe the program's logical state, and two conforming runtimes report the same counts for the same program and inputs. wm_fact_count counts every fact in working memory, the ones the lowering and the engine make included, so it can exceed ds_engine_fact_count ([NFCT.6.3]). Its byte sizes and its intern fields (intern_count, intern_string_bytes) describe a runtime's own storage and are implementation-defined, as the ds.intern.* gauges are ([NMET.4.7]): a runtime reports its own, and reports 0 for storage it does not keep. total_bytes is the sum of the byte fields it reports.

ratified — see also: NFCT.6, NFCT.6.3, NMET.4.7

[NDBG.2.2] Schemas: ds_engine_schema_count / _schema_find / _schema_at enumerate registered schemas, the engine's built-in internal schemas ([LSCP.2.6.2]) among them; the ds_schema_get_* family reads a schema's name, lifecycle, ttl, slots, source location (SchemaSource atom), and generated .proto text (SchemaDef atom). The lifecycle of a built-in schema reads as internal (ds_schema_lifecycle_t), which is how an integrator tells it from an author schema: by the lifecycle, never by the name.

ratified — see also: LSCP.2.6.2

[NDBG.2.3] Rules: ds_engine_rule_meta_count / _at / _find return a ds_rule_meta_view_t per rule — name, cooldown window, source location, and the debug-name template (RuleDebugName). A debugger uses these to label terminals and present per-rule rate-control state. A rule's source file is NULL when no DsSource atom carries its module. _find reports a miss through its found flag with DS_OK and does not write the view, so the caller must read the view only when the flag is set.

[NDBG.2.4] Services: ds_engine_service_count / _at / _find return a ds_service_view_t per service the loaded program declares, one per ServiceDef atom (proto/service_def.proto#ServiceDef), with _at in the artefact's order, which is source order ([RDSC.8.4]). _at must return DS_ERR_NOT_FOUND for an index past the count. _find looks a service up by name and must report a miss through its found flag with DS_OK, and leave the view unwritten, as ds_engine_rule_meta_find does ([NDBG.2.3]).

The engine must give, for each service, every field below that the artefact carries, and must keep each view's strings and kwarg array for the engine's lifetime:

  • the service's name;

  • the response schema's name, empty for a service that declares no response ([LADP.8.4.2]), and a flag that is set exactly when it declares no response;

  • its kwargs, in the artefact's order, which is by name ([LGRA.23.2]). Each gives its name; its declared type as the artefact spells it (ServiceKwarg.ds_type, [RDSC.6a.2.7]): a builtin type, a unit symbol, a dimension, a schema by its own name, the kind Schema or an opaque type, so the view carries the name and not a closed enumeration; whether it is required and whether it is literal ([LADP.8.5.1]); and its default, as the canonical text [RDSC.6a.2.4] gives, empty when it has none.

A service's hydration block is not in the view: hydration does not bind in this edition.

This is how an integrator that hosts services learns what to assert for one: a fact of the response schema with the call's correlation ([LCRS.4.3.1]), or nothing for a no response service ([LADP.8.4.2]). It may also refuse to register a callback under a name the loaded program does not declare. Reading the ServiceDef atoms from the artefact's bytes instead would be a second reader of what the engine loaded.


ratified — see also: LADP.8.4.2, LADP.8.5.1, LCRS.4.3.1, LGRA.23.2, NDBG.2.3, RDSC.6a.2.4, RDSC.6a.2.7, RDSC.8.4

DS-source mapping [NDBG.3]#

[NDBG.3.1] To map runtime nodes back to author source (for breakpoints, diagnostics, "which line is this?"), two view families pair up:

  • ds_engine_ds_source_count / _at → ds_ds_source_view_t: the preserved DS source text per module, keyed by module_id.

  • ds_engine_line_span_count / _at / _find → ds_line_span_view_t: the mapping from a bundle-global Rete node_id to a DS (file, line, col) span. ds_engine_line_span_find(engine, node_id, &out) resolves one node directly, returning DS_ERR_NOT_FOUND when no LineSpan atom mapped it.

[NDBG.3.2] Join line_span to ds_source by module_id to render the actual source line a diagnostic points at. This is the mechanism behind author-friendly error locations ([NERR.16]).


see also: NERR.16

Rete-network topology [NDBG.4]#

[NDBG.4.1] ds_engine_rete_network enumerates the network as nodes and edges via two callbacks, ds_rete_node_cb_t and ds_rete_edge_cb_t. All three are declared in runtime/include/libds.h, which is the authority on their shape; this clause states what they mean and not how they are spelled.

rule_filter (non-NULL) names one rule, and restricts the enumeration to the nodes the rule's terminal is reachable from: its terminal or terminals, and every join and alpha upstream of them. It reports only the edges whose two ends are both reported nodes, so a filtered network names no node it does not report. A name no rule carries enumerates nothing. include_occupancy populates the live fact/token count per node, read between pumps, the only time the call is answered ([NDBG.1.2]); without it, every node's occupancy is UINT32_MAX. A node's id, and each end of an edge, is the decimal text of the node's node_id in the artefact (proto/alfa.proto#AlphaNode, proto/beta.proto#BetaNode, proto/term.proto#TerminalNode), which the program fixes and every runtime reads alike; it is never a runtime's own internal label ([RARC.5.3.2]). label is an alpha's schema name or a terminal's rule name, and filter is an alpha's formatted test. A beta's label is join, and its filter is join where it carries join tests and empty where it carries none. is_negative marks NOT-beta nodes. Every string argument is valid only for the callback's duration.

The engine must report every node before any edge: the alphas, then the betas, then the terminals. The order within each kind and among the edges is unspecified. A NULL edge_cb enumerates the nodes alone.

A debugger that cannot get a network (e.g. a non-Rete build) approximates a terminal-per-rule topology from rule_meta instead.

ratified — see also: NDBG.1.2, RARC.5.3.2

[NDBG.4.2] ds_engine_rete_match_trace(engine, fact_id, cb, user) traces a fact through the alpha nodes that participate in its schema dispatch, reporting per node a result, the string passed or filtered, and a human-readable detail — the "why did/didn't this fact match?" tool. A node is named by its id as [NDBG.4.1] gives it, and the detail is in DS-level names ([RARC.5.3.2]).

ratified — see also: NDBG.4.1, RARC.5.3.2

[NDBG.4.3] ds_engine_refracted_activations(engine, rule_filter, cb, user) lists every activation refraction blocks: each entry of the terminals' refraction sets ([IRET.11.3]), with the rule name, the reason ("refraction" in v1), the matched fact ids and a detail. An entry stays listed until its activation is re-created ([IRET.11.3.2]); an unrelated assert or retract, or a pump boundary, removes nothing. Every fact an entry names is therefore live. Use it to explain "this rule matched but did not re-fire."

The runtime must report the entries in this order: terminals by ordinal ([LDET.5.4]), and within one terminal by their matched fact ids, compared as a tuple, element by element, ascending. The matched fact ids are the facts the author's patterns bound, in pattern order; a fact the compiler synthesised (the clock tick, an after timer) is not one of them, so an entry whose match holds only synthesised facts lists none. The detail is the text fired, and not re-created since.


ratified — see also: IRET.11.3, IRET.11.3.2, LDET.5.4

Truth-maintenance justifiers [NDBG.5]#

[NDBG.5.1] ds_engine_get_justifiers lists the activations that logically support a fact — the truth-maintenance "why is this fact still here?" query. The order of its entries is unspecified.

ratified

[NDBG.5.2] The arrays are caller-owned — free timetags, each rule_names[i], and rule_names with ds_free() ([IALC.4.3]), not the C library's free(), which is a different allocator under an allocator override. The call returns DS_OK with n == 0 for non-logical facts, unknown fact ids, or a backend with no exposed truth-maintenance. It is meaningful only while paused ([NDBG.1.2]).


ratified — see also: IALC.4.3, NDBG.1.2

The DAP debug adapter [NDBG.6]#

[NDBG.6.1] The DS DAP debug adapter (ds dap) is the reference consumer of this surface. It exposes the calls as DAP custom requests — ds/getJustifiers (→ get_justifiers, NDBG.14.3), ds/getReteNetwork (→ rete_network), ds/getMatchTrace (→ rete_match_trace), and ds/getRefractedActivations (→ refracted_activations, NDBG.14.12) — and gates the pause-only reads on its tracked stopped state. An integrator building its own inspector calls the same engine APIs directly; an integrator already running the DS DAP adapter gets this surface over DAP without writing C.


see also: NDBG.14.12, NDBG.14.3

Errors [NDBG.7]#

[NDBG.7.1] These accessors favour "empty, not error": unsupported backend or unknown id yields DS_OK with no results. DS_ERR_INVAL is returned for NULL engine / required out-pointers, and for a NULL required callback: ds_engine_rete_network's node_cb, and the callback of ds_engine_rete_match_trace and ds_engine_refracted_activations. edge_cb is optional ([NDBG.4.1]). DS_ERR_NOT_FOUND for an out-of-range index or an unmapped node_id (ds_engine_line_span_find); DS_ERR_UNSUPPORTED from ds_engine_mem on a non-Rete engine. See [NERR].


ratified — see also: NDBG.4.1

Protocol basis [NDBG.9]#

Foundation [NDBG.9.1]#

[NDBG.9.1.1] The DS debug protocol is the Debug Adapter Protocol (DAP) used by VS Code, Emacs DAP-mode, Neovim nvim-dap, and other editors. The primary payoff: IDE integration without writing a client from scratch.

[NDBG.9.1.2] The transport is JSON over stdio (standard DAP). The adapter runs as a subprocess the IDE spawns, one session per process, and runs its own engine. The adapter offers no other transport.

[NDBG.9.1.3] DS uses DAP's base protocol as-is for session lifecycle (initialize, launch, configurationDone, restart, disconnect), execution control (continue, next, stepIn, stepOut, stepBack, reverseContinue, pause), breakpoint management, stack/scope/variable inspection, and the event stream. The adapter must refuse attach: there is no running engine to attach to, and the error message says to use launch. DS-specific surface that has no DAP equivalent is delivered via custom requests and events, per the DAP extensibility model (customRequest, event bodies with custom type values).

Session lifecycle [NDBG.9.3]#

[NDBG.9.3.1] Launch parameters. The launch request takes a DS-specific arguments object:

  • program — the program, as a .dsc or as .ds source the adapter compiles. Optional when trace is given and embeds the program.

  • libs — library directories for a .ds program's imports. Optional.

  • trace — a recorded fact stream ([RFCS.1]). Present, the session replays it; absent, the session is live.

  • facts — live only: fact files the adapter feeds the engine as inputs. Optional.

  • source — the .ds source of a .dsc that carries no source spans. Optional.

  • events — the DS stream events to send ([NDBG.15]). Optional; absent, none is sent.

When the adapter checkpoints is implementation-defined ([NDBG.14r.2.3]).

see also: NDBG.14r.2.3, NDBG.15, RFCS.1

[NDBG.9.3.2] Disconnect and restart. The engine is the adapter's own ([NDBG.9.1.2]), so disconnect must end the session: the adapter frees the engine and every timeline, and exits.

restart must re-read the program, the trace and the fact files, compiling a .ds program again, and start the session over. Breakpoints are kept and verified again. Every fork is dropped ([NDBG.14.17]).

see also: NDBG.14.17, NDBG.9.1.2

[NDBG.9.3.3] A fault the session cannot survive. If the engine traps (a wasm trap, a native addon fault):

  • The adapter emits an output event with category: "important" naming the fault.

  • The adapter then emits a terminated event.

  • The adapter must not restart the session itself.

  • Variable references, thread IDs, and breakpoint IDs are all invalid.

[NDBG.9.3.4] Engine state during pause. While the session is paused:

  • The adapter feeds the engine nothing and runs no pump.

  • The engine's clock does not move, except by ds/advanceClock ([NDBG.14.18]).

  • New breakpoints may be registered; they take effect from the next step.

  • Variable references remain valid until the next continue/next/ stepIn/stepOut/stepBack, after which they are invalidated per standard DAP semantics.

see also: NDBG.14.18

[NDBG.9.3.5] Ids. Wherever the protocol writes a fact's id, in a request, a response or an event, the adapter must write it as # followed by the engine's fact id in decimal ("#42"), and a firing as ! followed by its firing number in the timeline ("!17"). A timeline ([NDBG.14.17]) is %0 for the real run and %N for the Nth fork the session opened ("%1"). A request must accept the same forms.

see also: NDBG.14.17

[NDBG.9.3.6] The program's log lines are its output. Each time the session crosses a firing's log action moving forward, live or in replay, the adapter must send the line it logs as an output event of category "stdout". The line opens with the firing ([NDBG.9.3.5]), the instant and the action's level. The adapter must send none moving back or while re-driving from a checkpoint ([NDBG.14r.2.3]). The events launch argument and ds/streamEvents do not choose these events ([NDBG.15.9]).

In replay, the line is the one the firing logs as the replay derives it again: a trace records no atom for a log ([RFCS.3.6]).

ratified — see also: NDBG.14r.2.3, NDBG.15.9, NDBG.9.3.5, RFCS.3.6

[NDBG.9.3.7] configurationDone. The adapter declares supportsConfigurationDoneRequest ([NDBG.9.2.1]). On configurationDone after a launch, it must answer and then send stopped at the session's current position, with reason "entry" when the session has not moved. Before a launch it must refuse the request with an error response.

ratified — see also: NDBG.9.2.1

[NDBG.9.3.8] Exit status. ds dap must exit with:

Status

When

0

the client sent disconnect

1

its input ended without a disconnect, or held bytes that are not DAP messages

2

it refuses its command line

ratified

Capability declaration [NDBG.9.2]#

[NDBG.9.2.1] The adapter's initialize response declares:

{
  "supportsStepBack":                    true,
  "supportsRestartRequest":              true,
  "supportsGotoTargetsRequest":          true,
  "supportsStepInTargetsRequest":        true,
  "exceptionBreakpointFilters":          [ … ],
  "supportsFunctionBreakpoints":         true,
  "supportsDataBreakpoints":             false,
  "supportsConditionalBreakpoints":      true,
  "supportsHitConditionalBreakpoints":   true,
  "supportsLogPoints":                   true,
  "supportsRestartFrame":                false,
  "supportsSetVariable":                 false,
  "supportsCompletionsRequest":          false,
  "supportsEvaluateForHovers":           true,
  "additionalModuleColumns":             []
}

exceptionBreakpointFilters holds the three filters of [NDBG.12.6.1]. supportsEvaluateForHovers is what makes a client send the evaluate whose context is "hover", which [NDBG.13.7.1] serves.

ratified — see also: NDBG.12.6.1, NDBG.13.7.1

[NDBG.9.2.2] supportsStepBack and supportsGotoTargetsRequest are true in replay and in a live session alike. The adapter records a live run as it goes, and reverse execution moves over that record ([NDBG.14r.3]).


see also: NDBG.14r.3

Thread model [NDBG.10]#

Firings as threads [NDBG.10.1]#

[NDBG.10.1.1] A DAP thread is a rule firing. The threads the adapter must report are:

  • in replay: the firing at the current position, focused, and the later firings of the same pump, each labelled as still to fire in this pump;

  • in a live session: the firings of the pump just run, with the firing a breakpoint stopped on focused ([NDBG.12.1.1]). They exit at the next step.

A trace records firings, not activations. An activation cancelled before it fires is therefore not a thread.

Where no firing qualifies (at a replay's start, at a position whose pump fired nothing, in a live session before a pump fires), the adapter must report exactly one thread, standing for the engine. Its id is one no firing's thread has ([NDBG.10.1.2]). Its name is engine at T= followed by the position's monotonic clock in seconds, to three decimal places, and s. It has one frame, with no source, and scopes on that frame returns the scopes of [NDBG.13.1.1] less Bindings.

see also: NDBG.10.1.2, NDBG.12.1.1, NDBG.13.1.1

[NDBG.10.1.2] A firing keeps one thread id for the whole session, and the adapter must never give that id to another firing. A fork's firings ([NDBG.14.17]) get ids of their own. When a firing becomes a thread, the adapter sends a thread event with reason: "started", and when it stops being one, a thread event with reason: "exited".

see also: NDBG.14.17

[NDBG.10.1.3] Thread display names are taken from the rule's RuleDebugName atom ([RDSC.6.8.4]). The template "alert_high(s={s.entity_id})" is filled with the firing's bound values, producing names like "alert_high(s=kitchen_temp)". When no RuleDebugName atom is present the adapter falls back to "{rule_name} !{N}", N being the firing's number as [NDBG.9.3.5] writes it.

see also: NDBG.9.3.5, RDSC.6.8.4

[NDBG.10.1.4] The adapter reports every thread as stopped while the session is paused. The focused thread is the one whose threadId appeared in the stopped event.

Stack frames [NDBG.10.2]#

[NDBG.10.2.1] The focused thread has a two-frame stack:

  • Frame 0 — the RHS action at the current position. presentationHint: "normal". Its source location is the RHS's span, and its name says which action it is (emit Alert). A .dsc carries a source span per terminal, not per action ([RDSC.14.3.6]).

  • Frame 1 — the rule context. presentationHint: "normal". Source location is the rule declaration line.

see also: RDSC.14.3.6

[NDBG.10.2.2] Every other thread (a firing still to come in this pump, or another firing of the pump just run) has a single frame:

  • Frame 0 — the rule declaration. presentationHint: "subtle". Source location is the rule declaration line. The frame name is the RuleDebugName display name.

[NDBG.10.2.3] The subtle presentation hint causes the IDE to render those threads greyed out in the call stack panel, distinguishing them from the focused thread.

[NDBG.10.2.4] Clicking any frame navigates the IDE to the corresponding .ds source location.

Multi-tier deployments [NDBG.10.3]#

Deferred: not binding in this edition.

[NDBG.10.3.1] Each engine tier maps to one DAP "thread group" (not a thread). Within each tier, activations are threads per [NDBG.10.1]. The IDE's thread panel groups threads by tier label.

see also: NDBG.10.1

[NDBG.10.3.2] When a fact crosses a tier boundary, the cross-tier emission is visible in the adapter call log (see [NDBG.15.4]) and in the stream events. It does not create a thread on the receiving tier's side — that tier's activation, when it fires, creates its own thread.


see also: NDBG.15.4

Execution control [NDBG.11]#

Step semantics [NDBG.11.1]#

[NDBG.11.1.1] A step moves the session one unit of the current granularity ([NDBG.14.1.1]). That unit is one RHS action in replay and one pump in a live session, unless the client sets another.

DAP operation

DS meaning

next

Move forward one step at the current granularity

stepIn

In replay: go to the first later firing whose match includes a fact the current action asserted, passing the firings between. stepInTargets lists every firing the action caused; the default target is the earliest

stepOut

In replay: run until every firing the current firing caused, directly or transitively, within the current pump has fired, then stop at the next firing

stepBack

Move back one step at the current granularity ([NDBG.14r.3.1])

continue

Run forward to the next breakpoint

reverseContinue

Run back to the most recent breakpoint ([NDBG.14r])

Behind the end of a live run, a forward step moves through the recorded run, and at its end the session carries on live.

see also: NDBG.14.1.1, NDBG.14r, NDBG.14r.3.1

[NDBG.11.1.2] In a live session, stepIn and stepOut behave as next. In replay, stepIn at an action that caused no firing behaves as next.

[NDBG.11.1.3] A breakpoint that stepIn or stepOut reaches before its target stops it there, as it stops continue.

[NDBG.11.1.4] pause. The adapter answers requests one at a time and each move completes before its response, so the session is never running when pause arrives. The adapter must answer pause and then send stopped with reason "pause" at the session's current position, which does not move.

ratified

Step granularity [NDBG.11.2]#

[NDBG.11.2.1] DAP's standard granularity field (statement, line, instruction) does not map onto DS's execution model. The adapter ignores it.

[NDBG.11.2.2] Coarser step granularities are available via custom request ds/stepGranularity (see [NDBG.14.1]).


see also: NDBG.14.1

Breakpoints [NDBG.12]#

Standard: source-line breakpoints [NDBG.12.1]#

[NDBG.12.1.1] setBreakpoints on a .ds source file accepts a breakpoint on a rule declaration, an after line or an on response line. One on a rule line stops only in that rule's firings; one on an after or on response line stops only in that body's firings. Where it stops:

  • in replay: at the firing's record, before its first RHS action;

  • in a live session: at the settled point after the pump, focused on the matching firing ([NDBG.10.1.1]). The engine refuses every call from inside a pump ([NDBG.1.2]), so no stop can fall inside one.

A breakpoint on any other line is unverified with message "DS breakpoints must be on rule, after or on response lines, or use ds/setFactBreakpoints for fact-event breakpoints". When the session has no source lines (a .dsc with no source spans and no source launch argument, [NDBG.9.3.1]), every line breakpoint is unverified with message "no source lines: give the program's .ds".

ratified — see also: NDBG.1.2, NDBG.10.1.1, NDBG.9.3.1

[NDBG.12.1.2] Conditional breakpoints (condition field) are supported. The condition is a DS expression evaluated against the firing's bound variables — same syntax as a rule where clause. The adapter compiles it immediately with the compiler (parse + validate against the rule's pattern schemas) and returns verified: false with error detail on parse/validate failure. With no source for the program, a condition is verified: false with message "needs the program's source".

[NDBG.12.1.3] Hit-count conditions (hitCondition) are supported. Standard DAP semantics: "5" means fire on the 5th hit; ">= 3" means fire from the 3rd hit onwards. The adapter must count hits from the start of the timeline, so a hit is the same firing whichever way the session has moved.

[NDBG.12.1.4] Logpoints (logMessage) are supported. The message is a DS interpolation string ("fired with value={s.value}"); the adapter emits an output event of category "important" rather than pausing. A logpoint must log each time the session crosses its hit moving forward, and never moving back or while re-driving from a checkpoint ([NDBG.14r.2.3]). Each line opens with the firing and the instant. With no source for the program, a logpoint is verified: false with message "needs the program's source".

see also: NDBG.14r.2.3

Standard: function breakpoints [NDBG.12.2]#

[NDBG.12.2.1] setFunctionBreakpoints treats the function name as a rule name. A function breakpoint on "alert_high" stops on every firing of alert_high, where a breakpoint on its rule line would ([NDBG.12.1.1]). It needs no source lines.

see also: NDBG.12.1.1

[NDBG.12.2.2] Conditional and hit-count fields are supported with the same semantics as [NDBG.12.1.2] and [NDBG.12.1.3], and logpoints as [NDBG.12.1.4].

see also: NDBG.12.1.2, NDBG.12.1.3, NDBG.12.1.4

[NDBG.12.2.3] Unknown rule names return verified: false, message: "no rule named 'X' in the loaded rule set".

Custom: fact breakpoints [NDBG.12.3]#

[NDBG.12.3.1] ds/setFactBreakpoints registers breakpoints that fire on fact lifecycle events rather than rule fires.

Request:

{
  "breakpoints": [
    {
      "schema": "Sensor",
      "on": ["assert", "retract"],
      "where": "sensor.value > 90.0",
      "hitCondition": ""
    }
  ]
}

[NDBG.12.3.2] schema is required, and may name a built-in schema (a fault fact, CallError) other than the clock tick. on is a non-empty list of "assert" and "retract". "retract" covers every way a fact leaves working memory, and the stop names which, as a retractor kind of [NDBG.14.4.2]. where is an optional DS expression in which the fact is named by its schema name lowercased (sensor for Sensor).

see also: NDBG.14.4.2

[NDBG.12.3.3] Immediate validation. The adapter validates:

  • schema must name a schema present in the loaded rule set. Unknown schema → verified: false, message: "no schema 'X'".

  • on must be a non-empty list of "assert" and "retract". Any other value → verified: false, message: "on must be ...".

  • where is compiled synchronously against the named schema's slot types (parse → validate). Compile failure → verified: false with the compiler error code and human-readable text in message.

  • hitCondition follows standard DAP hit-count syntax ("5", ">= 3", etc.). Malformed → verified: false.

All validation is performed before the breakpoint is registered; a partially-valid request returns individual results per breakpoint.

[NDBG.12.3.4] Response:

{
  "breakpoints": [
    { "id": 42, "verified": true }
  ]
}

[NDBG.12.3.5] When a fact breakpoint fires, the adapter emits a stopped event with reason: "data breakpoint" and a description giving the fact, what happened to it and its slot values: "Sensor #42 asserted: entity_id=kitchen_temp, value=95.2", or for a retract the retractor kind, "Sensor #42 retracted (ttl_expiry): …".

Custom: cache-operation breakpoints [NDBG.12.5]#

[NDBG.12.5.1] ds/setCacheBreakpoints registers breakpoints on cache read and write operations per LDEB.4.3.1.

Request:

{
  "breakpoints": [
    { "key": "app_config", "on": ["set"] },
    { "key": "",           "on": ["set", "delete"] }
  ]
}

see also: LDEB.4.3.1

[NDBG.12.5.2] key is the cache key string. Empty string matches any key. on is a non-empty list of "get", "set" and "delete". "delete" covers a TTL expiry as well as the delete verb ([NSTG.2.4.3]).

In replay, a "get" breakpoint is verified: false with message "a trace does not record cache reads"; its "set" and "delete" stand.

see also: NSTG.2.4.3

[NDBG.12.5.3] When a cache breakpoint fires, stopped event with reason: "data breakpoint" and description showing the key, op, and value (for set). For a removal it names the reason by its stable name, delete or ttl ([NSTG.2.4.3]).

see also: NSTG.2.4.3

[NDBG.12.5.4] Response follows the same shape as ds/setFactBreakpoints — one entry per breakpoint with id and verified. A key is a string, not an expression, so nothing is compiled. An entry is verified: false, with a message saying why, in three cases: its key is not a string; its on is not a non-empty list of "get", "set" and "delete"; or it is a "get" in replay ([NDBG.12.5.2]).

see also: NDBG.12.5.2

Exception breakpoints [NDBG.12.6]#

[NDBG.12.6.1] The adapter must offer these three filters as the exceptionBreakpointFilters of its initialize response, and take them through setExceptionBreakpoints:

filter

label

Stops when

default

unanswered_call

Unanswered call

a pump ends with a call still waiting for its answer

false

fault

Fault

a firing raises a fault ([LERR.9])

false

engine_error

Engine error

a pump returns an error status, or the engine halts

true

The stop is a stopped event with reason: "exception" and a description naming what happened. With unanswered_call off, an unanswered call does not stop the session: it is listed in the Calls scope ([NDBG.13.1.1]) and reported by ds/callMade ([NDBG.15.4]).

see also: LERR.9, NDBG.13.1.1, NDBG.15.4

Variable inspection [NDBG.13]#

Scope model [NDBG.13.1]#

[NDBG.13.1.1] When the session is paused, scopes on the focused thread's top frame returns five scopes:

Scope

Contents

Bindings

The firing's bound variables, by their source names — one entry per LHS pattern binding

Working Memory

The facts at the current position, grouped by schema, paged 100 to a schema

Agenda

In replay, the firings still to come in this pump, in order; empty in a live session

Cache

Each cache key at the current position, with its value and its TTL

Calls

The calls waiting for an answer, then those answered in this pump

[NDBG.13.1.2] scopes on any other thread's frame returns only Bindings. Working memory is shared and shown on the focused thread; duplicating it per-thread adds noise.

[NDBG.13.1.3] All scopes are lazy — variables is called on demand when the author expands a scope in the IDE. The adapter does not push variable data unprompted.

Bindings scope [NDBG.13.2]#

[NDBG.13.2.1] One variable per LHS binding. Variable name is the binding name (s, e, etc.). Value is the schema type (Sensor, Event). variablesReference is non-zero; drilling in shows one child per slot.

s: Sensor
  entity_id: "kitchen_temp"
  value: 95.2
e: Event
  entity_id: "kitchen_temp"
  payload: "{\"temp\": 95}"

[NDBG.13.2.2] Each fact variable also exposes a read-only _id child (the fact's id, written as [NDBG.9.3.5] gives it), and for logical facts a _justifiers child (see [NDBG.13.4]).

see also: NDBG.13.4, NDBG.9.3.5

Working Memory scope [NDBG.13.3]#

[NDBG.13.3.1] Top-level children are schema names with fact counts: "Sensor (3 facts)", "Event (1 fact)". Each schema name has variablesReference; drilling in shows the individual facts with their slot values.

[NDBG.13.3.2] Fact variables follow the same shape as binding variables in [NDBG.13.2.1] — slots as children, _id, and _justifiers for logical facts.

see also: NDBG.13.2.1

[NDBG.13.3.3] When a schema holds more than 100 facts, the adapter paginates using DAP's start and count parameters on the variables request.

[NDBG.13.3.4] occupancy counts (number of facts per schema) are only accurate when the engine is paused. If queried while running, the adapter returns null occupancy values rather than stale snapshots.

Logical-fact justifiers [NDBG.13.4]#

[NDBG.13.4.1] Every logical fact variable carries a _justifiers child. It is visible in the IDE variable tree alongside the schema slots, prefixed with _ to signal it is engine-metadata, not an author-declared slot.

[NDBG.13.4.2] Drilling into _justifiers shows one child per active justifier:

_justifiers: (2 active)
  [0]: alert_high(s=kitchen_temp) at T=1.234_s
  [1]: pair_check(s=kitchen_temp, e=kitchen_temp) at T=1.236_s

[NDBG.13.4.3] The same data is available programmatically via ds/getJustifiers (see [NDBG.14.3]) for tooling that does not use the variable tree.

see also: NDBG.14.3

Json slot drilling [NDBG.13.5]#

[NDBG.13.5.1] Json-typed slots are presented as a recursive variable tree. Object keys become children; array indices become children.

[NDBG.13.5.2] The tree has no depth cap. The adapter builds each level when the client expands it ([NDBG.13.1.3]), and a Json value is at most 16 levels deep ([LGRA.5.8.6]), so every level is reachable.

ratified — see also: LGRA.5.8.6, NDBG.13.1.3

Agenda scope [NDBG.13.6]#

[NDBG.13.6.1] In replay, the Agenda scope shows the firings still to come in the current pump, in the order they fire ([LDET.5]). Each entry shows the rule name, a bindings summary and the terminal ordinal. A trace records firings, not activations, so an activation cancelled before it fires is not shown. In a live session the scope is empty: a live stop falls after the pump ([NDBG.12.1.1]).

see also: LDET.5, NDBG.12.1.1

[NDBG.13.6.2] This mirrors the thread panel but provides a single ordered view rather than requiring the author to mentally sort the thread list.

[NDBG.13.6.3] Refracted and suppressed activations (those that matched but were prevented from firing by refraction or supersedure) are not shown in the Agenda scope — they are not pending, they are suppressed. Use ds/getRefractedActivations (see [NDBG.14.12]) to query them separately.


see also: NDBG.14.12

Watches, hovers and the debug console [NDBG.13.7]#

[NDBG.13.7.1] evaluate reads a DS expression at the current position. For an evaluate request whose context is "watch", "hover" or "repl", the adapter must evaluate expression as a DS expression, with the syntax of a rule where clause, against the bound variables of the firing whose frame frameId names. Without a frameId, or on the engine's thread ([NDBG.10.1.1]), the expression has no bindings. It reads the clocks and the series as a firing at that position reads them ([LTIM.2.4.3]). This is how a watch ([LDEB.4.4]) is served. A "repl" request, which a client's debug console sends for a typed line, is answered exactly as a "watch": the line is an expression and nothing else. The adapter must answer an evaluate with any other context with an error response naming it.

The adapter must compile the expression as it compiles a breakpoint condition ([NDBG.12.1.2]), and answer a parse or validate failure, or a program with no source, with an error response carrying the detail. Evaluation changes nothing in the engine ([LDEB.7.4.1]).

ratified — see also: LDEB.4.4, LDEB.7.4.1, LTIM.2.4.3, NDBG.10.1.1, NDBG.12.1.2

[NDBG.13.7.2] The answer. The response's result is the value as the variables request writes it. A Json value carries a variablesReference that expands as [NDBG.13.5] says. An expression whose evaluation faults is answered with an error response naming the fault's class ([LERR.1]).

ratified — see also: LERR.1, NDBG.13.5

Reverse execution and replay [NDBG.14r]#

Replay mode [NDBG.14r.1]#

[NDBG.14r.1.1] Replay is entered by the trace launch argument ([NDBG.9.3.1]) or by ds/loadRecording. The engine is driven from a recorded fact stream rather than live inputs. Every execution-control operation works in both modes, except the step granularities [NDBG.14.1.1] reserves to replay.

see also: NDBG.14.1.1, NDBG.9.3.1

[NDBG.14r.1.2] The adapter advertises supportsStepBack: true and supportsGotoTargetsRequest: true in both modes ([NDBG.9.2.2]), so a change of mode changes neither.

see also: NDBG.9.2.2

Reverse index [NDBG.14r.2]#

[NDBG.14r.2.1] At ds/loadRecording time the adapter builds a reverse index in one forward pass over the event stream. The index is a sorted array per event category (rule fires, fact asserts, fact retracts, timer fires, etc.), keyed by stream position. Build cost is O(N) in event count; each subsequent reverse-navigation operation is O(log N) via binary search. In a live session the adapter extends the index as it records the run.

[NDBG.14r.2.2] Conforming adapters that implement reverseContinue MUST pre-build this index at load time. Lazy scanning is not permitted — O(N) per reverse step degrades interactively on long recordings.

[NDBG.14r.2.3] In addition to the event index, the adapter maintains checkpoints: full snapshots of engine state, taken at an interval the adapter chooses. Reverse navigation seeks to the checkpoint immediately preceding the target position, then re-drives the engine forward from there. Checkpoint granularity trades memory against maximum re-drive cost.

stepBack [NDBG.14r.3]#

[NDBG.14r.3.1] stepBack moves back one step at the current granularity ([NDBG.14.1.1]). The adapter:

  1. Finds the checkpoint before the target position.

  2. Re-drives the engine from the checkpoint to the target position.

  3. Pauses; emits stopped with reason: "step".

see also: NDBG.14.1.1

reverseContinue [NDBG.14r.4]#

[NDBG.14r.4.1] reverseContinue runs backwards to the most recent event that would have triggered any active breakpoint. The adapter:

  1. Binary-searches the reverse index for the nearest breakpoint- eligible event before the current position.

  2. Seeks to the checkpoint before that event.

  3. Re-drives to that event.

  4. Pauses; emits stopped with the breakpoint's reason.

gotoTargets and goto [NDBG.14r.5]#

[NDBG.14r.5.1] gotoTargets is answered on four kinds of line, with the recorded instants as targets:

  • a rule declaration: each firing of that rule;

  • an after or on response line: each firing of that body;

  • a schema declaration: each assert of a fact of that schema.

The adapter returns at most the 1,000 targets nearest the current position. Each target has a label "!N at T=X.XXXs", or for an assert "#N at T=X.XXXs" ([NDBG.9.3.5]).

see also: NDBG.9.3.5

[NDBG.14r.5.2] goto(targetId) seeks the engine to that instant using the checkpoint + re-drive mechanism.

Recordings [NDBG.14r.6]#

A recording the adapter replays is a fact stream ([RFCS.1]), given as the trace launch argument ([NDBG.9.3.1]) or to ds/loadRecording ([NDBG.14.2.1]). The adapter reads no other recording format.

see also: NDBG.14.2.1, NDBG.9.3.1, RFCS.1

[NDBG.14r.6.5] Binding check. When the adapter pairs a trace with the session's program, it must apply [RFCS.4.5]'s check of the trace against that program. A mismatch is fatal to the load and surfaces as a DAP error response. Its body.error is a DAP Message whose variables hold the underlying DS_ERR_BND_* code's name under code, so a client reads it at body.error.variables.code; the message's text is for a person and binds no client. The adapter may make the comparison in its own code, as [RBND.6.3] admits a reader outside a runtime.

ratified — see also: RBND.6.3, RFCS.4.5

Custom requests [NDBG.14]#

ds/stepGranularity [NDBG.14.1]#

[NDBG.14.1.1] Changes the step granularity for the current session.

Request:

{ "granularity": "action" | "rule" | "pump" | "input" }
  • "action" — one RHS action. Replay only.

  • "rule" — one whole firing, every RHS action of it. Replay only.

  • "pump" — one pump, to its settled point. The engine asserts one clock tick per pump ([IRET.19.5]), so this is also the clock-tick step.

  • "input" — to the next input the trace or the fact files feed the engine.

The adapter must refuse "action" and "rule" in a live session, with an error saying they are replay only. The default is "action" in replay and "pump" live. When the session changes mode, the granularity becomes the new mode's default unless the client has set one the new mode admits.

A live step with no input left to feed must leave the session paused, and the adapter says so in an output event.

see also: IRET.19.5

ds/loadRecording [NDBG.14.2]#

[NDBG.14.2.1] Loads a recorded fact stream ([RFCS.1]) mid-session, entering replay. The adapter must refuse a trace that was not recorded with the session's program ([NDBG.14r.6.5]).

Request:

{ "path": "/path/to/session.trace" }

Response:

{
  "duration_ns": 45000000000,
  "event_count": 8432,
  "rule_count": 12,
  "schema_count": 7
}

see also: NDBG.14r.6.5, RFCS.1

[NDBG.14.2.2] After this call the session replays the trace from its start, and the step granularity follows [NDBG.14.1.1]'s rule for a change of mode.

see also: NDBG.14.1.1

ds/gotoInstant [NDBG.14g]#

[NDBG.14g.1] Seek to a specific clock instant in the recording.

Request: { "clock_ns": 12345678900 }

Response: {} (engine seeks and emits stopped with reason: "goto")

Deferred: not binding in this edition.

[NDBG.14g.2] Used by the IDE's scrubber UI. Available wherever reverse execution is: in replay, and over the recorded part of a live run ([NDBG.9.2.2]).

Deferred: not binding in this edition.

see also: NDBG.9.2.2

ds/getJustifiers [NDBG.14.3]#

[NDBG.14.3.1] Returns the active justifiers for a logical fact.

Request: { "fact_id": "#42" }

Response:

{
  "justifiers": [
    { "rule_name": "alert_high",
      "firing": "!47",
      "display_name": "alert_high(s=kitchen_temp)",
      "clock_ns": 1234000000 },
    { "rule_name": "pair_check",
      "firing": "!51",
      "display_name": "pair_check(s=kitchen_temp, e=kitchen_temp)",
      "clock_ns": 1236000000 }
  ]
}

ds/getFactLineage [NDBG.14.4]#

[NDBG.14.4.1] Returns the assertion and retraction history for a fact.

Request: { "fact_id": "#42" }

Response:

{
  "asserter": {
    "kind": "rule",
    "rule_name": "sensor_absorb",
    "firing": "!12",
    "clock_ns": 1000000000
  },
  "retractor": {
    "kind": "ttl_expiry",
    "clock_ns": 31000000000
  }
}

[NDBG.14.4.2] asserter.kind is one of:

  • "rule" — a firing asserted it: { "kind": "rule", "rule_name": "sensor_absorb", "firing": "!12", "clock_ns": 1000000000 };

  • "input" — the trace, a fact file or an inject fed it ([NDBG.14.13]);

  • "response" — it is a call's answer ([LCRS.4.3.1]);

  • "engine" — the engine asserted it itself, as it does a fault fact ([LERR.9]).

Each kind other than "rule" carries kind and clock_ns.

retractor is null if the fact is still live. retractor.kind is one of "rule" (a firing retracted it), "ttl_expiry", "support_lost" (a logical fact whose last support ended) and "input" (the trace, a fact file or an inject withdrew it). For "rule", retractor also carries rule_name and firing. The fact breakpoint's retract reasons are these kinds ([NDBG.12.3.2]).

see also: LCRS.4.3.1, LERR.9, NDBG.12.3.2, NDBG.14.13

ds/getWorkingMemory [NDBG.14w]#

[NDBG.14w.1] Returns working memory contents, optionally filtered.

Request:

{
  "schema": "Sensor",
  "where":  "s.entity_id ~ /kitchen/",
  "limit":  50,
  "offset": 0
}

[NDBG.14w.1a] schema filters to one schema type. Omit for all schemas. where is an optional DS expression pattern-filter using the same syntax as a rule where clause, compiled with the compiler; the fact is named by its schema name lower-cased (sensor for Sensor). where requires schema — it is an error to supply where without schema.

Response:

{
  "facts": [
    { "fact_id": "#42",
      "schema": "Sensor",
      "slots": { "entity_id": "kitchen_temp", "value": 95.2 },
      "logical": true,
      "ttl_remaining_ns": null }
  ],
  "total": 3
}

[NDBG.14w.2] Omitting schema returns facts from all schemas. logical: true facts include a _justifiers summary count. ttl_remaining_ns is non-null for TTL facts.

ds/getReteNetwork [NDBG.14.6]#

[NDBG.14.6.1] Returns the Rete network topology, optionally scoped to one rule and optionally including live node occupancy.

Request:

{ "rule_name": "alert_high", "include_occupancy": true }

Response:

{
  "nodes": [
    { "id": "17",
      "kind": "alpha",
      "label": "Sensor",
      "filter": "value > 90.0",
      "occupancy": 2,
      "source": { "path": "rules.ds", "line": 1, "col": 1 } },
    { "id": "5",
      "kind": "terminal",
      "label": "alert_high",
      "pending_activations": 1,
      "source": { "path": "rules.ds", "line": 8, "col": 1 } }
  ],
  "edges": [
    { "from": "17", "to": "5" }
  ]
}

[NDBG.14.6.2] kind is one of "alpha", "beta", "terminal". All labels use DS source terms — schema names, slot names, binding names. Engine-internal identifiers must not appear.

[NDBG.14.6.3] When include_occupancy: true and the engine is running, the adapter returns the response normally but with all occupancy and pending_activations fields set to null. It does not error or pause the engine. This is consistent with [NDBG.13.3.4]. Live counts are only returned when the engine is paused.

see also: NDBG.13.3.4

[NDBG.14.6.4] Omitting rule_name returns the full network. For large rule sets this may be large; the adapter should include a "truncated": true flag and "node_count" when the response exceeds 1 000 nodes, and callers should use the per-rule form for interactive drilling.

ds/getMatchTrace [NDBG.14.7]#

[NDBG.14.7.1] Traces a specific fact through the alpha nodes of the Rete network, showing where it passed and where it was filtered. The engine traces alpha nodes only ([NDBG.4.2]), so the response says that joins are not traced.

Request: { "fact_id": "#39" }

Response:

{
  "fact": { "schema": "Sensor", "slots": { "entity_id": "bedroom", "value": 71.0 } },
  "path": [
    { "node_id": "17",
      "node_kind": "alpha",
      "result": "filtered",
      "detail": "value > 80.0 failed: value is 71.0" }
  ],
  "joins_traced": false
}

see also: NDBG.4.2

[NDBG.14.7.2] result is "passed" or "filtered". For "filtered", detail states exactly which test failed and the runtime values. joins_traced is false: a fact that passes every alpha test and still matches no rule was stopped at a join, which this request cannot show.

ds/getTimerAgenda [NDBG.14.8]#

[NDBG.14.8.1] Returns, in clock order, the deadlines the engine reports exactly: each cooldown window the engine has armed, and each live fact's TTL deadline. The engine reports no pending after timer, so the response must say that they are not listed.

Response:

{
  "timers": [
    { "kind": "cooldown",
      "rule_name": "pair_check",
      "ends_at_ns": 6100000000,
      "remaining_ns": 3440000000 },
    { "kind": "ttl",
      "fact_id": "#42",
      "ends_at_ns": 31000000000,
      "remaining_ns": 28340000000 }
  ],
  "after_listed": false
}

ds/setFactBreakpoints [NDBG.14.9]#

The request, its validation and its stop are [NDBG.12.3].

see also: NDBG.12.3

ds/timelines, ds/switchTimeline, ds/dropTimeline [NDBG.14.17]#

[NDBG.14.17.1] A session holds timelines: the real run, and each hypothesis fork the session has opened. A fork starts at a position in another timeline with one change there: an inject ([NDBG.14.13.1], [NDBG.14.14.1]), or a mock that answers a recorded call differently ([NDBG.14.15.2]). Opening a fork switches the session to it. A fork's firings have thread ids of their own ([NDBG.10.1.2]), and restart drops every fork ([NDBG.9.3.2]).

see also: NDBG.10.1.2, NDBG.14.13.1, NDBG.14.14.1, NDBG.14.15.2, NDBG.9.3.2

[NDBG.14.17.2] ds/timelines lists them, the one the session follows marked:

{
  "timelines": [
    { "timeline": "%0", "current": false },
    { "timeline": "%1", "from": "%0", "at_ns": 12000000000,
      "change": "Sensor #42 asserted", "current": true }
  ]
}

ds/switchTimeline { "timeline": "%0" } makes the session follow another timeline, at the position it held there, and the adapter emits stopped with reason: "goto". ds/dropTimeline { "timeline": "%1" } drops a fork and every fork opened from it. The adapter must refuse to drop %0, or the timeline the session follows, with a DAP error.

ds/advanceClock [NDBG.14.18]#

[NDBG.14.18.1] At the end of a live run, moves the engine's clock forward and pumps once, then stops with reason: "step".

Request: { "by": "5_s" } — a duration, or a whole number of nanoseconds.

In replay, and behind a live run's end, the clock is the recorded run's: the adapter must refuse the request with a DAP error saying so.

ds/answerCall [NDBG.14.19]#

[NDBG.14.19.1] Answers one call waiting in the Calls scope ([NDBG.13.1.1]), once.

Request: { "corr": "c-0012", "response": { "state": "on" } }, or with error in place of response.

response and error are as [NDBG.14.15.1] gives them. The answer lands as an inject does ([NDBG.14.13.1]): into a live run at its end, and into a new hypothesis fork anywhere else. A corr that names no waiting call → DAP error.

see also: NDBG.13.1.1, NDBG.14.13.1, NDBG.14.15.1

ds/streamEvents [NDBG.14.20]#

[NDBG.14.20.1] Chooses which DS stream events ([NDBG.15]) the adapter sends from now on, replacing the choice the events launch argument made ([NDBG.9.3.1]).

Request: { "kinds": ["factAsserted", "callMade"] } — each the event's name without ds/. An empty list sends none. An unknown name → DAP error naming it.

see also: NDBG.15, NDBG.9.3.1

ds/getActivationPath [NDBG.14.11]#

[NDBG.14.11.1] Returns the complete pattern-and-join match chain that produced a given firing — the activation-path view per LDEB.3.3.4. Answers "exactly which facts matched each LHS pattern?"

Request: { "firing": "!47" }, or { "threadId": 9 }

Response:

{
  "rule_name": "pair_check",
  "display_name": "pair_check(s=kitchen_temp, e=kitchen_temp)",
  "steps": [
    { "pattern_index": 0,
      "schema": "Sensor",
      "binding": "s",
      "fact_id": "#42",
      "slots": { "entity_id": "kitchen_temp", "value": 95.2 },
      "join_result": "passed",
      "join_detail": "alpha filter passed (no where on this pattern)" },
    { "pattern_index": 1,
      "schema": "Event",
      "binding": "e",
      "fact_id": "#77",
      "slots": { "entity_id": "kitchen_temp", "payload": "{}" },
      "join_result": "passed",
      "join_detail": "join e.entity_id == s.entity_id: both 'kitchen_temp'" }
  ]
}

see also: LDEB.3.3.4

[NDBG.14.11.2] steps are in LHS pattern declaration order. join_result is "passed" for all steps in a resolved activation (it fired because all patterns matched). join_detail is a human-readable explanation using DS source terms.

[NDBG.14.11.3] The adapter must answer for any firing in the current timeline, named by its "!N" or by its thread id ([NDBG.9.3.5], [NDBG.10.1.2]), and return a DAP error for one the timeline does not hold.

see also: NDBG.10.1.2, NDBG.9.3.5

ds/getRefractedActivations [NDBG.14.12]#

[NDBG.14.12.1] Returns activations that matched but were prevented from firing by refraction per LDEB.3.4.3, with their bindings filled in by source name. Each entry's display_name is the rule's name. These are not in the Agenda scope. The engine does not report after supersedure, so suppressed is empty and the response must say that supersedure is not reported.

Request: { "rule_name": "" }

Response:

{
  "refracted": [
    { "rule_name": "alert_high",
      "display_name": "alert_high",
      "reason": "refraction",
      "detail": "activation already fired at T=1.234_s with the same bindings",
      "bindings": { "s": { "fact_id": "#42", "entity_id": "kitchen_temp" } } }
  ],
  "suppressed": [],
  "supersedure_reported": false
}

see also: LDEB.3.4.3

[NDBG.14.12.2] reason is "refraction". detail is a human-readable explanation. rule_name filter is optional; empty string returns all rules.

ds/assertFact [NDBG.14.13]#

[NDBG.14.13.1] Injects a fact from the debugger while the session is paused. Where it lands:

  • at the end of a live run: into the run itself, as an input; the next step pumps it;

  • anywhere else (behind a live run's end, or in replay): the adapter opens a hypothesis fork at the current position with the fact asserted, and the session follows the fork ([NDBG.14.17]).

Request:

{
  "schema": "Sensor",
  "slots": { "entity_id": "debug_probe", "value": 99.9 }
}

Response:

{
  "fact_id": "#42",
  "timeline": "%1",
  "message": "opened fork %1 at T=12.0s with Sensor asserted"
}

see also: NDBG.14.17

[NDBG.14.13.2] slots is one row of the schema: a JSON object with a value per slot, each read as the slot's declared type. The fact takes its schema's own lifetime: no public entry point sets a fact's TTL. The adapter must refuse a request that carries a ttl with an error response, and inject nothing. The response's message states what was done ("asserted Sensor #42 into the real run", "opened fork %1 at T=12.0s with Sensor asserted"), and the adapter sends it as an output event too. The adapter asks for no confirmation.

[NDBG.14.13.3] schema must name a schema in the loaded rule set. Unknown schema → DAP error "no schema 'X'". A slot value that does not read as its slot's type → DAP error naming the slot. An assert the engine refuses → DAP error carrying the engine's code.

ds/retractFact [NDBG.14.14]#

[NDBG.14.14.1] Retracts a fact by id while the session is paused. It lands as an assert does ([NDBG.14.13.1]): into a live run at its end, and into a new hypothesis fork anywhere else. The adapter does what the engine allows for that fact, and when the engine refuses it, returns a DAP error carrying the engine's code.

Request: { "fact_id": "#42" }

Response:

{ "timeline": "%0", "message": "retracted Sensor #42 from the real run" }

see also: NDBG.14.13.1

[NDBG.14.14.2] Unknown or already-retracted fact_id → DAP error "fact 'X' not in working memory".

[NDBG.14.14.3] The response's message states what was done, and the adapter sends it as an output event, as in [NDBG.14.13.2].

see also: NDBG.14.13.2

ds/installMock [NDBG.14.15]#

[NDBG.14.15.1] Installs a standing answer for calls, matched by one call correlation (corr) or by service name (service). Per LDEB.2.2.6.

Request:

{
  "corr": "c-0012",
  "response": { "state": "on" }
}

response is one row of the service's response schema ([LCRS.4.3.1]), read as [NDBG.14.13.2] reads slots. In its place, error answers with a failure, { "code": …, "message": "…" }, which the call's continuation receives as a CallError ([LCRS.4.2]). A request carries exactly one of corr and service, and exactly one of response and error.

Response: { "mock_id": "mock-0001" }

see also: LCRS.4.2, LCRS.4.3.1, LDEB.2.2.6, NDBG.14.13.2

[NDBG.14.15.2] When the engine issues a call the mock matches, the adapter answers it with the mock. In replay, a mock that would answer a recorded call differently from the trace opens a hypothesis fork at the first such call after the current position ([NDBG.14.17]).

see also: NDBG.14.17

[NDBG.14.15.3] A mock matched by service answers every call to it:

{
  "service": "light.turn_on",
  "error": { "code": "transport.unreachable", "message": "bridge offline" },
  "times": 0
}

times: 0 means "match until explicitly removed." times: N means answer N calls, then remove the mock. Absent, times is 1.

ds/removeMock [NDBG.14.16]#

[NDBG.14.16.1] Removes a previously-installed mock.

Request: { "mock_id": "mock-0001" }

[NDBG.14.16.2] mock_id is returned by ds/installMock in its response: { "mock_id": "mock-0001" }.


Custom events [NDBG.15]#

[NDBG.15.9] The adapter emits these DS-specific events in addition to the standard DAP event stream. All carry type: "event" and a event string prefixed "ds/". They are off by default: the adapter must send only the kinds the events launch argument ([NDBG.9.3.1]) or ds/streamEvents ([NDBG.14.20]) chose, and only while the session moves forward, never moving back or re-driving from a checkpoint. Their ids are [NDBG.9.3.5]'s.

see also: NDBG.14.20, NDBG.9.3.1, NDBG.9.3.5

ds/factAsserted [NDBG.15.1]#

{
  "schema": "Sensor",
  "fact_id": "#42",
  "slots": { "entity_id": "kitchen_temp", "value": 95.2 },
  "asserter": { "kind": "rule", "rule_name": "sensor_absorb", "firing": "!12" },
  "clock_ns": 1000000000,
  "logical": false
}

asserter is as [NDBG.14.4.2] gives it.

see also: NDBG.14.4.2

ds/factRetracted [NDBG.15.2]#

{
  "schema": "Sensor",
  "fact_id": "#42",
  "retractor": { "kind": "ttl_expiry" },
  "clock_ns": 31000000000
}

retractor is as [NDBG.14.4.2] gives it.

see also: NDBG.14.4.2

ds/logicalFactFlipped [NDBG.15.3]#

{
  "schema": "AlertActive",
  "fact_id": "#55",
  "direction": "retract",
  "justifier_count": 0,
  "clock_ns": 45000000000
}

direction is "assert" (fact came into existence) or "retract" (fact left WM when its last justifier withdrew).

ds/callMade [NDBG.15.4]#

Sent when the engine issues a call.

{
  "corr": "c-0012",
  "service": "light.turn_on",
  "kwargs": { "entity_id": "kitchen", "brightness": 80 },
  "firing": "!21",
  "clock_ns": 2000000000
}

ds/pauseRequested [NDBG.15.6]#

DAP notification (type: "event", no response expected) sent from the leader tier to follower tiers in a debug group when a breakpoint fires, requesting coordinated pause per [NDBG.22.2.1].

{
  "leader_tier_id": "sensor_tier",
  "reason": "breakpoint",
  "breakpoint_description": "Sensor asserted: entity_id=kitchen_temp"
}

reason matches the reason field of the stopped event on the leader tier. Followers finish their current pump cycle then pause.

Deferred: not binding in this edition.

see also: NDBG.22.2.1

ds/tierPauseState [NDBG.15.7]#

Emitted by a follower tier when its pause state changes per [NDBG.22.2.2].

{
  "tier_id": "analytics_tier",
  "state": "pause_pending",
  "leader_tier_id": "sensor_tier"
}

state is "pause_pending" (received ds/pauseRequested, finishing current pump cycle) or "paused" (pump cycle complete, fully paused).

Deferred: not binding in this edition.

see also: NDBG.22.2.2

ds/tierPauseTimeout [NDBG.15.8]#

Emitted by the leader when a follower does not reach paused state within the configured timeout per [NDBG.22.3].

{
  "tier_id": "analytics_tier",
  "timeout_ms": 5000,
  "leader_tier_id": "sensor_tier"
}

Deferred: not binding in this edition.

see also: NDBG.22.3

ds/callAnswered [NDBG.15.5]#

Sent when a call's answer reaches the engine: a response row of the service's response schema, or an error delivered as a CallError ([NDBG.14.15.1]).

{
  "corr": "c-0012",
  "service": "light.turn_on",
  "response": { "state": "on" },
  "clock_ns": 2050000000
}

see also: NDBG.14.15.1

Standard DAP surface summary [NDBG.16]#

[NDBG.16.1] The table below maps DS concepts to the standard DAP surface used, and identifies where custom extensions fill gaps.

DS concept

DAP surface

Custom extension

Session lifecycle

initialize, launch, configurationDone ([NDBG.9.3.7]), restart, disconnect

ds/loadRecording for replay; launch arguments in [NDBG.9.3.1]

Execution control

continue, next, stepIn, stepOut, stepInTargets, pause ([NDBG.11.1.4])

ds/stepGranularity ([NDBG.14.1]); ds/advanceClock ([NDBG.14.18])

Reverse execution

stepBack, reverseContinue

—

Jump to a firing

gotoTargets, goto ([NDBG.14r.5])

—

Rule-fire breakpoints

setFunctionBreakpoints

—

Source-line breakpoints

setBreakpoints (rule, after and on response lines)

—

Exception breakpoints

setExceptionBreakpoints ([NDBG.12.6])

—

Fact-event breakpoints

—

ds/setFactBreakpoints ([NDBG.12.3])

Cache-op breakpoints

—

ds/setCacheBreakpoints ([NDBG.12.5])

Firings

threads, stackTrace ([NDBG.10.1])

— (RuleDebugName for display names)

Bound variables

scopes, variables (Bindings scope)

—

Working memory (all)

scopes, variables (WM scope)

ds/getWorkingMemory with where filter ([NDBG.14w])

Cache and calls

scopes, variables (Cache and Calls scopes, [NDBG.13.1.1])

—

Logical justifiers

variables (_justifiers child)

ds/getJustifiers ([NDBG.14.3])

Json slot drilling

variables (recursive, [NDBG.13.5])

—

Watches, hovers and the debug console

evaluate ([NDBG.13.7])

—

The program's log lines

output events, category "stdout" ([NDBG.9.3.6])

—

WM delta between positions

—

ds/diffWorkingMemory ([NDBG.20])

Fact lineage

—

ds/getFactLineage ([NDBG.14.4])

Firing match path

—

ds/getActivationPath ([NDBG.14.11])

Refracted activations

—

ds/getRefractedActivations ([NDBG.14.12])

Fact injection

—

ds/assertFact, ds/retractFact ([NDBG.14.13], [NDBG.14.14])

Call answers

—

ds/answerCall ([NDBG.14.19]); ds/installMock, ds/removeMock ([NDBG.14.15], [NDBG.14.16])

Hypothesis forks

—

ds/timelines, ds/switchTimeline, ds/dropTimeline ([NDBG.14.17])

Rete topology

—

ds/getReteNetwork ([NDBG.14.6])

Match trace

—

ds/getMatchTrace ([NDBG.14.7])

Timer agenda

—

ds/getTimerAgenda ([NDBG.14.8])

Event trace events

output events

ds/factAsserted, ds/factRetracted, ds/logicalFactFlipped, ds/callMade, ds/callAnswered ([NDBG.15]); chosen by ds/streamEvents ([NDBG.14.20])


see also: NDBG.10.1, NDBG.11.1.4, NDBG.12.3, NDBG.12.5, NDBG.12.6, NDBG.13.1.1, NDBG.13.5, NDBG.13.7, NDBG.14.1, NDBG.14.11, NDBG.14.12, NDBG.14.13, NDBG.14.14, NDBG.14.15, NDBG.14.16, NDBG.14.17, NDBG.14.18, NDBG.14.19, NDBG.14.20, NDBG.14.3, NDBG.14.4, NDBG.14.6, NDBG.14.7, NDBG.14.8, NDBG.14r.5, NDBG.14w, NDBG.15, NDBG.20, NDBG.9.3.1, NDBG.9.3.6, NDBG.9.3.7

Protocol commitments [NDBG.17]#

  • [NDBG.17.1] DAP is the protocol. Standard transport, session lifecycle, execution control, variable inspection, and events are all stock DAP. DS-specific surface is additive custom extensions.

  • [NDBG.17.2] Firings as threads ([NDBG.10.1.1]). Each firing the session shows is a DAP thread. Those other than the focused one use subtle stack frames pointing to the rule declaration. RuleDebugName atoms (RDSC.6.8) supply human-readable display names so the thread panel is legible without numeric IDs.

see also: NDBG.10.1.1, RDSC.6.8

  • [NDBG.17.3] Immediate breakpoint validation ([NDBG.12.3.3]). ds/setFactBreakpoints where expressions are compiled synchronously with the compiler. Authors see errors before running.

see also: NDBG.12.3.3

  • [NDBG.17.4] O(log N) reverse navigation ([NDBG.14r.2]). The reverse index is built at recording load time (O(N) once), or as a live run is recorded; all reverse-navigation operations are O(log N) binary search plus checkpoint re-drive. Conforming adapters must pre-index — lazy scanning is not permitted.

see also: NDBG.14r.2

  • [NDBG.17.5] Rete visualisation in author terms. ds/getReteNetwork and ds/getMatchTrace use DS source labels throughout. Engine internals must not appear in any response.

  • [NDBG.17.6] Occupancy only when paused. Node occupancy and WM fact counts return null while the engine is running. This prevents stale snapshot confusion in live debugging.


ds/diffWorkingMemory [NDBG.20]#

[NDBG.20.1] Returns the working-memory delta between two positions, each a timeline and an instant in it ([NDBG.14.17]): two instants of one timeline, or a fork against the real run.

Request:

{
  "from": { "timeline": "%0", "at_ns": 45000000000 },
  "to":   { "timeline": "%1", "at_ns": 46000000000 }
}

Response:

{
  "asserted": [
    { "schema": "Alert",
      "fact_id": "#99",
      "slots": { "entity_id": "kitchen_temp", "level": "high" } }
  ],
  "retracted": [
    { "schema": "Sensor",
      "fact_id": "#42",
      "slots": { "entity_id": "bedroom", "value": 71.0 } }
  ]
}

see also: NDBG.14.17

[NDBG.20.2] Within one timeline, asserted holds the facts that entered WM in the half-open interval [from, to) and retracted those that left it. Across two timelines, asserted holds the facts in WM at to and not at from, and retracted the reverse. DS facts are immutable (retract + reassert, never in-place modify), so there is no modified bucket.

[NDBG.20.3] Within one timeline, a fact that was asserted and then retracted inside the interval appears in both lists. The author sees the churn.

[NDBG.20.4] Results are ordered by clock instant ascending within each list. Within one timeline, if from is not before to the adapter returns an error: "from must be strictly before to".

[NDBG.20.5] Each position must lie within what its timeline has recorded. For one that does not, the adapter returns a DAP error naming it.


Checkpoint granularity [NDBG.21]#

[NDBG.21.1] Checkpoints are full snapshots of engine state (WM + agenda), taken during the forward indexing pass at load time, or as a live run is recorded. They bound the re-drive cost for reverse navigation. When the adapter takes one is implementation-defined ([NDBG.14r.2.3]).

see also: NDBG.14r.2.3

[NDBG.21.4] The adapter reports the actual checkpoint count in the ds/loadRecording response:

{
  "duration_ns": 45000000000,
  "event_count": 8432,
  "wm_mutation_count": 1204,
  "checkpoint_count": 3,
  "rule_count": 12,
  "schema_count": 7
}

Deferred: not binding in this edition.

Multi-tier coordinated breakpoints [NDBG.22]#

Deferred: not binding in this edition.

Debug groups [NDBG.22.1]#

[NDBG.22.1.1] A debug group is a named set of tiers that coordinate pauses. Specified in the attach arguments:

{
  "tier_id": "sensor_tier",
  "debug_group": ["sensor_tier", "analytics_tier"]
}

checks: tla

[NDBG.22.1.2] Tiers in the same debug group form a leader-follower pause relationship. The tier whose breakpoint fires first is the leader for that pause event. All others are followers.

checks: tla×3

Leader-follower pause [NDBG.22.2]#

[NDBG.22.2.1] When a breakpoint fires in the leader tier:

  1. The leader pauses immediately and emits stopped.

  2. The leader sends a ds/pauseRequested notification to all followers in the group.

  3. Each follower finishes its current pump cycle — a bounded latency window, at most one cycle — then pauses and emits stopped.

  4. The IDE shows a ⚠ pause pending indicator on follower threads until they reach their pause point.

checks: tla×7

[NDBG.22.2.2] The ⚠ pause pending state is communicated via a ds/tierPauseState event ([NDBG.15.7]).

state transitions from "pause_pending" to "paused" when the follower's pump cycle completes.

checks: tla×3 — see also: NDBG.15.7

[NDBG.22.2.3] The skew between leader and follower is bounded to at most one pump cycle. This is not bit-exact atomic pause but is deterministic and the skew window is known and small.

checks: tla×2

[NDBG.22.2.4] Zero-skew cross-process pause would require a shared synchronisation primitive — a distributed barrier — which this protocol does not define.

Follower timeout [NDBG.22.3]#

[NDBG.22.3.1] If a follower tier does not reach its pause point within a configurable timeout (default 5 s), the leader emits a ds/tierPauseTimeout event and the IDE marks the follower as "unresponsive". The leader's pause state is not affected.

checks: tla×5

[NDBG.22.3.2] Timeout is configurable per debug group in the attach arguments: "group_pause_timeout_ms": 5000.


checks: tla

Deferred to post-v1 [NDBG.24]#

Items excluded from the v1 conformance requirement. Conforming v1 adapters may implement them; they may not.

An entry here must be a scope decision, not a progress report. A deferral is legitimate when v1 does not have the thing to observe, or when the obligation is already discharged by another surface and only a convenience is deferred — and an entry claiming the second must say which surface, so a reader can check it. "Not yet built" is not a deferral: an unmet must stays a must and is a reportable gap against the implementation, while an absent one is nothing at all.

  • [NDBG.24.1] Uniform error response format. Custom requests use DAP error semantics. A structured DS error envelope is deferred.

  • [NDBG.24.2] Observe-level enforcement mechanism. The principle (no side effects) is specified; runtime-level enforcement strategy (scheduler isolation, etc.) is implementation- specific and not part of the v1 conformance test.

  • [NDBG.24.4] ds/snapshotState (LDEB.4.2.6). Capture full engine state for later comparison. Client-side workaround: call ds/getWorkingMemory and ds/getReteNetwork and save the results.

see also: LDEB.4.2.6

  • [NDBG.24.7] In-flight calls ([LDEB.3.7.2]). A dedicated query for calls issued but not yet resolved is deferred. The obligation is derivable, not unmet: the Calls scope lists the calls still waiting ([NDBG.13.1.1]), and ds/callMade and ds/callAnswered events ([NDBG.15.4], [NDBG.15.5]) carry the issue and the answer, so a client holds the elapsed time by subtraction from the issue instant. This is the same client-side reconstruction [NDBG.24.4] states explicitly, and what is deferred is the convenience of not doing it.

see also: LDEB.3.7.2, NDBG.13.1.1, NDBG.15.4, NDBG.15.5, NDBG.24.4

  • [NDBG.24.8] True atomic multi-tier pause. Zero-skew cross- process barrier. Requires distributed synchronization primitive. Deferred post-v1 (see NDBG.22.2.4).

see also: NDBG.22.2.4