Skip to content

feat(client): StateBus observer + tag API#203

Open
runyaga wants to merge 1 commit into
soliplex:mainfrom
runyaga:feat/state-bus-observer
Open

feat(client): StateBus observer + tag API#203
runyaga wants to merge 1 commit into
soliplex:mainfrom
runyaga:feat/state-bus-observer

Conversation

@runyaga
Copy link
Copy Markdown
Contributor

@runyaga runyaga commented May 1, 2026

Part of #202 (1 of 4 stacked PRs). Merge first — base for the other three.

What this changes

StateBus (in soliplex_client) gains:

  • void Function() addObserver(BusObserver observer) — register a
    callback that fires after every successful commit. Returns a
    disposer for symmetric tear-down. Detaching during dispatch is
    safe (siblings still fire). Adding to a disposed bus is a no-op.
  • Optional String? tag argument on setAgentState and update
    writers can label the source of each commit, observers receive it.

Why this shape

The upcoming Bus Inspector (#202) needs to record every state commit
with thread context. Putting the recording logic on a per-bus
observer keeps the bus pure (no inspector dependency) and lets any
future diagnostic plug in without modifying core code.

The tag argument is optional so existing callers don't change; the
agent layer will set it explicitly only at the seed paths
(seed.initial, seed.history).

Testing

11 new unit tests cover dispatch ordering, dispose semantics, the
self-detaching-during-dispatch case, tag preservation, and disposed-bus
safety. Existing tests unchanged.

Stack

  1. This PR — StateBus observer + tag API
  2. `feat/agent-runtime-observers` — bus + event observers on AgentRuntime
  3. `feat/bus-inspector-diagnostics` — Bus Inspector module
  4. `feat/wire-bus-inspector` — wire into shell

Adds an additive `addObserver` hook on `StateBus` that fires after
every successful commit, plus an optional `tag` argument on
`setAgentState` and `update` so writers can label the source of each
write. Observers receive `(tag, snapshot)`; the snapshot is the
frozen post-commit map already exposed via `agentState`.

`addObserver` returns a disposer for symmetric tear-down. Detaching
during dispatch is safe (siblings still fire). Adding to a disposed
bus is a no-op.

Pure additive: existing call sites continue to work without
modification, and the new `BusObserver` typedef is exported via the
existing `application` barrel.

11 tests cover the observer dispatch ordering, dispose semantics,
self-detaching observers, tag preservation, and disposed-bus
safety.

Foundation for an upcoming Bus Inspector debug surface that needs
to record every state commit on a per-thread basis without forcing
a bus dependency on the agent layer's diagnostics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant