Skip to content

Persist explicit session IDs for reuse in subsequent commands.#7635

Merged
trangevi merged 2 commits intoAzure:mainfrom
therealjohn:fix-7602
Apr 10, 2026
Merged

Persist explicit session IDs for reuse in subsequent commands.#7635
trangevi merged 2 commits intoAzure:mainfrom
therealjohn:fix-7602

Conversation

@therealjohn
Copy link
Copy Markdown
Contributor

Fixes #7602

Before:
Does not save the session when explicitly passed, so monitor fails saying to invoke first.

model-test git:(main) 09:53 azd ai agent invoke --session-id "1234571b-e4d0-4811-ae6d-67faf2c94011" "hello"
Agent:        seattle-hotel-agent (remote)
Message:      "hello"
Session:      1234571b-e4d0-4811-ae6d-67faf2c94011
Conversation: conv_9da3f7bbaed1d2b700xhdNUWasJQgubLV6k7Qe6tTvcywHO60J

Trace ID: ceb08745-e9c0-40e0-a704-dccef21f6045
[seattle-hotel-agent] Hello! How can I assist you today? Are you looking for hotel recommendations in Seattle? If so, could you please provide your check-in and check-out dates? Also, do you have a budget range in mind?

model-test git:(main) 09:54 azd ai agent monitor
ERROR: VNext agents are currently enabled and require a session ID for log streaming.

Suggestion: Specify the session ID using --session, or run `azd ai agent invoke` first to create on

After:

model-test git:(main) 09:56 azd ai agent invoke --session-id "1234571b-e4d0-4811-ae6d-67faf2c94011" "hello"
Agent:        seattle-hotel-agent (remote)
Message:      "hello"
Session:      1234571b-e4d0-4811-ae6d-67faf2c94011
Conversation: conv_9da3f7bbaed1d2b700xhdNUWasJQgubLV6k7Qe6tTvcywHO60J

Trace ID: 0e0faceb-bd50-4183-8c1c-450df7527dce
[seattle-hotel-agent] Hello! How can I assist you with hotels in Seattle today? Are you looking for a place to stay, or do you have any specific dates in mind for your trip?

model-test git:(main) 10:01 azd ai agent monitor
Streaming session logs for seattle-hotel-agent (session: 1234571b-e4d0-4811-ae6d-67faf2c94011)...
event: log
data: {"timestamp":"2026-04-10T14:01:07.7270399+00:00","session_id":"1234571b-e4d0-4811-ae6d-67faf2c94011","session_state":"Running","agent":"seattle-hotel-agent","last_accessed":"2026-04-10T13:54:02.345+00:00"}
...

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses #7602 by ensuring that when a user explicitly provides a session (and conversation) ID, it is persisted to the local .foundry-agent.json context so subsequent commands (notably azd ai agent monitor) can reuse it without requiring the flag again.

Changes:

  • Persist explicit IDs in resolveStoredID() by saving them into the local agent context store.
  • Add unit tests intended to validate that explicit session/conversation IDs are persisted and reusable (including overwrite behavior).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
cli/azd/extensions/azure.ai.agents/internal/cmd/helpers.go Persists explicit IDs via saveContextValue() when resolveStoredID() receives an explicit value.
cli/azd/extensions/azure.ai.agents/internal/cmd/monitor_test.go Adds tests around persisting/reloading explicit session/conversation IDs and overwrite behavior.

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.

Fix correctly addresses the root cause - when an explicit session ID is passed, it now gets persisted so subsequent commands (like monitor) can find it. The saveContextValue call is consistent with how the same function already persists generated IDs (line 170-171).

Two notes:

  1. The new tests verify that the config persistence round-trip works (save + load), but they don't call resolveStoredID directly. If the saveContextValue call gets removed in a future refactor, these tests would still pass. Not blocking since mocking azdClient isn't trivial, but worth considering if there's a test helper for it.

  2. resolveConversationID (line 307 in helpers.go) has the same early-return-without-persist pattern for explicit conversation IDs. Not blocking since monitor only reads session IDs, but if you want explicit --conversation IDs to also be remembered across commands, that'd be the same one-line fix.

@trangevi trangevi merged commit cd1a0c2 into Azure:main Apr 10, 2026
19 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.

session-id isn't saved when manually passing during invoke

4 participants