Skip to content

feat(traces): stamp opencode's session title on session spans - #120

Open
Moep90 wants to merge 1 commit into
DEVtheOPS:mainfrom
Moep90:feat/session-title
Open

feat(traces): stamp opencode's session title on session spans#120
Moep90 wants to merge 1 commit into
DEVtheOPS:mainfrom
Moep90:feat/session-title

Conversation

@Moep90

@Moep90 Moep90 commented Aug 24, 2026

Copy link
Copy Markdown

What

Adds a session.title span attribute carrying the name opencode gives a session.

Session spans identify a run by id only. In a backend that reads as ses_fcc85048effeCXe1RvEetcywD4, which says nothing about what the session was. opencode names every session from its first prompt and ships that name in its session events, so the plugin can pass it on for free.

How

session.created fires before opencode has named the session; the name arrives with session.updated a moment later. So:

  • handleSessionUpdated (new) records the title and stamps it on the spans still open for that session: the subagent session span and the active run span.
  • handleRunStarted picks up a title that is already known, for runs that start after the naming.
  • handleSessionCreated takes the title if opencode already has one.

The map is bounded with setBoundedMap like the other per-session state and swept in sweepSession on session.idle. Sessions opencode has not named carry no session.title at all, and an empty title never overwrites a known one. Nothing is emitted when session traces are disabled, though the title is still tracked so a later run span can use it.

Verified

  • bun run lint, bun run typecheck, bun test — 334 pass, 0 fail (8 new tests).
  • End to end against a real opencode 1.18.21 into Grafana Alloy → Tempo. The span came back as:
{"session.title": "session title check", "input.value": "\"Say exactly: session title check\""}

which is opencode's own generated title for that session, matching the title column in its opencode.db.

Notes

  • Attribute name follows the existing convention on these spans (session.is_subagent, agent.type).
  • No new configuration. If a title is wanted out of the trace data only for some deployments, OPENCODE_DISABLE_TRACES=session already covers it.

Session spans carry the id only, and an id like ses_fcc85048effeCXe1RvEetcywD4
tells a reader nothing. opencode names every session from its first prompt and
already ships that name in the session events, so the plugin can pass it on.

session.created is emitted before the name exists, so the title arrives with
session.updated a moment later. The handler records it and stamps it on the
spans that are still open for that session, the subagent session span and the
active run span, and handleRunStarted picks up a title that is already known
for runs that start afterwards. Sessions opencode has not named carry no
session.title at all, and an empty title never overwrites a known one.

The map is bounded like the other per-session state and swept on session.idle.

Signed-off-by: moep90 <volleyballlive@googlemail.com>
@Moep90
Moep90 force-pushed the feat/session-title branch from f69d866 to 564d251 Compare August 24, 2026 14:45
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