Skip to content

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

Closed

Description

@mstomar125

Found during

Adversarial review of #2089 (updateTaskNode's OCC direct-hydration skip-while-editing guard). Flagged as an out-of-scope observation, not verified with a repro/test yet — filing so it isn't lost, needs confirmation before anyone spends a fix cycle on it.

The suspected issue

updateTaskNode()'s success path (packages/desktop-app/src/lib/services/shared-node-store.svelte.ts, inside the PersistenceCoordinator.getInstance().persist(...) closure, a few lines above the OCC catch handler):

const updatedTaskNode = await backendAdapter.updateTaskNode(nodeId, currentVersion, update);

// Update local node with backend version
const localNode = this.nodes.get(nodeId);
if (localNode && updatedTaskNode) {
  localNode.version = updatedTaskNode.version;
  Object.assign(localNode, {
    status: updatedTaskNode.status,
    priority: updatedTaskNode.priority,
    dueDate: updatedTaskNode.dueDate,
    assignee: updatedTaskNode.assignee,
    startedAt: updatedTaskNode.startedAt,
    completedAt: updatedTaskNode.completedAt
  });
  if (updatedTaskNode.content !== undefined) {
    localNode.content = updatedTaskNode.content;
  }
  this.nodesSet(nodeId, localNode);
}

localNode is whatever object this.nodes.get(nodeId) returns at the moment this specific write's RPC resolves — not necessarily the object this write's own optimistic update installed. If a second updateTaskNode() call for the same node is submitted while this one is still in flight, that second call's own optimistic updatedNode = { ...existingNode, ...localChanges } (a different object) becomes the current this.nodes.get(nodeId) value. When the first call's RPC then resolves, Object.assign(localNode, {...}) mutates that other write's object in place, potentially overwriting fields the second write's own optimistic update just set (or, since Object.assign uses this write's own updatedTaskNode fields unconditionally rather than merging, silently reverting fields the second write changed but this write's response doesn't know about).

This is adjacent to, but distinct from, #2088 (which is about the failure-path unconditional rollback). This one is about the success path potentially mutating/overwriting a concurrently-resolving different write's result via shared object-reference mutation, rather than a clean read-modify-write against the current store state.

Needs before fixing

  1. A concrete repro/test: two updateTaskNode() calls for the same node in close succession, both eventually succeeding, with the second call's fields not reflected in the final store state (or reflected then silently reverted by the first call's later-resolving response).
  2. Confirm whether PersistenceCoordinator's queuing (used elsewhere in this file, e.g. via isQueued/clearQueued) already serializes same-node writes such that this can't actually happen in practice (i.e., this path might be dead/unreachable for the same-node-concurrent case) — if so, downgrade or close.

Scope note

Purely an observation from reading the code during #2089's review — not yet verified against actual PersistenceCoordinator queuing behavior for same-node writes, and no test currently demonstrates it. Do not assume it reproduces; confirm first.

Activity

  1. mstomar125 commented on Aug 14, 2026

    @mstomar125
    ContributorAuthor

    Verified and fixed in #2096.

    This was flagged as an unverified suspicion — I reproduced it concretely first, with a test written before any fix: write A changes priority on a task node; write B (submitted while A's RPC is still in flight) changes status on the same node and collapses into PersistenceCoordinator's queued slot. Once A's RPC resolves, its success handler's Object.assign(localNode, { status, priority, dueDate, assignee, startedAt, completedAt }) unconditionally applied ALL of A's response fields — including status, which A never touched — onto whatever this.nodes.get(nodeId) currently held (B's optimistic object at that point), reverting B's optimistic status change back to A's stale pre-B value before B's own write had even been sent to the server.

    Fixed by limiting each write's applied patch to only the fields that write's own request actually asked to change, mirroring the localChanges construction already used for the optimistic apply earlier in the same method. Confirmed the regression test fails against the pre-fix code and passes with the fix; added a second test confirming normal eventual consistency (both writes' fields correctly converge once both real persist attempts complete) is unaffected.

  2. added a commit that references this issue on Aug 14, 2026
    d38b9f6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions