Skip to content

[dotnet-port-fixes] fix: preserve null session state values - #1267

Merged
Quim Muntal (qmuntal) merged 1 commit into
mainfrom
dotnet-port-fix-session-null-roundtrip-7b9cb9f102718852
Oct 8, 2026
Merged

Quim Muntal (qmuntal) merged 1 commit into
mainfrom
dotnet-port-fix-session-null-roundtrip-7b9cb9f102718852

Conversation

@microsoft-agent-framework-for-go

Copy link
Copy Markdown
Contributor

Summary

Preserve explicit JSON null session values during Go Session round trips. The internal unmarshal path now decodes state entries as raw JSON before wrapping them, so a null entry remains a readable state key and can be overwritten instead of becoming a nil internal pointer.

Ported .NET PRs

Ported the fix intent from .NET commit d0ccaa62761ec36c59c139940797978623fb630a, verified as present at pinned upstream SHA 40763bed1a5e94a1698ba9ebf009e5622eb099aa: source change and regression tests. The complete upstream change was classified as fix-only: no exported API, option, default, or capability change.

The other deeply inspected candidate, .NET commit 763887452f371d8d03a67993ec7adcd95a0e18c2, was excluded because it targets .NET AI-context decorators owning IAsyncEnumerator instances; the Go counterpart uses iterator-based context-provider middleware and has no established corresponding enumerator-owning path.

Focused duplicate searches were repeated before publication with these exact queries: issue repo:microsoft/agent-framework-go session null state JSON roundtrip and PR repo:microsoft/agent-framework-go Session UnmarshalJSON stateValue null. Both returned no results.

Breaking Changes

No. This preserves existing public APIs and corrects deserialization of an existing serialized value.

Tests and Examples

gofmt -w agent/session.go agent/session_test.go

go test ./agent

git diff --check

Added TestSession_UnmarshalJSON_NullStateValueRoundtripsAndCanBeOverwritten, covering public Set → json.Marshal → json.Unmarshal behavior and subsequent overwrite.

Notes

The fix changes only agent/session.go and agent/session_test.go. Publication is queued from branch dotnet-port-fix-session-null-roundtrip; no binaries or build artifacts are included.

Warning

Firewall blocked 3 domains

The following domains were blocked by the firewall during workflow execution:

  • proxy.golang.org
  • storage.googleapis.com
  • sum.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"
    - "storage.googleapis.com"
    - "sum.golang.org"

See Network Configuration for more information.

Generated by .NET to Go Fixes and Test Porting Agent · copilot · gpt56 · 3.45 AIC · ⌖ 0.82 AIC · ⊞ 24.8K · ◷

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added area:agent Changes files in the agent area size:medium At most 100 changed lines across at most 5 files kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

API consistency review

Result Scope
aligned user-visible behavior

Changed Go contract

agent.Session.UnmarshalJSON (in agent/session.go) now decodes each session-state entry as json.RawMessage before wrapping it in *stateValue, instead of unmarshaling directly into map[string]*stateValue. No exported type, method signature, or field changed; Session.Get/Session.Set/MarshalJSON are unaffected.

Upstream evidence reviewed

Implementation Source Contract checked
.NET AgentSessionStateBagValueJsonConverter.cs (fix commit d0ccaa6) HandleNull => true ensures the converter's Read runs for a JSON null state entry instead of the deserializer short-circuiting to a null AgentSessionStateBagValue
.NET AgentSessionStateBagTests.cs SerializeDeserialize_WithNullValue_Roundtrips / _CanOverwrite assert the null key survives roundtrip and remains settable/overwritable afterward

Assessment

Before this fix, Go's map[string]*stateValue unmarshaled a JSON null entry as a nil *stateValue pointer (confirmed by reproduction: Session.Get on such a key panicked via nil-pointer dereference in stateValue.readInto), diverging from .NET's HandleNull-gated converter, which always constructs a valid AgentSessionStateBagValue wrapping a JSON null element. The PR's raw-message decoding path ensures every state entry — including explicit nulls — becomes a valid, non-nil *stateValue{raw: "null"}, matching .NET's roundtrip-and-overwrite semantics verified above. This is a pure bug fix with no public API or default change (verified by go build ./... and go test ./agent/... passing, plus manual reproduction of the pre-fix panic).

Warning

Firewall blocked 3 domains

The following domains were blocked by the firewall during workflow execution:

  • proxy.golang.org
  • storage.googleapis.com
  • sum.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"
    - "storage.googleapis.com"
    - "sum.golang.org"

See Network Configuration for more information.

Generated by Go API Consistency Review Agent for #1267 · copilot · auto · 62.1 AIC · ⌖ 6.33 AIC · ⊞ 13.9K · ◷

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Oct 8, 2026
@qmuntal
Quim Muntal (qmuntal) marked this pull request as ready for review October 8, 2026 04:21
@qmuntal
Quim Muntal (qmuntal) requested a review from a team as a code owner October 8, 2026 04:21
Copilot AI balanced review requested due to automatic review settings October 8, 2026 04:21

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.

🟢 Approval recommended

The focused implementation matches the intended behavior and includes adequate regression coverage.

0 open findings

What changed in this PR

Preserves explicit JSON null values in session state across serialization round trips.

Changes:

  • Decode state entries as raw JSON before wrapping them.
  • Add regression coverage for reading and overwriting null values.
File Description
agent/​session.go Preserves null state entries as non-nil wrappers.
agent/​session_test.go Tests null round trips and replacement.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@qmuntal
Quim Muntal (qmuntal) added this pull request to the merge queue Oct 8, 2026
Merged via the queue into main with commit 8c15f10 Oct 8, 2026
35 checks passed
@qmuntal
Quim Muntal (qmuntal) deleted the dotnet-port-fix-session-null-roundtrip-7b9cb9f102718852 branch October 8, 2026 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Changes files in the agent area kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure parity-approved Go API consistency review found no parity issues size:medium At most 100 changed lines across at most 5 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants