Repository navigation
[dotnet-port-fixes] Fall back when a restored agent mode is no longer configured - #1346
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
API consistency review
Changed Go contractNo exported API changes. Observable behavior: a restored Upstream evidence reviewed
AssessmentThe Go change matches the .NET semantics: same trigger, same default fallback, same persistence, same notification clearing, and the same entry points. There is no new option and no gate, and the .NET change is also unconditional.
|
There was a problem hiding this comment.
🟡 Changes recommended
The test does not verify that the mode correction persists through serialization, so it could pass even if ensureConfiguredMode stopped saving the correction.
1 open issue
What changed in this PR
Updates agentmode to fall back to the configured default when a restored session references a mode that is no longer available, without changing the public API.
Changes:
- Validates stored modes during state loading and persists the fallback.
- Clears pending notifications that would announce a default-to-default switch.
- Adds regression coverage for fallback behavior and notification suppression.
| File | Description |
|---|---|
agent/harness/agentmode/agentmode.go |
Repairs and persists unconfigured stored modes during state loading. |
agent/harness/agentmode/agentmode_test.go |
Tests fallback after mode configuration changes and suppresses redundant notifications. |
Review effort: Balanced
| if mode := v2.Mode(session); mode != "draft" { | ||
| t.Fatalf("expected fallback to 'draft', got %q", mode) | ||
| } |

Summary
When a session restored from persisted state holds an
agentmodemode that the currentagentmode.Providerno longer configures, the provider now resets to the configured default mode and persists the correction. This applies toProvider.Mode, context-provider invocation, and themode_gettool, since all of them go throughloadSessionState. A pending mode-change notification that would announce a default-to-default switch is cleared. Previously Go returned the stale mode and injected its instructions.Ported .NET PRs
4bb5ffa7da18775bdd456d91c1313208e3363381. Inspected range: the first-parent commits in the prepared list, with in-depth review of8ab068b8(excluded) and60eae452(selected).AgentModeProvideris not marked experimental.Breaking Changes
No. This corrects behavior for restored sessions whose stored mode is no longer valid.
Tests and Examples
TestRestoredUnconfiguredModeFallsBackToDefaultinagent/harness/agentmode, adapted from the upstream test. It covers the fallback and the absence of a default-to-default notification.gofmtwas clean andgo test ./agent/harness/...passed. No E2E or benchmark suites were run.Notes
8ab068b8(reject duplicate tool approval request IDs, .NET: Reject duplicate tool approval request IDs agent-framework#9542). Go has the counterparttoolapprovalpackage, but the issue duplicate search returned an integrity-filtered result. I assumed conservatively that the approach is not desired. This is not a confirmed maintainer rejection.ee362838) is already satisfied in Go (workflow/internal/execution/edgerunner.go, around line 303).agentmoderestored or stale mode fallback) returned no results, both before editing and again before publication.agentmodepackage and its test were changed; the catalog and guide were left untouched.