Skip to content

Extract agent session management, run-manager, and usage stats to @studio/common - #3987

Merged
youknowriad merged 6 commits into
trunkfrom
extract-agent-sessions
Jun 30, 2026
Merged

Extract agent session management, run-manager, and usage stats to @studio/common#3987
youknowriad merged 6 commits into
trunkfrom
extract-agent-sessions

Conversation

@youknowriad

Copy link
Copy Markdown
Contributor

Proposed Changes

Behavior-preserving refactor. Moves the agent-session backend into transport-agnostic modules under @studio/common so the desktop app and the upcoming studio ui local web server share one implementation:

  • ai/sessions/manage — session listing + creation (hydrated with star/archive + site placement)
  • ai/sessions/run-manager — the agent run lifecycle (fork CLI, relay events, interrupt policy)
  • ai/sessions/placement — which local site a session owns (app.json)
  • ai/sessions/agent-stats + lib/app-bump-stats — Studio Code usage stats
  • lib/error-reporting — SDK-agnostic Sentry reporting helper

The desktop side now delegates: ai-agent/run-manager, ai-session-placement, bump-stats, and the session IPC handlers. Adds @sentry/core + atomically to tools/common. No user-facing change.

Independent of the site-operations PR; based on trunk. Part of splitting the studio ui proof-of-concept (#3953).

Testing Instructions

  • npm run typecheck clean for tools/common, apps/studio, apps/cli.
  • npm test -- tools/common/ai/sessions/tests/ (17 tests pass).
  • Smoke: start a new chat (with and without a site), send a prompt, interrupt a run, star/archive a session.

Pre-merge Checklist

  • Verify agent runs, session create/list, and usage-stat bumping still work in the desktop app.
…udio/common

Moves session listing/creation (manage), the agent run lifecycle (run-manager), site placement (placement), Studio Code usage stats (agent-stats + app-bump-stats), and a Sentry reporting helper (error-reporting) into transport-agnostic @studio/common modules. Desktop's ai-agent/run-manager, ai-session-placement, bump-stats, and the session IPC handlers now delegate to them. Adds @sentry/core + atomically to tools/common. No behavior change; this is the shared backend the studio ui local server will reuse. Part of splitting #3953.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wpmobilebot

wpmobilebot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing ea5624e vs trunk

app-size

Metric trunk ea5624e Diff Change
App Size (Mac) 1315.66 MB 1315.67 MB +0.01 MB ⚪ 0.0%

site-editor

Metric trunk ea5624e Diff Change
load 734 ms 1088 ms +354 ms 🔴 48.2%

site-startup

Metric trunk ea5624e Diff Change
siteCreation 6484 ms 6500 ms +16 ms ⚪ 0.0%
siteStartup 6577 ms 6571 ms 6 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

youknowriad and others added 5 commits June 29, 2026 13:14
…ents

Deletes the desktop src/lib/ai-session-placement re-export and points its importers at @studio/common/ai/sessions/placement directly; trims the app-bump-stats header to its behavioral notes and fixes a stale recordAgentSend comment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- run-manager routing: key the desktop binding by the unique runId (carried on both RunManagerOutput kinds) instead of sessionId, fixing two races where an interrupt-then-restart or a rejected concurrent start on the same session silenced a run's events.
- agent-stats: report weekly/monthly unique-stat bump failures to Sentry via the shared captureException instead of swallowing them (matches the app-wide convention); make getPlatformMetric module-private.
- bump-stats: lastBumpStatsProvider is now module-private with an accurate comment (the shared agent stats use appBumpStatsProvider, not this).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Add @studio/common/lib/app-config (read/save/lock/unlock/updateAppConfig), mirroring shared-config, as the single home for app.json I/O; placement and app-bump-stats now delegate to it instead of each hand-rolling the read/write/lock idiom.
- AiSessionSitePlacement is owned by @studio/common/ai/sessions/placement; the desktop storage-types now re-exports it (was a second, drift-prone definition).
- Move run-manager + agent-stats from ai/sessions/ up to ai/ — they're agent execution + telemetry, not session data, so ai/sessions/ now holds only session data/metadata.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Nothing imports the type from storage-types (consumers use the canonical @studio/common/ai/sessions/placement). storage-types still imports it for the UserData schema field, but it's an AI-session type that's merely persisted in app.json — not a storage type — so it shouldn't be re-exported from here.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@youknowriad
youknowriad merged commit 1e66332 into trunk Jun 30, 2026
11 checks passed
@youknowriad
youknowriad deleted the extract-agent-sessions branch June 30, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants