Expand description
Authoritative writer for session metadata fields (title, pinned, …).
All callers that mutate session metadata MUST go through this service. Each method follows a fixed pipeline so that title/pinned writes never diverge in subtle ways (load order, version bump, save semantics, event shape):
- Trim / validate input (fail-fast before acquiring the lock).
persistence.acquire_lock(session_id)— serialise all writes for this session so that commit order == publish order.storage.load_session(session_id)— pick up the latest authoritative copy from disk (not a runner-held session that may have stale metadata).- Re-check preconditions inside the lock (e.g.
is_untitledforapply_generated_titlewhen not forced; equality short-circuit for setters that would be a no-op). - Mutate the field, bump
title_version(for title) and always bumpmetadata_version, setupdated_at. - Plain
storage.save_session(&session)— no merge needed because we loaded the latest copy inside the lock and no other writer for this session could have interleaved. - Refresh the in-memory cache (
state.sessions). - Build the corresponding
AgentEventfrom the final persisted session and publish viapublish_replayable_session_event.
§Authority rules
set_title/apply_generated_title: the only authoritative writers fortitleandtitle_version. The runtime engine, scheduler, and tool execution paths are non-authoritative and must stay onmerge_save_session/merge_save_runtimewithout touchingtitledirectly.set_pinned: the only authoritative writer forpinned.- Only these methods bump
metadata_version. Runtime paths never bump it, somerge_save_session/merge_save_runtimecan use it as a staleness signal for the entire authoritative metadata group.
Structs§
Enums§
- Metadata
Error - Errors returned by
SessionMetadataService.
Type Aliases§
- Metadata
Change - Outcome of a metadata mutation.