Skip to content

tui: persist agent/model per session - #5264

Closed
ry2009 wants to merge 5 commits into
anomalyco:devfrom
ry2009:feat/session-model-agent-persist
Closed

ry2009 wants to merge 5 commits into
anomalyco:devfrom
ry2009:feat/session-model-agent-persist

Conversation

@ry2009

@ry2009 ry2009 commented Dec 9, 2025

Copy link
Copy Markdown
Contributor
  • Per-session agent/model prefs are persisted and re-applied on every switch (old and new sessions).
  • Prefs are saved when leaving a session and applied (or seeded) when entering the next session.
  • New pref store file session-pref.json under state dir; unit test for round-trip.

@ry2009

ry2009 commented Dec 9, 2025

Copy link
Copy Markdown
Contributor Author

I know this still may be in talks about approach/want of this feature but thought I would get ahead as I saw it as low hanging fruit

@rekram1-node

Copy link
Copy Markdown
Collaborator

/review

@rekram1-node

Copy link
Copy Markdown
Collaborator

Yea

Comment on lines +24 to +41
const pref = iife(() => {
const [store, setStore] = createStore<Record<string, SessionPref>>({})

readPrefs()
.then((data) => {
setStore(() => data)
})
.catch(() => {})

function snapshot() {
return JSON.parse(JSON.stringify(store)) as Record<string, SessionPref>
}

function setSession(sessionID: string, value: SessionPref) {
setStore(sessionID, value)
writePrefs(snapshot())
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay why are we doing all this complex logic? Why don't we just read the last message and set the agent / model to what was set on the last message?

This seems wayyy overcomplicated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This became a nuance in testing which lead to this, if user never sends a message (which I did not while switching multiple times) it fails -- also a little weird with how if multiple messages from different agents/models exist or which one is “current”? (slightly trivial problem though but the complex code goes around it totally)

I did not test this theory but this would require always scanning message history on every switch which for larger sessions or multiple large sessions (which I have seen in issues) could slow system down

Nonetheless I can attempt to simplify the pref module (drop snapshot(), use direct writes of the store object) without losing correctness if thats preffered?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we only grab last 100 messages for rendering, you should be able to just messages[messages.length-1]

then grab agent and model from that

@rekram1-node rekram1-node Dec 12, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if user hasnt sent message in a session use existing logic only change model/agent if the last message has a different one set and only run this on session switch

@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Feb 12, 2026
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.

2 participants