Skip to content

shared-node-store: fix updateTaskNode()'s unconditional failure-rollback clobbering a queued write - #2095

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2088-updatetasknode-rollback-clobber
Aug 14, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2088-updatetasknode-rollback-clobber

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

updateTaskNode()'s catch handler unconditionally called this.nodesSet(nodeId, existingNode) on any write failure (OCC or not), where existingNode is the snapshot captured before this specific call's own optimistic update. If a second updateTaskNode() call for the same node landed and applied its own optimistic update while the first was still executing, and the first then failed, this line overwrote the store with the first write's stale pre-edit snapshot — discarding the second write's still-queued optimistic value.

updateNode()'s sibling catch handler doesn't have this problem: it calls rollbackUpdate(), which only rewinds bookkeeping (the pending-update list, the version counter) and re-notifies with whatever the store currently holds — it never calls nodesSet() and never touches node content.

Fix

updateTaskNode()'s catch handler now notifies subscribers with whatever the store currently holds instead of force-reverting to existingNode. updateTaskNode() doesn't track a NodeUpdate/pendingUpdates entry the way updateNode() does, so rollbackUpdate() itself isn't directly reusable here — the fix mirrors its no-op-on-content behavior directly.

Tests

  • New updatetasknode-rollback-clobber-regression.test.ts: verified to fail against the pre-fix code.
    • A queued second write's still-in-flight optimistic value survives the first write's non-OCC failure (uses a real, never-resolving mock for the promoted second write's own RPC, so the assertion can't be masked by that write later succeeding on its own).
    • An isolated non-OCC failure (nothing queued behind it) leaves the optimistic edit in place, matching updateNode()'s design, instead of reverting it.
  • Updated shared-node-store-skip-while-editing.test.ts's updateTaskNode OCC direct-hydration guard (#2072) suite:

Full suite run cold (cache cleared) — all files green except two flaky, unrelated pre-existing tests (core-plugins.test.ts viewer-resolution timeout, model-store.test.ts fake-timer loop) that reproduce independently of this change and pass in isolation and on repeat full runs.

Closes #2088

🤖 Generated with Claude Code

…ack clobbering a queued write

updateTaskNode()'s catch handler unconditionally called
this.nodesSet(nodeId, existingNode) on ANY write failure (OCC or
not), where existingNode is the snapshot captured before THIS call's
own optimistic update. If a second updateTaskNode() call for the
same node landed and applied its own optimistic update while the
first was still executing, and the first then failed, this line
overwrote the store with the first write's stale pre-edit snapshot —
discarding the second write's optimistic value (or, for the OCC
direct-hydration branch, defeating the hasPending-aware skip-while-
editing guard that runs immediately afterward, since the clobber had
already happened before that guard's decision even executed).

updateNode()'s sibling catch handler doesn't have this problem: it
calls rollbackUpdate(), which only rewinds bookkeeping (the pending-
update list, the version counter) and re-notifies with whatever the
store CURRENTLY holds — it never calls nodesSet() and never touches
node content.

Fixed updateTaskNode()'s catch handler to match: instead of force-
reverting to existingNode, it now notifies subscribers with whatever
the store currently holds. updateTaskNode() doesn't track a
NodeUpdate/pendingUpdates entry the way updateNode() does, so
rollbackUpdate() itself isn't directly reusable here; the fix mirrors
its no-op-on-content behavior directly.

Added updatetasknode-rollback-clobber-regression.test.ts, verified to
fail against the pre-fix code: a queued second write's still-in-flight
optimistic value survives the first write's non-OCC failure, and an
isolated non-OCC failure leaves the optimistic edit in place (matching
updateNode()'s design) instead of reverting it.

Also fixed shared-node-store-skip-while-editing.test.ts's
updateTaskNode OCC direct-hydration guard (#2072) suite: one test's
assertions/comment described the old unconditional-revert behavior as
expected; updated to assert the optimistic edit is preserved. Filled
in the it.todo() that PR left as an explicit placeholder for this fix,
with a real regression test proving a queued write's value survives
both the failure-path handling and the direct-hydration guard's own
skip decision.

Closes #2088

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

The isolated-failure test's title and only comment claimed it verified
"surfaces the generic write-failure notification" for a non-OCC
failure, but its assertions only checked the test-only error-tracking
array and the preserved optimistic value — it never asserted on
conflictNotifications. updateTaskNode() actually has no code path that
raises a user-facing write-failure notification for a non-OCC failure
at all (a separate, pre-existing gap, out of scope here). Retitled and
added a comment clarifying what the test actually verifies, so it
doesn't overpromise coverage it doesn't have.

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

Copy link
Copy Markdown
Contributor Author

APPROVE

Independently re-verified:

  • Diff is exactly the intended fix: the unconditional nodesSet(nodeId, existingNode) + notifySubscribers(nodeId, existingNode, source) in updateTaskNode()'s catch handler is replaced with a read of current store state, notified only if present — mirrors updateNode()'s rollbackUpdate() (never touches node content on failure).
  • Confirmed updateTaskNode() has no versions/pendingUpdates bookkeeping of its own (grepped), so there's no stranded state from dropping the forced revert.
  • Ran the full test suite cold (cache cleared): 209 files / 4654 tests, all green.
  • New regression test verified to FAIL against the pre-fix code (confirmed via git stash of the production-file change) and PASS with the fix, for both: (a) a queued second write's still-in-flight optimistic value surviving the first write's non-OCC failure, and (b) an isolated non-OCC failure leaving the optimistic edit in place rather than reverting it.
  • Fixed a pre-existing test in shared-node-store-skip-while-editing.test.ts whose assertions documented the old buggy behavior as expected, and filled in the it.todo() PR shared-node-store: apply skip-while-editing guard to updateTaskNode's OCC direct-hydration path #2089 explicitly left as a placeholder for this fix — both verified to fail pre-fix, pass post-fix.
  • Spawned an independent adversarial review sub-agent: verdict APPROVE WITH NITS. Addressed the one actionable nit (a test title/comment that overclaimed asserting a user-facing notification it didn't actually check — retitled and clarified, since that gap is real but tracked separately as updateTaskNode() surfaces zero user-visible notification on a non-OCC write failure #2092, not this PR's scope). The other note (an interaction with the recent nodeGeneration/reconnect-staleness stamping) was independently confirmed benign — the node's generation is already stamped fresh by the initial optimistic apply at the top of updateTaskNode(), before persist() even starts, so removing the catch handler's re-stamp is a no-op in the ordinary case and an incidental improvement in the reconnect-race case.
  • Scope check: exactly 3 files changed (production file + 2 test files), 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.

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 unconditional rollback-on-failure can clobber a later queued write's result

1 participant