Thanks to visit codestin.com
Credit goes to github.com

Skip to content

.NET: Fix hosted agent crash after tool call by rooting session store under $HOME (#6231)#6714

Merged
rogerbarreto merged 2 commits into
microsoft:mainfrom
rogerbarreto:copilot-eager-rust-bear
Jun 24, 2026
Merged

.NET: Fix hosted agent crash after tool call by rooting session store under $HOME (#6231)#6714
rogerbarreto merged 2 commits into
microsoft:mainfrom
rogerbarreto:copilot-eager-rust-bear

Conversation

@rogerbarreto

Copy link
Copy Markdown
Member

Motivation & Context

After upgrading a .NET hosted Foundry agent to Microsoft.Agents.AI.Foundry.Hosting 1.8.0, the container starts but crashes right after the agent invokes a local AIFunctionFactory.Create(...) tool, with the platform log mount: /app: mount failed: No such file or directory..

Root cause: PR #5589 (first shipped in 1.8.0) made FileSystemAgentSessionStore the default session store in AddFoundryResponses. When hosted, CreateDefault() rooted the store at the absolute path /.checkpoints (the filesystem root). AgentFrameworkResponseHandler persists the session in a finally after the response stream, so the first tool-call turn writes under /.checkpoints. In a Foundry hosted container the root filesystem is read-only, so Directory.CreateDirectory("/.checkpoints") throws IOException: Read-only file system, which tears down the request and the container. The mount: /app message is the platform's downstream symptom. 1.3.0 had no file-backed default, which is why the upgrade introduced the failure.

Per container-image-spec.md section 5, the only writable and durable location in a hosted container is $HOME (default /home/session); the root filesystem is read-only and paths outside $HOME may be cleared between requests.

Description & Review Guide

  • What are the major changes?

    • FileSystemAgentSessionStore.CreateDefault() now roots the hosted store at {$HOME}/.checkpoints (env HOME, default /home/session) instead of /.checkpoints. Local (non-hosted) behavior is unchanged ({cwd}/.checkpoints).
    • Path selection is factored into an internal ResolveDefaultRootDirectory(isHosted, home, cwd) so it can be unit tested without the process-wide cached FoundryEnvironment.IsHosted.
    • Persistence failures stay fatal (the store complements Foundry storage; a silent loss would be worse), but SaveSessionAsync now wraps IOException/UnauthorizedAccessException in a clear, actionable IOException that names the path and the $HOME requirement, preserving the raw error as InnerException.
    • The public constant HostedCheckpointDirectory ("/.checkpoints") is replaced by SessionDataDirectoryEnvironmentVariable ("HOME") and DefaultHostedSessionDataDirectory ("/home/session") on the [Experimental] FileSystemAgentSessionStore type.
    • Added 6 unit tests (hosted/local path resolution, including an assertion that the hosted root is never the filesystem root, plus the clear fatal error).
    • Enabled the four ToolCallingHostedAgentTests (previously skipped pending end to end smoke), which exercise server-side tool invocation and multi-turn session persistence in a real hosted container.
  • What is the impact of these changes?

    • Hosted agents that use local function tools no longer crash after a tool call. Sessions now persist to the platform's durable $HOME volume so they survive across requests and restarts.
    • Non-hosted/local usage is unchanged.

Verification

  • Build: --warnaserror clean (0 warnings) on the changed projects.
  • Format: CI-parity dotnet format --verify-no-changes (Docker mcr.microsoft.com/dotnet/sdk:10.0) clean on all three changed projects.
  • Unit: all 21 FileSystemAgentSessionStoreTests pass.
  • Repro plus Docker: a standalone repro reproduces the original IOException: Read-only file system : '/.checkpoints' under a read-only root container, and confirms the fix succeeds when $HOME is writable and emits the clear fatal error when it is not.
  • Live: the four ToolCalling Foundry Hosted Agents integration tests pass end to end against a live Foundry project, including the multi-turn session-persistence test, confirming the platform mounts $HOME writable and the fix resolves the issue.

Related Issue

Fixes #6231

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change.

… under $HOME

FileSystemAgentSessionStore.CreateDefault rooted the hosted session store at the
filesystem root "/.checkpoints", which is read-only inside a Foundry hosted
container. After a local tool call the response handler persists the session, so
the write to "/.checkpoints" threw IOException and tore down the container, which
the platform surfaced as "mount: /app: mount failed: No such file or directory.".

Root the hosted store at $HOME (default /home/session), the only writable and
durable location per the container image spec. Persistence failures stay fatal but
are now wrapped in a clear, actionable IOException instead of the opaque raw error.

Add unit tests covering hosted and local path resolution plus the clear error, and
enable the ToolCalling Foundry Hosted Agents integration tests (verified live).

Fixes microsoft#6231
Copilot AI review requested due to automatic review settings June 24, 2026 16:34
@moonbox3 moonbox3 added the .NET Usage: [Issues, PRs], Target: .Net label Jun 24, 2026

@github-actions github-actions Bot left a comment

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.

Automated Code Review

Reviewers: 5 | Confidence: 90% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by rogerbarreto's agents

Copilot AI left a comment

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.

Pull request overview

This PR fixes a regression in the .NET Foundry hosting layer where hosted agents can crash after the first local tool call due to the default file-based session store attempting to write under the container filesystem root (/.checkpoints) on a read-only root filesystem. It updates the default hosted storage root to use the platform-provided writable/durable $HOME volume and adds/reenables test coverage to validate the behavior end-to-end.

Changes:

  • Update FileSystemAgentSessionStore.CreateDefault() to root hosted session persistence under $HOME/.checkpoints (fallback /home/session/.checkpoints) while keeping local behavior under {cwd}/.checkpoints.
  • Improve SaveSessionAsync failure diagnostics by wrapping IOException/UnauthorizedAccessException with an actionable message that explains the $HOME requirement (preserving the original exception as InnerException).
  • Add unit tests for hosted/local path resolution + failure message, and re-enable the hosted agent tool-calling integration tests.

Reviewed changes

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

File Description
dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FileSystemAgentSessionStore.cs Changes hosted default session-store root to $HOME and improves fatal error messaging on non-writable roots.
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/FileSystemAgentSessionStoreTests.cs Adds unit coverage for hosted/local root resolution and for clear fatal IO error messaging on non-writable roots.
dotnet/tests/Foundry.Hosting.IntegrationTests/ToolCallingHostedAgentTests.cs Re-enables hosted tool-calling integration tests to validate multi-turn server-side tool invocation and persistence.

Comment thread dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/FileSystemAgentSessionStore.cs Outdated
Address review feedback on microsoft#6714: a misconfigured HOME pointing at a filesystem
root (e.g. "/") resolved back to "/.checkpoints" and would reintroduce the original
read-only-root crash. CreateDefault now falls back to the default session-data
directory (/home/session) when HOME is missing, blank, a filesystem root, or an
unnormalizable path. Adds a unit test locking in the "never the filesystem root"
behavior for a hosted HOME of "/".

Related microsoft#6231
@rogerbarreto rogerbarreto added this pull request to the merge queue Jun 24, 2026
Merged via the queue into microsoft:main with commit 0283fd0 Jun 24, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

5 participants