OpenProgram Docs

Cross-module UI invariants

Breaking a rule changes this list first, then the code. Each rule should have a pinning test under tests/unit/.

Change model or provider toggle custom provider deleted Forget _clear_stale_defaults last used, chat, exec, default agent Broadcast agent_settings_changed through the event bus Refetch agent settings: chips models-enabled: dropdowns
  1. Changemodel or provider togglecustom provider deleted
  2. Forget_clear_stale_defaultslast used, chat, exec,default agent
  3. Broadcastagent_settings_changedthrough the event bus
  4. Refetchagent settings: chipsmodels-enabled: dropdowns

Rules 1 to 3. A new entry point that changes the set (config import, bulk operations, CLI writes) hooks the same broadcast; Settings may be in another tab.

RuleHolds through
1. The enabled set is the only model gatelist_enabled_models(): spec rows in the providers config. Disabled means no picker, no default, no chip
2. Enabled-set changes broadcastEvery consumer reacts, as drawn
3. Disabling the last used model forgets itNew conversations start on last_used_model in config.json; there is no default. Hiding would keep it serving background work and bring it back on re-enable
4. The frontend store can express clearedsetAgentSettings field: object replaces, null clears, undefined keeps. ?? alone cannot overwrite a stale value; any field the backend can report gone needs this
5. Backend-to-frontend frames go through the event busemit_ws_frame({"type": ..., "data": ...}); one server subscriber forwards to the sockets (event layer). _s._broadcast hides a frame from bus consumers (proactive, logging) and audit. Exempt, carrying session routing: _broadcast_envelope, _broadcast_chat_response
6. The three spawn entry points share one semanticsClean mode: spawn_caller makes the branch root's caller the opening turn, not ROOT. Change and test together
7. The chat sibling switcher appears only on real forks< N/M > sets group by fork point (predecessor, else caller; ROOT means none) and hold conversation turns only
8. Instant interaction feedbackInteraction feedback. Function runs pay about 1s of subprocess cold start, which must never feel like a dead click
9. Display order may change; data order may notThe attach pointer stays at the tail for head movement, yet the Spawned card renders before the reply it fed. Solved in the server projection (transcript/children.py), never in persisted order or head semantics
10. SSR boundary: no window at module scopeapps/web/lib/runtime-bridge/* may read window at module scope (session/chat-handlers.ts); a static import from a prerendered page breaks. New modules keep this or defer window access into function bodies
11. A transcript row draws what the server sentThe main chat, a split pane and an expanded sub-agent all draw through TranscriptRows. Each row dispatches on its rowKind with no default branch and takes its conversation from the row list, never from the focused one
Rule 1: surfaces
SurfaceSource
Top-bar chat and exec chipsthe gated GET /api/agent_settings
Reads of that endpointOne request in flight per conversation and branch (lib/agents/agent-settings-request.ts): the socket connecting, the conversation loading and the composer mounting share its answer, and nothing is kept after it. agent_settings_changed or this page's own write makes later callers ask again
Model picker dropdowns/api/models/enabled
Default resolution on send_resolve_session_provider_model, including the agent.json model path
Function executionthe exec runtime

Empty picker, no model in the top bar and the enable-a-model send error hold together.

Rule 3: what is cleared
RecordCleared when
last_used_model (openprogram/models/providers/catalog/last_used.py)It leaves the enabled set
runtime_management chat global, default agent's model in agent.jsonThe chat global's model leaves the set
runtime_management exec globalThe exec global's model leaves the set

All in _clear_stale_defaults.

Rule 6: entry points and budgets
EntryPath
agent(), synchronousopenprogram/programs/tools/agents/agent/agent/agent.py
Asynchronous runneropenprogram/runtime/jobs/runner/
send_messageopenprogram/programs/tools/agents/send_message/
SettingDefaultCounts
agent.max_spawn_depth1Generations of new agents; only creating one counts. At 1 a spawned agent's agent() spawn is refused and it does the work itself
agent.max_messages0, no limitMessages in the chain, whatever the tool, replies included

Tool exposure is binary: agent leaves the listing when messages or generations run out, except in a fork, which keeps its caller's tool list for the shared prompt cache and is refused at run time. read_conversation stays. An agent reading a worker's result keeps its own generation count, so it can spawn the next wave. See agent collaboration.

Rule 7: never joins
RowWhy
Tool and code sub-call rows, ROOTThey have no predecessor and would pollute the root set
source=agent_spawn branch rootsGrouped apart from the user's turns: an agent-opened branch is not a pageable alternative
display=runtime cardsFunction-run cards have their own navigation
Rule 10: how pages load it
ImporterLoad
App Router pages and the shellnext/dynamic with ssr: false
Settings componentsDynamic import(), as refreshAgentChip does
Components inside the shellMay import statically: never prerendered

Implementation status

Not yet: rule 5 holds for external sources and part of the server. Other routes and WebSocket actions (routes/chat.py, routes/catalog/, ws_actions/) still call _broadcast directly.

Last updated · 2026-11-25