Skip to content

Profile and settings write ownership across extension-host windows (compare-and-set now, write revision as the end state) #2488

Open

Description

@easonLiangWorldedtech

Why this issue exists

Twelve CodeRabbit findings across four PRs in the vps2 view-state stack were deferred for the same reason: the stack has no rule for who owns a write to a shared profile record or shared settings record when several extension-host windows (several ClineProvider instances) can write the same key, and whose write is authoritative for another window. They are not twelve independent bugs, so they are tracked here as one decision.

Covered findings (all deferred pending this decision, now unblocked by it):

Step 1 - the rule being implemented now (compare-and-set on values)

  • R1 Single writer unchanged. Every shared-store mode to profile write still goes through the one writer (sidebarProvider.setModeConfig into ProviderSettingsManager.setModeConfig). Compensation must not bypass it, and no second write path may be introduced.
  • R2 Snapshot fidelity. Before any mutation set that compensation may undo, record per key the target layer and that layer's pre-write value. A window-local map write must never borrow the manager's value as its snapshot. This is the same bug class as the round-2 fix on test(e2e): port view-state suite with reload and rehydration coverage (vps2 F6) #1565, where the rollback rewound a window-local mapping from the manager's snapshot.
  • R3 Compare-and-set restore. On compensation, re-read the same layer and restore a key only when the current value still equals the recorded pre-write value: === for strings, deepEqual from fast-deep-equal for records (already the repo's helper - src/core/config/ProviderSettingsManager.ts:3, src/core/webview/ClineProvider.ts:11, src/core/task-persistence/taskStoreConcurrency.ts:1, with the write-before-compare precedent at ProviderSettingsManager.ts:909-910). If the value differs, another window wrote after us: skip that key, keep the rest of the compensation, and log it. If the re-read throws, treat the state as unconfirmed and do not write blind.
  • R4 Failure semantics must not regress. A rejected or failed store write still drops the window-local pin, still posts state, and the error is logged rather than propagated past the section boundary.
  • R5 Known weakness, stated rather than hidden. Value equality cannot distinguish "wrote X" from "wrote X again". If another window rewrites the identical value, our compensation may clear that key; the outcome is still the same value, so this is acceptable for step 1. Removing the ambiguity is the job of step 2.

Step 2 - agreed end state (record-level write revision)

Give each shared record a monotonic write revision, and make compensation and fan-out compare revisions instead of values: a writer captures the revision it read, and a compensation or a forwarded fan-out applies only while the record's revision still matches. That makes "wrote the same value twice" distinguishable, removes the R5 weakness, and replaces per-key value comparisons with one integer check.

Open questions for maintainers before step 2 is scheduled:

  1. Where should the revision live - inside each profile record, or as a side map in the persisted store? Existing persisted state has no revision field, so a default must be defined for records written before the change.
  2. Should ProviderSettingsManager reject a stale write (a real compare-and-set at the datastore layer), or only expose the revision so callers decide? Rejecting is stronger but changes the manager contract for every caller.
  3. Does 4604437299 want the cross-instance lock to span provider re-entry after all, or should the section boundary stay as it is and rely on revisions? This issue assumes the current design (no lock across re-entry) stays.

Where step 1 is implemented

PRs #1560, #1562 and #1565 each carry their own commits for this rule and link back here. Per the stack's collision rule, no shared helper module is created for it - each PR inlines what it needs in files it already touches, so three lanes do not collide on identical new paths.

Activity

  1. easonLiangWorldedtech commented on Nov 18, 2026

    @easonLiangWorldedtech
    ContributorAuthor

    Addendum - a concrete instance of the undecided revision, from PR 1565.

    PR 1565 review comment 4610600217 (2026-11-18T07:46:31Z, Major, Data Integrity and Integration) is an instance of the write-revision half of this issue rather than of the compare-and-set half already treated as decided. The compensation added at head 27c49d0 in src/core/webview/ClineProvider.ts restores the pre-call profile record, or deletes the profile when the save was a create, when a sibling pin read or its overlay commit rejects after the save landed. A second window can complete a newer save of the same profile during that await, and this compensation then overwrites or deletes it. The finding asks for the record-level comparison this issue describes as its end state; it is deferred here rather than adopted, because adopting it would settle the open half inside a pull request thread.

    Acceptance criteria carried from that thread, so the issue holds the shape of the fix and not only the symptom:

    1. The compensation compares the stored record against the record the failing call wrote, not the record it read, inside the cross-instance critical section so no write can land between the comparison and the compensation.
    2. A stored record newer than what the failing call wrote is retained rather than restored or deleted.
    3. The comparison covers content, not identity alone - an id check alone cannot detect a same-record update - so normalized settings must be compared as well as the id.
    4. An interleaving regression covers both the restore leg, where a prior record exists, and the delete leg, where the call created the profile.

    Open choice, both halves stated, so a maintainer decides rather than a thread: when the comparison finds that the record moved under the failing call, should the operation (a) fail the save outright and report the conflict to the caller, or (b) retain the newer record and let the activation proceed against it. Option a preserves the invariant that a rejected operation leaves nothing half-applied; option b preserves the newer user intent at the cost of activating settings the failing call did not write. Neither is currently implemented anywhere in the extension package: the profile record has no comparison helper, while the mode-mapping path already has compare-before-restore at src/core/webview/ClineProvider.ts:3806 and a disk-authoritative compare-and-clear at :7368, which is the precedent a fix here should follow.
    Count, recorded after the fact because it is the argument for deciding rather than deferring. In one day this undecided revision has produced four review items across two pull requests. On 1565: the Persistence integrity pre-merge check on review 5951048605, which was answered by shipping the restore-or-delete compensation at head 27c49d0 and which now passes, since the fresh review 5952562574 at that head carries no failing persistence item; and today review comment 4610600217, a Major asking for the comparison itself, answered by reply 4610685521 with this issue named as the place the choice is recorded. On 1562, sourced from that lane's read with its filters named: both demands come from coderabbitai review 5951499613, submitted 2026-11-18T05:56:55Z at commit 7c7556b, a COMMENTED review whose 17,352-character body carries the Persistence Integrity block, and neither demand was ever posted as an inline thread - measured rather than inferred, because of 417 rows returned by the review-comments endpoint on 1562, zero contain the string allSettled case-insensitively and zero contain committed and failed. Item 1 of that block, replace Promise.all with Promise.allSettled in activateProviderProfileUnlocked and await every shared write before the catch runs, was answered by doing it: the activation fan-out now awaits all four write legs with allSettled at src/core/webview/ClineProvider.ts:4480, decides only after the awaits, keeps the first rejection as the error the caller sees, names the failed legs in the log, and leaves the catch rebuild byte-identical; the answer is published in the 1562 pull request body under Persistence integrity (error-mode review line) and in commit 5014920, not as a thread reply, because there was no thread to reply to. Item 4 of the same block - assert that the manager selection, the shared currentApiConfigName, the shared provider settings and the view state agree, and that no write is pending when the error is received - was declined in prose and now stands as the acceptance criterion of the follow-up unit with ownership assigned to this issue. That lane also reports 127 inline roots on 1562 with zero unanswered under its stated filter.

    Two of these four items, both on 1562, exist only inside a 17,352-character review body, where neither a thread count nor an unresolved-thread counter can see them; the 1562 unresolved counter reads clean at zero unanswered while those demands are open text. On 1565 the blocking item is likewise body and CI text rather than a thread. Reviewing by thread counting is therefore blind to most of what this undecided rule has cost in a single day.

    Four review items in one day, across two pull requests, all of them downstream of a rule nobody has made. The maintainers who own this issue are the only people who can spend the ten minutes that retires all four; another round of review on any of the affected pull requests costs more than that decision does.

  2. easonLiangWorldedtech commented on Nov 18, 2026

    @easonLiangWorldedtech
    ContributorAuthor

    Deferral criteria from PR #1562 round 11 (two lines left open)

    Both items below are recorded here as the criteria a fix has to meet. They are not accepted as "done" by #1562, and no commit on that pull request claims them.

    1. Pin compare-and-clear at the serialized clear (carried from #1562 finding …4723b, Major).

    • The condition that a view-local pin refers to a profile that is gone has to be evaluated at the clear, inside the same serialized step that performs it, not before the fan-out. A pin that is created or repointed between the check and the clear must not be erased.
    • Compare-and-clear semantics: the clear takes the pin it validated, identified by the pair (profile name, view id); if the live pin is not that pair at write time, the write is skipped and reported, not silently retried against the new value.
    • The rule must cover the same pin from both entry points that clear it today — the reset broadcast and the profile rename — with one shared implementation, so the two cannot drift apart.
    • Test required: a pin written between the check and the clear survives it; a pin that is genuinely absent is cleared. Both directions asserted against the shipped code path, not a mock of it.

    2. Store-level existence read: presence independent of per-entry usability (carried from #1562 finding …4765).

    • What fix(webview): invalidate live sibling view state on reset and settings import (vps2 F4) #1562 looked for and found: the settings store exposes getConfig / getProfile (which wrap "absent" and "unreadable" in one plain Error), listConfigHandles and listProfiles (which answer "is this id in the listing"), and validateProfiles (which reports per-entry usability). Nothing answers "does this record exist" without either reading its contents or running validation over it. A deleted-profile probe therefore currently has to combine a listing with a separate usability answer, and the wording on that path in fix(webview): invalidate live sibling view state on reset and settings import (vps2 F4) #1562 was corrected to say so.
    • The criterion: a single read that answers presence on its own, for a store that holds several kinds of record. It must say what it reports when the blob itself cannot be decoded — "absent" and "corrupt" cannot collapse into one answer, because the callers make opposite decisions: an absent record means drop the reference, an unreadable one means fail closed and keep it.
    • It has to cover the mode→profile mappings kept in the same store as the profiles, not just the profile records, because the deletion path resolves a mapping and then asks about the record it names; otherwise the two halves answer different questions.
    • One shared answer for "present" versus "usable", with a documented rule for a record that is present but fails validation, so no caller has to guess which question a boolean is answering.
    • Test required: absent, present-and-readable, present-but-undecodable, and a mapping that names an absent record — four states, each asserted separately.

    Until (1) has the compare-and-clear at the serialized clear and (2) has a presence read with a stated corrupt-blob answer, #1562 keeps Persistence Integrity as a live line on its own pull request rather than describing it as cleared.

    Reviewer engagement, recorded because it changes how each line should be read. The compare-and-clear rule (1) has been engaged with: on #1562 comment 4611540605 (2026-11-18T09:17:22Z, 125 s after the answer under root 4611384723) coderabbitai writes "I understand the decision to defer the compare-and-clear rule to #2488. I am not marking the finding as addressed while that race remains." So that deferral is acknowledged rather than unnoticed, and item (1) is written above as a spec for whoever picks it up, not as a request for agreement. The existence-read item (2) has not been read: nothing was posted under root 4611384765 after the answer that says what was looked for in the store and what was found there, so item (2) still has to argue its case from the beginning.

  3. easonLiangWorldedtech commented on Nov 18, 2026

    @easonLiangWorldedtech
    ContributorAuthor

    Evidence that the ownership rule is one question, from four reviewer-side observations

    Recorded here as evidence for items (1) and (2) above. Quoted text is the reviewer's own, with comment ids and timestamps, because the point is that the convergence was observed, not asserted by us.

    1. The reviewer relocated the answer from the call site to the serialized step. On #1562, comment 4612125530 (2026-11-18T10:05:41Z, replying under root 4612067427):

    @easonLiangWorldedtech Agreed. Pairing each clear with its post removes the wait for later clears once that view’s clear and the shared fallback have settled. One limit remains: persistedViewStateWriteQueue serializes durable writes. If B’s write stalls ahead of A’s, A’s clear will still wait. I am not marking the finding addressed until the change is made.

    So per-view pairing is accepted, and the reviewer is the one who names the remaining constraint: the durable write queue serializes these writes, so a view whose write is queued earlier still blocks the one behind it. Item (1) asks for the pin check inside that serialized step. This is the same observation arriving from the other side: the step, not the call site, is where the decision has to be made and validated.

    2. The reviewer asked for a property of the mechanism, not a patch. On #1562, comment 4612122369 (2026-11-18T10:05:26Z, under root 4612067411):

    @easonLiangWorldedtech Agreed. Attaching the rejection handler when the write starts closes the unhandled-rejection window. One edge case: the proposed result uses undefined for success, but a promise can also reject with undefined. A tagged result would preserve that rejection. A regression test should hold the viewStates write pending across an event-loop turn, reject the shared write, then check for an unhandled rejec

    A result type that distinguishes "succeeded" from "rejected with no value" is not a hunk at one site; it is what any caller of the serialized write needs. Item (2) is the same demand in the read direction: presence and usability cannot collapse into one answer, for the same reason a success and a valueless rejection cannot collapse into one sentinel.

    3. Three findings in one pass on #1562 reach the same rule from three directions (review 5954361618, 2026-11-18T10:00:56Z):

    • 4612067438 (Major, ClineProvider.ts:1246) — the step that records a committed view id records whatever the field holds after the await, so a registration still in flight gets marked as committed.
    • 4612067448 (Major, heavy lift, ClineProvider.ts:4229) — the compensation restores from a snapshot taken before the queue ran, so a mapping changed between the snapshot and the write is lost.
    • 4612067465 (Major, ClineProvider.ts:4732) — the identity that the rollback gates compare is taken from a listing rather than from the write that happened, so a record absent from the listing makes both checks decline.

    Each is a different call site. All three are the same statement: a value established before an await, or a listing consulted in place of the record, is being used to decide what to do after the await.

    4. The same pass on #1557 asked both halves as separate Majors. Review 5954370209 (2026-11-18T10:01:24Z) on that pull request:

    • #4612073263 (minor, ClineProvider.spec.ts:4222, 2026-11-18T10:01:23Z) — "Align the standalone rollback test title with its assertions, and cover the shared-proxy case"
    • #4612073281 (major, ClineProvider.ts:5559, 2026-11-18T10:01:23Z) — "Do not let an editor’s shared write preserve a failed sidebar pin"
    • #4612073291 (major, ClineProvider.ts:5574, 2026-11-18T10:01:23Z) — "Do not reuse the ownership check after awaiting a pin restore"

    Two pull requests, opened 40 seconds apart in review time, independently produced the await question and the listing-authority question.

    What this changes about the criteria above. Item (1) and item (2) are one mechanism read two ways — the write must own its decision at the serialized step, and a read must state which question it answers. The queue is that step. Writing the rule per call site would mean implementing it once per finding, which is what these two pull requests are currently doing and what the reviewer keeps meeting again at the next site. The evidence above is for stating the rule once, here, and having both pull requests adopt it.

    Scope boundary: this is evidence about the mechanism. It does not answer the scope question raised on either pull request, and no code was shipped against these findings — the last two rounds on #1562 were prose only, by maintainer-side ruling.


    ROUND 7 ADDITION, made by editing this comment rather than posting a new one so the thread count does not grow.

    The Persistence Integrity row has now landed on pull request 1557 as well. It arrived in review 5954886692, CHANGES_REQUESTED, submitted 2026-11-18T10:34:36Z against head c621114, in a review body of 13,218 characters. Quoted from that body with markdown emphasis and backticks removed and the en dash in the line range written as a hyphen, the row reads:

    Persistence Integrity:

    1. In API.applyConfiguration (src/extension/api.ts), acquire or reuse the field-write token for the setValues(values) call. Restore only keys that the failed call still owns. Add a ClineProvider entry point, or pass the token through, so the restore path can apply this check. Do not restore a key a newer write has taken over. 2. Or serialize setConfiguration with setValue and setValues calls for the same keys, so no write can interleave with the rollback window. 3. Add a regression test in src/extension/tests/api-set-configuration.spec.ts. Start setConfiguration with mode set and make saveConfig reject. While it is pending, land setValue("mode", "debug"). Assert that the stored mode stays debug after the call rejects. 4. In the setValues compensation loop (src/core/webview/ClineProvider.ts, L5559-5574), re-check ownership of each restorable key immediately before each awaited saveViewState call. Do not rely on a check made before an earlier awaited restore.

    Why this changes the argument rather than adding a line to it: it is the third site asking for one rule, and it arrives from two pull requests.

    • The sibling pull request 1562 carries the rule at 1246, 4229 and 4732.
    • Pull request 1557 carries it in threads 4612073291 and 4612073281, at ClineProvider.ts 5574 and 5559, which is item 4 of the row quoted above. Those two threads are deferred to this issue with the existing criteria and are not answered by a patch here.
    • The new part is item 1: the field-write token around the setValues call in API.applyConfiguration, with restore limited to keys the failed call still owns. That is a third location, in a different file, on a different pull request, asking for the same ownership rule at the same moment - immediately before a write whose failure triggers a compensation.

    An issue that carries three named sites across two pull requests is a different argument from an issue that carries one, and this comment is where that is recorded so the scope question can be decided from evidence rather than from recollection.

    The boundary is unchanged from the earlier sections of this comment: this is evidence about the mechanism. It does not answer the scope question, and nothing on this point has been shipped - round 7 on pull request 1557 changed tests and comments only, one file, 40 insertions and 34 deletions, pushed as c9babab at 10:43:38Z.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions