Repository navigation
fix(gateway): isolate the SessionsUpdated snapshot from live tracked state - #1012
Conversation
…state GetSessionListInternal copies the _sessions array but its elements are the same SessionInfo instances the map holds, which UpdateTrackedSession mutates in place under _sessionsLock. SessionsUpdated subscribers read the snapshot with no lock, so they can observe CurrentActivity/LastSeen/Status changing underneath them — a data race on shared mutable state. Hand out a defensive copy (SessionInfo.Clone via MemberwiseClone) so a delivered snapshot is isolated from later in-place mutation. Adds SessionSnapshotIsolationTests (red before the fix: a captured snapshot's CurrentActivity is overwritten by a later update for the same key; green after).
|
Codex review: needs real behavior proof before merge. Reviewed July 17, 2026, 11:57 AM ET / 15:57 UTC. Summary Reproducibility: yes. at source level: retaining live object references makes a captured snapshot change after the same tracked session is updated, and the focused regression test directly expresses that path. An independent live gateway reproduction was not established during this read-only review. Review metrics: 2 noteworthy metrics.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Retain the defensive snapshot copy and regression test, then add a redacted real-gateway terminal or log transcript showing a held session snapshot remains stable across a later session update before landing the fix. Do we have a high-confidence way to reproduce the issue? Yes at source level: retaining live object references makes a captured snapshot change after the same tracked session is updated, and the focused regression test directly expresses that path. An independent live gateway reproduction was not established during this read-only review. Is this the best way to solve the issue? Yes. Copying the session objects while constructing the lock-protected snapshot is the narrowest maintainable way to preserve the existing API while preventing later live-state mutation from leaking to consumers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9fb1960ec434. Label changesLabel changes:
Label justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
- SessionInfo.Clone() now deep-copies Presentation and Worktree objects so defensive snapshots cannot alias live tracked session state (#1012). - TrayDashboardSummary.SelectActiveSession prefers non-ended sessions as the fallback display item, preserving AbortedLastRun visibility. - Add snapshot isolation tests proving clone independence. - Add runtime behavior tests for ended/background/routing pipeline. - Add dashboard ended-session deprioritization tests. Co-authored-by: Copilot App <[email protected]> Copilot-Session: c311ae3b-8656-403f-91a6-5bfe2f91f5cd
* fix: render sessions with friendly presentation metadata * fix: harden legacy session presentation fallbacks * fix: use valid session wrapper tuple names * fix: preserve sparse session presentation updates * fix: preserve legacy main identity on sparse updates * fix: decouple session localization from test runtime * fix: align session presentation drift guard * fix: complete session title localization * fix(chat): retain session title tooltips * fix: deep-copy nested session state and harden ended-session surfaces - SessionInfo.Clone() now deep-copies Presentation and Worktree objects so defensive snapshots cannot alias live tracked session state (#1012). - TrayDashboardSummary.SelectActiveSession prefers non-ended sessions as the fallback display item, preserving AbortedLastRun visibility. - Add snapshot isolation tests proving clone independence. - Add runtime behavior tests for ended/background/routing pipeline. - Add dashboard ended-session deprioritization tests. Co-authored-by: Copilot App <[email protected]> Copilot-Session: c311ae3b-8656-403f-91a6-5bfe2f91f5cd --------- Co-authored-by: Scott Hanselman <[email protected]> Co-authored-by: Copilot App <[email protected]>
Related: #1010
What Problem This Solves
Fixes a data race where a
SessionInfosnapshot delivered toSessionsUpdatedsubscribers is not isolated from the gateway client's live tracked state. A subscriber reading a session's fields (e.g.CurrentActivity,LastSeen,Status) can observe them changing underneath it while the message-receive thread updates the same session — so a consumer (the tray's session views) can read shifting/inconsistent values, e.g. a session's activity from one update mixed with its timestamp from the next.Severity — being precise: this is a genuine unsynchronized read/write, but low-severity in practice. On x64 the individual field reads are atomic (
stringreferences andDateTime's backingulong), so the symptom is stale/mixed field values in the UI, not a torn read or crash. The fix is a cheap, standard hardening (hand out an immutable copy) rather than a fix for an observed corruption.Why This Change Was Made
GetSessionListInternalsnapshots the array but copies theSessionInforeferences straight out of the_sessionsmap (_sessions.Values.CopyTo(arr, 0)).UpdateTrackedSessionthen mutates those same objects in place under_sessionsLock, whileSessionsUpdatedsubscribers read the snapshot with no lock. The delivered snapshot is therefore a live alias of mutable state. The fix hands out a defensive copy —arr[i] = arr[i].Clone()(aSessionInfo.Clone()viaMemberwiseClone) — so a delivered snapshot is immutable with respect to later in-place updates.User Impact
Consumers of the sessions list (the tray's session views) now receive a stable, point-in-time snapshot rather than objects that can mutate mid-read. No user-facing behavior change beyond the removal of the race.
Evidence
Focused red→green regression test
SessionSnapshotIsolationTests.SessionSnapshot_IsNotAliasedToLiveTrackedState, plus the full Windows build+test matrix below.Change Type
Scope
winnodeValidation
Full CI-matrix mirror on a Windows host (win-x64, .NET 10.0.301), HEAD
e36992fbvs base9fb1960e. Every project built and all 8 test suites passed (exit 0), including the changedShared.Tests:(Note: this repo has two intermittent pre-existing flakes —
Connection.Tests.ConnectAndReconnect_EmitCompletedOperatorSpansandTray.UITests.ChatTimelineVirtualizationProofTests— neither of which fired in this run; both are on surfaces this Shared-only diff does not touch.)Real Behavior Proof
e36992fb(branchfix/session-snapshot-isolation)dotnet test tests/OpenClaw.Shared.Tests --filter "FullyQualifiedName~SessionSnapshotIsolation", run against base and HEAD. The test records a session with activity"compiling", captures its snapshot viaGetSessionList(), then issues a second update for the same key and asserts the earlier snapshot is unchanged.CurrentActivityflips to"running-tool"(the later update reaching back through the aliased object) → fails; on HEAD it stays"compiling"→ passes.N/A(non-UI shared-state logic; proof is the paired red/green test)Security Impact
NoNoNoNoNoCompatibility and Migration
YesNoNoReview History
Local review history (findings + dispositions per commit): https://gist.github.com/anagnorisis2peripeteia/30c18e621cc0d17539ed1362931f8fc6
Review Conversations