pub(crate) fn persist_session_id(
block_id: &str,
sid: &str,
mstore: &Option<Arc<Store>>,
event_bus: &Option<Arc<EventBus>>,
)Expand description
Persist a newly captured session ID to block metadata and broadcast the
waveobj:update event so the frontend reflects the change immediately.
Every controller that captures a session id goes through this one path
(persistent/stdout_reader.rs and stderr_reader.rs, subprocess/host_spawn.rs
and container_spawn.rs, acp.rs, app_server_controller.rs); ACP used to only set
inner.session_id in memory.
Also writes through to the matching db_agent_instances row’s
session_id column (SPEC_PANE_CLOSE_REOPEN_CONTINUITY_GUARANTEE_2026_07_27.md
§4.1). Without this, that column was set to "" at instance creation and
never updated again in production — ListRecentSessionsCommand prefers
the local row over the shared registry whenever both exist, so the “My
Agents” picker’s reattach flow (AgentPicker.tsx’s handleReattach) was
handed an empty session id even mid-session, and — per
agent-model.ts’s own documented invariant that an empty
continueSessionId clears agent:sessionid on the new block — silently
started a genuinely fresh conversation instead of resuming. Best-effort:
logs and continues on failure, since the block-meta write above (the
live-turn source of truth) already succeeded.
No-ops silently when mstore is None (e.g. in unit tests that don’t wire
up a store).