Skip to content

Session management commands and file command improvements#7574

Open
therealjohn wants to merge 16 commits intoAzure:mainfrom
therealjohn:session-crud
Open

Session management commands and file command improvements#7574
therealjohn wants to merge 16 commits intoAzure:mainfrom
therealjohn:session-crud

Conversation

@therealjohn
Copy link
Copy Markdown
Contributor

@therealjohn therealjohn commented Apr 8, 2026

Adds azd ai agent sessions CRUD commands for managing hosted agent sessions, improves error handling, and enhances file command UX.

Session management (sessions)

  • sessions create — Create a new session for a hosted agent
  • sessions show — Get session details; gracefully handles 404 with a user-friendly message instead of dumping raw HTTP response
  • sessions list — List sessions for an agent
  • sessions delete — Delete a session; correctly handles 200 OK responses (server returns 200 with the deleted resource, not 204)

File command improvements

  • files remove → files delete — Renamed for consistency with sessions delete and the SDK; remove kept as a backward-compatible alias
  • Positional argument support — All file subcommands (upload, download, delete, mkdir) now accept the path as a positional argument: azd ai agent files upload ./input.csv # positional (new)
    azd ai agent files upload --file ./input.csv # flag (still works)

Flag consistency

  • --session → --session-id — Renamed across files and monitor commands for consistency between commands (shorthand -s preserved)

Bug fixes

  • DeleteSession now accepts both 200 OK and 204 No Content — the service returns 200 with the deleted session body
  • sessions show intercepts 404 session_not_found errors and returns a clean validation error with a suggestion, instead of rendering the full HTTP error dump
  • Fixed default target path for file downloads to be relative to home

Tests

  • Added operations_test.go with API-level tests for DeleteSession (200/204/500) and GetSession (404)
  • Added error classification tests in session_test.go (404 → LocalError, 500 → ServiceError)
  • Updated files_test.go and monitor_test.go for renamed flag and command

Fixes #7429 Fixes #7519

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds new CLI surface and API client support for hosted agent session lifecycle management, while refining file command ergonomics and harmonizing session flag naming.

Changes:

  • Introduces sessions CLI commands (create/show/list/delete) and corresponding agent API operations/models.
  • Improves files UX: removedelete (alias preserved) and adds positional path support; adjusts upload default remote path behavior.
  • Renames --session to --session-id across relevant commands and updates tests.

Reviewed changes

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

Show a summary per file
File Description
cli/azd/extensions/azure.ai.agents/internal/pkg/agents/agent_api/operations_test.go Adds API-level tests for new session operations behavior (notably DeleteSession status code handling).
cli/azd/extensions/azure.ai.agents/internal/pkg/agents/agent_api/operations.go Adds session lifecycle HTTP operations; updates upload/download file content endpoint path.
cli/azd/extensions/azure.ai.agents/internal/pkg/agents/agent_api/models.go Adds new session lifecycle models and enums used by operations/CLI output.
cli/azd/extensions/azure.ai.agents/internal/exterrors/codes.go Adds new error codes and operation names for session flows.
cli/azd/extensions/azure.ai.agents/internal/cmd/session_test.go Adds command structure, formatting, and error classification tests for sessions.
cli/azd/extensions/azure.ai.agents/internal/cmd/session.go Implements sessions cobra commands and formatting helpers.
cli/azd/extensions/azure.ai.agents/internal/cmd/root.go Registers the new sessions command on the root command.
cli/azd/extensions/azure.ai.agents/internal/cmd/monitor_test.go Updates tests for renamed --session-id flag.
cli/azd/extensions/azure.ai.agents/internal/cmd/monitor.go Renames monitor flag from --session to --session-id.
cli/azd/extensions/azure.ai.agents/internal/cmd/files_test.go Updates tests for delete subcommand and renamed --session-id flag.
cli/azd/extensions/azure.ai.agents/internal/cmd/files.go Implements delete (alias remove), positional args for file commands, and updates session flag naming.

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.

CI is red - golangci-lint fails on operations_test.go. Plus a stale flag reference in help text.

Issues to address:

  • operations_test.go:20 - unused body field on fakeTransport + gofmt misalignment on line 27 (both fail CI)
  • files.go:79 - parent files command help still says --session instead of --session-id
  • operations_test.go:88 - context.Background() should be t.Context() (rest of file uses it)

@therealjohn therealjohn requested a review from jongio April 8, 2026 20:37
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 session CRUD implementation is clean and follows existing patterns well. All previous feedback items have been addressed and CI is green. Two minor notes below - neither is blocking.

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.

Issues to address:

  • session.go:421 - sessions delete doesn't handle 404 like sessions show does

Co-authored-by: Jon Gallant <2163001+jongio@users.noreply.github.com>
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.

Two items - one CI-blocking, one coverage gap.

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.

Session CRUD implementation follows the files command patterns well and tests are thorough.

A few non-blocking notes:

  1. printSessionTable will show blank Version: (type: ) if the server returns empty VersionIndicator fields. Could check for empty strings and show "-" to match how formatUnixTimestamp handles zero values.

  2. persistSessionID silently drops all errors. Fine as best-effort, but a debug log would help diagnose cases where session auto-detection doesn't work on subsequent commands.

  3. The copilot bot's comments about errors.AsType not compiling are wrong - it's valid Go 1.26 per this repo's AGENTS.md.

Copy link
Copy Markdown
Contributor

@wbreza wbreza left a comment

Choose a reason for hiding this comment

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

Code Review — PR #7574

Session management commands and file command improvements by @therealjohn

Summary

Well-structured session CRUD implementation following established extension patterns. Clean error handling with proper LocalError/ServiceError classification, correct 200/204 handling for delete, and complete --session--session-id rename. One minor naming inconsistency below — no blocking issues.

🟡 Medium (1 finding)

  1. filesFlags.session field name doesn't match --session-id flag — The struct field is session string but the flag is --session-id. Sessions commands use matching field names. Minor inconsistency — no functional impact.

✅ What Looks Good

  • Session CRUD with proper error codes (CodeSessionNotFound, CodeSessionCreateFailed, etc.)
  • 404 → friendly LocalError with suggestion, 500 → ServiceError — correct extension pattern
  • Delete handles both 200 OK and 204 No Content correctly
  • --session--session-id rename complete across all commands
  • Positional args with backward-compatible flag fallback for file commands
  • errors.AsType used correctly for error classification
  • Comprehensive test coverage: API-level (200/204/500), error classification, command structure
  • Prior review items all resolved
Priority Count
Medium 1
Total 1

Overall Assessment: Comment — clean implementation, no blocking issues.

Review performed with GitHub Copilot CLI

}

func newSessionCommand() *cobra.Command {
cmd := &cobra.Command{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@trangevi please review the sessions feature.

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.

Align --session flag on monitor to match --session-id CRUD for vnext hosted agent sessions

5 participants