Skip to content

fix(sessions): refresh model from registry on session restore#502

Merged
tmustier merged 1 commit intomainfrom
fix/session-model-context-window
Mar 15, 2026
Merged

fix(sessions): refresh model from registry on session restore#502
tmustier merged 1 commit intomainfrom
fix/session-model-context-window

Conversation

@tmustier
Copy link
Copy Markdown
Owner

Problem

Restored sessions show stale model metadata (e.g. 200k context window for Opus 4.6 instead of 1M) because setModel() receives the model object as it was persisted — which may predate a dep bump that updated the registry.

Root cause

saveSession() serializes the full agent.state including the Model object with its contextWindow, pricing, etc. On restore, loadSession()setModel(sessionData.model) uses that stale snapshot directly.

Fix

refreshModelFromRegistry() re-resolves the persisted model via getModel(provider, id) from pi-ai's current registry before passing it to setModel(). If the model isn't in the registry (custom gateways), falls back to the persisted object.

This ensures existing sessions automatically pick up:

  • Updated context windows (Opus/Sonnet 4.6: 200k → 1M)
  • Updated pricing
  • Any other registry metadata changes

Testing

  • npm run build
  • npm run test:context ✅ (640/640)

Persisted sessions store the full model object including contextWindow.
After a dependency bump that updates registry metadata (e.g. Opus 4.6
going from 200k to 1M context), restored sessions would still show the
old value because setModel() received the stale persisted object.

Now re-resolve the model from getModel(provider, id) on restore, picking
up the latest contextWindow, pricing, and other metadata. Falls back to
the persisted model for custom-gateway models not in the registry.
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
pi-for-excel Ignored Ignored Mar 15, 2026 9:29pm

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 620bc4060a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@tmustier tmustier merged commit fb119d8 into main Mar 15, 2026
9 checks passed
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