[PR #6962] fix(session): backfill agent field when forking sessions with legacy messages #12180

Open
opened 2026-02-16 18:17:06 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6962

State: open
Merged: No


Fixes session forking for sessions created before December 14, 2025.

Problem

Commit 262d836dd (Dec 14, 2025) added a required agent field to Assistant messages as part of the "LLM cleanup" PR (#5462). This broke the ability to fork sessions containing messages created before this change, as those messages only have the deprecated mode field.

Solution

When forking a session, automatically backfill the agent field from mode for any assistant messages that lack it. This approach:

  • Maintains type safety (agent remains required in the schema)
  • Fixes the data at the point of migration (fork operation)
  • Is self-contained and doesn't spread complexity
  • Provides a clean path for future data migrations

Testing

Added comprehensive test coverage in test/session/fork.test.ts:

  • Forking empty sessions
  • Backfilling agent from mode for legacy messages
  • Preserving existing agent values
  • Forking with messageID parameter

All tests pass

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6962 **State:** open **Merged:** No --- Fixes session forking for sessions created before December 14, 2025. ## Problem Commit 262d836dd (Dec 14, 2025) added a required `agent` field to Assistant messages as part of the "LLM cleanup" PR (#5462). This broke the ability to fork sessions containing messages created before this change, as those messages only have the deprecated `mode` field. ## Solution When forking a session, automatically backfill the `agent` field from `mode` for any assistant messages that lack it. This approach: - Maintains type safety (agent remains required in the schema) - Fixes the data at the point of migration (fork operation) - Is self-contained and doesn't spread complexity - Provides a clean path for future data migrations ## Testing Added comprehensive test coverage in `test/session/fork.test.ts`: - Forking empty sessions - Backfilling agent from mode for legacy messages - Preserving existing agent values - Forking with messageID parameter All tests pass ✅
yindo added the pull-request label 2026-02-16 18:17:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12180