[PR #1842] [CLOSED] feat(session): persisting agent for session #10080

Closed
opened 2026-02-16 18:14:40 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opencode/pull/1842
Author: @spoons-and-mirrors
Created: 8/11/2025
Status: Closed

Base: devHead: feat/persisting-agent-per-session


📝 Commits (5)

  • bd3670d feat(session): persisting agent for session
  • 816f514 Merge latest dev into feat/persisting-agent-per-session
  • 9aa0700 ci: sync
  • 457eb58 Merge branch 'dev' into feat/persisting-agent-per-session
  • b0ea89b Merge branch 'dev' into feat/persisting-agent-per-session

📊 Changes

7 files changed (+162 additions, -7 deletions)

View changed files

📝 packages/opencode/src/server/server.ts (+38 -1)
📝 packages/opencode/src/session/index.ts (+3 -1)
📝 packages/opencode/src/storage/storage.ts (+16 -0)
📝 packages/sdk/go/session.go (+32 -2)
📝 packages/sdk/go/session_test.go (+1 -1)
📝 packages/tui/internal/app/app.go (+30 -1)
📝 packages/tui/internal/tui/tui.go (+42 -1)

📄 Description

Summary

This PR implements per-session agent persistence, ensuring that the selected agent is remembered for each individual session and resolves issue #1812

Before

Previously, agent selection was a global setting. When a user switched agents in one session, that agent would remain active even when switching to other sessions. This meant that switching between sessions did not restore the agent that was last used in that specific context.

After

With this change, each session now stores its own agent. The behavior is as follows:

  • Agent Persistence: When you switch agents, the change is saved to the current session's metadata.
  • Session Switching: When you switch to a different session, the TUI automatically activates the agent that was last used in that session.
  • Session Creation: New sessions are created with the currently active agent.
  • Backward Compatibility: The changes are fully backward-compatible. A migration has been added to populate existing sessions with a default agent ("build").

This creates a more intuitive and seamless user experience, as the agent context is now tied directly to the session it's being used in.

Key Changes

Backend:

  • The session Info schema in packages/opencode/src/session/index.ts was extended with an optional agent field.
  • A PATCH /session/:id endpoint was added to packages/opencode/src/server/server.ts to handle session updates.
  • The POST /session endpoint now accepts an agent parameter on creation.
  • A migration was added in packages/opencode/src/storage/storage.ts to update existing session data.

Go SDK:

  • The Session struct in packages/sdk/go/session.go was updated to include the Agent field.
  • A Session.Update() method was added to call the new PATCH endpoint.
  • The Session.New() method was updated to accept an agent on creation.

TUI:

  • The SessionSelectedMsg and AgentSelectedMsg handlers in packages/tui/internal/tui/tui.go were updated to restore and persist the agent for the current session.
  • The cycleMode function in packages/tui/internal/app/app.go now makes a backend call to update the session when the agent is switched.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opencode/pull/1842 **Author:** [@spoons-and-mirrors](https://github.com/spoons-and-mirrors) **Created:** 8/11/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `feat/persisting-agent-per-session` --- ### 📝 Commits (5) - [`bd3670d`](https://github.com/anomalyco/opencode/commit/bd3670d14c58cbb3c071da6b91fb219b7d0e5414) feat(session): persisting agent for session - [`816f514`](https://github.com/anomalyco/opencode/commit/816f514f9dfdd3bb5861306bcf013692b09c5ae3) Merge latest dev into feat/persisting-agent-per-session - [`9aa0700`](https://github.com/anomalyco/opencode/commit/9aa0700dc42bf1c8040a6ca5edc6b4f294e6070c) ci: sync - [`457eb58`](https://github.com/anomalyco/opencode/commit/457eb584fffa60d59cbe3a2f0000d7d8121bccdc) Merge branch 'dev' into feat/persisting-agent-per-session - [`b0ea89b`](https://github.com/anomalyco/opencode/commit/b0ea89b9a7ea0235bd40245701e065a7f965de8c) Merge branch 'dev' into feat/persisting-agent-per-session ### 📊 Changes **7 files changed** (+162 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/opencode/src/server/server.ts` (+38 -1) 📝 `packages/opencode/src/session/index.ts` (+3 -1) 📝 `packages/opencode/src/storage/storage.ts` (+16 -0) 📝 `packages/sdk/go/session.go` (+32 -2) 📝 `packages/sdk/go/session_test.go` (+1 -1) 📝 `packages/tui/internal/app/app.go` (+30 -1) 📝 `packages/tui/internal/tui/tui.go` (+42 -1) </details> ### 📄 Description ## Summary This PR implements per-session agent persistence, ensuring that the selected agent is remembered for each individual session and resolves [issue #1812](https://github.com/sst/opencode/issues/1812#issue-3309596744) ### Before Previously, agent selection was a global setting. When a user switched agents in one session, that agent would remain active even when switching to other sessions. This meant that switching between sessions did not restore the agent that was last used in that specific context. ### After With this change, each session now stores its own agent. The behavior is as follows: - **Agent Persistence:** When you switch agents, the change is saved to the current session's metadata. - **Session Switching:** When you switch to a different session, the TUI automatically activates the agent that was last used in that session. - **Session Creation:** New sessions are created with the currently active agent. - **Backward Compatibility:** The changes are fully backward-compatible. A migration has been added to populate existing sessions with a default agent ("build"). This creates a more intuitive and seamless user experience, as the agent context is now tied directly to the session it's being used in. ## Key Changes **Backend:** - The session `Info` schema in `packages/opencode/src/session/index.ts` was extended with an optional `agent` field. - A `PATCH /session/:id` endpoint was added to `packages/opencode/src/server/server.ts` to handle session updates. - The `POST /session` endpoint now accepts an `agent` parameter on creation. - A migration was added in `packages/opencode/src/storage/storage.ts` to update existing session data. **Go SDK:** - The `Session` struct in `packages/sdk/go/session.go` was updated to include the `Agent` field. - A `Session.Update()` method was added to call the new `PATCH` endpoint. - The `Session.New()` method was updated to accept an agent on creation. **TUI:** - The `SessionSelectedMsg` and `AgentSelectedMsg` handlers in `packages/tui/internal/tui/tui.go` were updated to restore and persist the agent for the current session. - The `cycleMode` function in `packages/tui/internal/app/app.go` now makes a backend call to update the session when the agent is switched. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 18:14:40 -05:00
yindo closed this issue 2026-02-16 18:14:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10080