Skip to content

fix: --new-session implies --new-conversation for agent invoke#7871

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-new-session-creation
Draft

fix: --new-session implies --new-conversation for agent invoke#7871
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-new-session-creation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

The backend derives sessions from conversation IDs, so --new-session alone reuses the existing conversation and gets back the same session ID. This makes --new-session ineffective unless paired with --new-conversation.

Changes

  • invoke.go: Pass newConversation || newSession as the forceNew parameter when resolving conversation IDs in both responsesRemote() and responsesLocal()
  • invoke_test.go: Add tests covering three flag combinations: --new-session alone (forces both), --new-conversation alone (session unchanged), and both together (redundant but valid)
// Before
convID, err := resolveConversationID(ctx, azdClient, name, a.flags.conversation, a.flags.newConversation, ...)

// After
convID, err := resolveConversationID(ctx, azdClient, name, a.flags.conversation, a.flags.newConversation || a.flags.newSession, ...)

When --new-session is used, also force a new conversation because the
backend derives sessions from conversation IDs. Without this, reusing an
existing conversation returns the same session ID, making --new-session
ineffective on its own.

Fixes #16222

Agent-Logs-Url: https://github.com/Azure/azure-dev/sessions/87d2f1e7-6e8d-4fa0-92e0-ed2fb1979ee2

Co-authored-by: therealjohn <1501196+therealjohn@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix new session creation with existing conversation ID fix: --new-session implies --new-conversation for agent invoke Apr 22, 2026
Copilot AI requested a review from therealjohn April 22, 2026 14:37
@trangevi
Copy link
Copy Markdown
Member

What do we think the user expectation actually is here? If a user is expecting that they'd keep the same conversation on a new session, this will break that expectation.

If I saw the conversation correctly, manually providing a session ID will not generate a new conversation ID, so should we be doing that? So a user would be required to pass both new flags to hit that path, instead of an implicit handling with no way to keep the conversation on a new session?

@microsoft-github-policy-service microsoft-github-policy-service Bot added the no-recent-activity identity issues with no activity label Apr 29, 2026
@microsoft-github-policy-service
Copy link
Copy Markdown
Contributor

Hi @@copilot. Thank you for your interest in helping to improve the Azure Developer CLI experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.

Copy link
Copy Markdown
Member

@jongio jongio left a comment

Choose a reason for hiding this comment

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

The fix addresses a real problem: the backend derives sessions from conversations, so --new-session alone reuses the existing conversation and gets back the same session. The || approach makes the flag work.

Two items to resolve before merging:

  1. @trangevi's design question is still open. This removes the ability to start a new session while keeping a conversation. If that's intentionally unsupported, the --new-session flag help text should say so. It currently reads "Force a new session (discard saved one)" with no mention of conversations. Note: explicit --conversation <id> still overrides the force-new logic, so power users have an escape hatch.

  2. The || a.flags.newSession logic is duplicated at two call sites (responsesLocal and responsesRemote). Consider resolving the implication once in Run():

    if a.flags.newSession {
        a.flags.newConversation = true
    }

    This keeps both paths in sync and prevents drift if a third path is added.

Also: this is a draft PR with a "no-recent-activity" label. The open design question from @trangevi should be addressed before marking ready.

convID, _ = resolveStoredID(
ctx, azdClient, agentKey, a.flags.conversation, a.flags.newConversation, "conversations", true,
ctx, azdClient, agentKey, a.flags.conversation,
a.flags.newConversation || a.flags.newSession, "conversations", true,
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.

This || is also in responsesRemote. Consider resolving the implication once in Run() so both code paths stay in sync.

@JeffreyCA JeffreyCA added the ext-agents azure.ai.agents extension label May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext-agents azure.ai.agents extension no-recent-activity identity issues with no activity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--new-session doesn't create a new session when an existing conversation ID is present

5 participants