Skip to content

feat: Add save-session metaquery and ask to save on exit#484

Merged
droot merged 6 commits into
GoogleCloudPlatform:mainfrom
noahlwest:save-session
Aug 20, 2025
Merged

feat: Add save-session metaquery and ask to save on exit#484
droot merged 6 commits into
GoogleCloudPlatform:mainfrom
noahlwest:save-session

Conversation

@noahlwest
Copy link
Copy Markdown
Collaborator

Lets people start without a persisted session and switch at any time with save-session
Also, adds a check on ctrl+c exit whether user wants to save the current in-memory session.

demo (shows use of save-session, yes on exit save, and no on exit save): https://github.com/user-attachments/assets/dccb62e9-3f48-4b7d-b897-ac1ea6cb23ba

Comment thread pkg/agent/conversation.go Outdated
log.Info("Received input from channel", "userInput", userInput)
if userInput == io.EOF {
log.Info("Agent loop done, EOF received")
if _, ok := c.ChatMessageStore.(*sessions.InMemoryChatStore); ok {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is another way to do this where UI (terminal UI in this case) can present this option of saving or not at their end and then can send "save-session" meta query to the agent.

That approach decouples the UI from the core agent layer where agent isn't aware about user's interaction etc. Another advantage is that it unifies the "saving session" flow where there is only one mechanism (issuing meta query) to save session.

WDYT ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I added handling for this on the the terminal side. Manually tested stdin path by ./kubectl-ai "query" and tty path by echo "query" | ./kubectl-ai

Comment thread pkg/agent/conversation.go Outdated
}
foundSession, _ := manager.FindSessionByID(c.session.ID)
if foundSession != nil {
return "", fmt.Errorf("session with ID %s already exists", foundSession.ID)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if user is already in a session that being persisted and they say "save-session" just to ensure that session is being saved, will that result in error ? (probably, we should respond with a more friendly message saying.... session is already being saved or something....)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I removed the error, now it just returns that the session was saved. I don't know how important it is to distinguish to the user that the session is already being saved vs. newly being saved. If you think that's a big deal, I can change it to include an already being saved message.

Comment thread pkg/agent/conversation.go
if foundSession != nil {
return "", fmt.Errorf("session with ID %s already exists", foundSession.ID)
}
metadata := sessions.Metadata{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if the session was in-memory then this metadata should exists somewhere right ? because session was created sometime ago and we decided to save it just now. It is like migrating the session from in-memory to persistent-session so sort of attaching the persistence layer.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I updated this to use the existing CreatedAt, though the rest of the metadata is fine as is (LastAccessed, ModelID, ProviderID).

Copy link
Copy Markdown
Member

@droot droot left a comment

Choose a reason for hiding this comment

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

Thanks!

@droot droot merged commit 2872d19 into GoogleCloudPlatform:main Aug 20, 2025
6 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.

2 participants