Skip to content

shared-node-store: fix updateTaskNode()'s success-path field clobber via shared-reference mutation - #2096

Merged
mstomar125 merged 1 commit into
mainfrom
issue-2090-updatetasknode-success-clobber
Aug 14, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-2090-updatetasknode-success-clobber

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

updateTaskNode()'s success handler read this.nodes.get(nodeId) at the moment a write's RPC resolved and unconditionally Object.assign'd ALL six type-specific fields (status, priority, dueDate, assignee, startedAt, completedAt) from that write's own response onto it. If a second updateTaskNode() call for the same node applied its own optimistic update to a DIFFERENT field while the first was still executing, the first write's response — which reflects the server's view as of its own request, frozen for every field it never touched — clobbered the second write's still-in-flight optimistic value for that other field.

This issue was filed as an unverified out-of-scope observation during #2089's review. I reproduced it concretely before writing any fix: write A changes priority, write B (submitted while A is executing) changes status. Once A's RPC resolves, the store's status reverted to A's stale pre-B value, discarding B's optimistic status change — even though B's own write hadn't been sent to the server yet.

Fix

Limited each write's applied patch to only the fields that write's own request actually asked to change (mirroring what localChanges already does for the optimistic apply earlier in the same method). A field a write didn't touch is left exactly as the store currently has it, however it got there. version is still always applied unconditionally: PersistenceCoordinator serializes real RPCs per node, so the version a response carries is always the latest authoritative one.

Tests

updatetasknode-success-clobber-regression.test.ts:

  • Primary test verified to fail against the pre-fix code (confirmed via git stash): write B's still-in-flight optimistic field survives write A's unrelated-field success response.
  • Second test checks the fix doesn't break normal eventual consistency once both writes' real persist attempts complete.

Full suite run cold (cache cleared) — all 210 files / 4656 tests green except one flaky, unrelated pre-existing test (architecture-benchmarks.test.ts's scaling-factor timing assertion) that reproduces independently of this change and passes in isolation and on repeat full runs — consistent with the same load-sensitive flakiness pattern seen in #2088's PR.

Closes #2090

🤖 Generated with Claude Code

…via shared-reference mutation

updateTaskNode()'s success handler read this.nodes.get(nodeId) at the
moment a write's RPC resolved and unconditionally Object.assign'd ALL
six type-specific fields (status, priority, dueDate, assignee,
startedAt, completedAt) from that write's own response onto it. If a
second updateTaskNode() call for the same node applied its own
optimistic update to a DIFFERENT field while the first was still
executing, the first write's response — which reflects the server's
view as of its own request, frozen for every field it never touched —
clobbered the second write's still-in-flight optimistic value for
that other field.

Confirmed with a repro before applying any fix: write A changes
priority, write B (submitted while A is executing) changes status;
once A's RPC resolves, the store's status reverted to A's stale
pre-B value, discarding B's optimistic status change, even though
B's own write hadn't been sent to the server yet.

Fixed by limiting each write's applied patch to only the fields that
write's own request actually asked to change (mirroring what
localChanges already does for the optimistic apply earlier in the
same method) — a field a write didn't touch is left exactly as the
store currently has it, however it got there. version is still always
applied unconditionally: PersistenceCoordinator serializes real RPCs
per node, so the version a response carries is always the latest
authoritative one.

Added updatetasknode-success-clobber-regression.test.ts: the primary
test is verified to fail against the pre-fix code (write B's
still-in-flight optimistic field survives write A's unrelated-field
success response); a second test checks the fix doesn't break normal
eventual consistency once both writes' real persist attempts complete.

Closes #2090

Co-Authored-By: Claude <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE

Independently re-verified:

  • Diff is exactly the intended fix: 2 files, 280/10 (production file + new test file), matching the PR description.
  • Confirmed the reproduction is genuine, not fabricated — the primary regression test fails against the pre-fix code and passes with the fix.
  • Ran the full test suite cold (cache cleared): 210 files / 4656 tests, all green except one flaky, unrelated pre-existing test (architecture-benchmarks.test.ts's timing-based scaling-factor assertion), which passes in isolation and on repeat runs — consistent with the same load-sensitive flakiness pattern already seen in shared-node-store: fix updateTaskNode()'s unconditional failure-rollback clobbering a queued write #2095's PR (a different flaky test each time: core-plugins.test.ts, model-store.test.ts, now this one — none touch shared-node-store.svelte.ts's task logic).
  • Spawned an independent adversarial review sub-agent: verdict APPROVE, no blocking issues. It independently re-confirmed the reproduction (via an isolated scratch worktree at HEAD~1), independently verified the "version always safe to apply unconditionally" claim by reading PersistenceCoordinator's serialization mechanics directly rather than trusting the code comment, checked the content-gating change against all existing updateTaskNode tests (279/279 pass), and confirmed scope discipline.
  • The review surfaced two non-blocking observations, both explicitly out of updateTaskNode()'s success path may clobber a concurrently-resolving write's fields via shared-reference mutation #2090's scope: (1) a same-field-both-writes transient clobber that is self-correcting and pre-existing (not a regression from this PR) — filed as a follow-up, updateTaskNode(): same-field concurrent writes can still transiently clobber each other (self-correcting, low severity) #2097; (2) confirmation that intentionally narrowing the success handler to no longer passively refresh unrelated fields from any successful response is the correct tradeoff, given the codebase already has a purpose-built channel (the database-sourced broadcast/resyncNodeFromServer/WatchNodes path) for cross-client field freshness — confirmed correct, no action needed.
  • Scope check: exactly 2 files changed, nothing under packages/agent, nlp-engine, skills, eval, playbook, ai-chat, and PR Classify node types by frontend integration, not core-list membership (closes #1998) #2013 untouched.

Merging.

@mstomar125
mstomar125 merged commit d38b9f6 into main Aug 14, 2026
@mstomar125
mstomar125 deleted the issue-2090-updatetasknode-success-clobber branch August 14, 2026 11:08
mstomar125 added a commit that referenced this pull request Aug 17, 2026
… clobber window (#2099)

* Close updateTaskNode() same-field concurrent-write clobber window

Field-scoping (from #2096) stops a write's response from clobbering a
concurrently-resolving write's DIFFERENT field, but a write's own
confirmed value for a field it DID change can still transiently
overwrite a newer optimistic write for that SAME field, since the
response reflects the server's state as of this write's own request
and predates the newer write.

Add a per-node, per-field write-sequence counter: updateTaskNode()
bumps it for each field at optimistic-apply time and captures the
number; when its RPC resolves, it only applies its confirmed value
for a field if the sequence hasn't moved on since (no newer same-
field write raced in). The newer write's own RPC still applies its
own confirmed value when it resolves, so the store converges either
way - this just closes the transient wrong-value window in between.

Co-Authored-By: Claude <[email protected]>

* Restore taskFieldWriteSeq on subtree-access-denied delete refusal

Address review finding on #2099: deleteNode()'s optimistic removal wipes
a node's per-field write-sequence map, but the subtree-access-denied
refusal path only restored versions/persistedNodeIds, not this map -
leaving a resurrected node's field sequences silently reset to zero.
Not currently reachable (updateTaskNode() no-ops on a missing node, and
the success handler already gates on the node still being present), but
it broke the restore symmetry with versions/persistedNodeIds and would
become a live gap under a future change to either guard. Capture and
restore the map the same way removedVersion is handled.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
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.

updateTaskNode()'s success path may clobber a concurrently-resolving write's fields via shared-reference mutation

1 participant