Skip to content

Preferences API: an optional expected revision on PUT, answered 409 when another write came first #3261

Done

Description

@vibewriter-hand

Problem

PUT /api/preferences lays the change over the document as it is now and saves it as revision + 1 (server/preferences.ts:138-191, main d5b8333). The writer never says which revision it read, so two writers that read the same document cannot tell that the other wrote first. For pins, which is one list sent whole, the later write replaces the earlier one: a pin one browser removed comes back when another browser (or a script, or a second page) that read the same revision saves its own list.

Reproduction against main, with the server's own store (PreferenceStore and handlePreferencesRequest):

PUT {settings:{}, pins:["pane-a","pane-b"]}              -> revision 1
writer 1 and writer 2 both GET revision 1
writer 1: PUT {settings:{}, pins:["pane-a"]}             -> revision 2, pins [pane-a]
writer 2: PUT {settings:{}, pins:["pane-a","pane-b","pane-c"]} -> 200, revision 3, pins [pane-a, pane-b, pane-c]

pane-b is pinned again, and neither writer is told. An expected_revision field in the body is accepted and ignored today (the body parser drops unknown keys), so a client cannot ask for this either.

Ovis's own client documents last write wins, setting by setting (src/lib/preferencesSync.ts:1-16), which is right for single settings. It is the whole-list values (pins, and muted_panes) where it loses a user's change. Our setup has several writers (browsers on two devices, and a small browser add-on of ours that pins agents through this API). We have seen a removed pin come back, and the revision move with no write from the device in front of us. We could not tell which writer it was each time, which is the point: nothing in the API lets a writer find out.

Proposal

An optional precondition on PUT, off unless the client sends it, so today's clients behave exactly as now:

  • PUT /api/preferences with "expected_revision": N (and, if useful, the state_id it read) saves only when the current revision is N (and the state id matches).
  • Otherwise it saves nothing and answers 409 with { error: { code: "revision_conflict" }, current: <the whole document> }, so the client can merge (for pins: apply its own add or remove to the current list) and send again.
  • If-Match with the revision as an ETag (and ETag on GET) is the HTTP-native spelling of the same thing, if you prefer headers.

preferencesSync.ts could then send expected_revision with pins and muted_panes changes and, on 409, replay only its own add/remove over current, while settings keep last write wins.

Where

Other

Where it exists today

HTTP conditional requests: If-Match / 412 Precondition Failed (RFC 9110, section 13.1.1) exist for exactly this lost-update case, and many REST APIs that keep a version number answer 409 Conflict to a stale one. We have not checked whether the Codex or Claude apps' own settings sync does this; their settings are not shared across browsers the way Ovis's are.

Workarounds and alternatives

  • A client can GET right before each PUT and send only pins. That narrows the window but cannot close it.
  • Per-pin operations (pins_added / pins_removed, like tab_labels_removed already does for labels) would fix pins without a precondition; nextTabLabels in shared/preferences.ts:95-102 is the pattern. That is a smaller change for pins alone, while a revision check covers every whole-list value.

Activity

  1. fivetaku commented on Nov 16, 2026

    @fivetaku
    Contributor

    Another case for this: a second program writing the same document. I run a session board next to Ovis and would like it to use Ovis's pins and muted panes instead of keeping its own copy, so that muting a pane on the phone also quiets it on the board. Without an expected revision the board and a browser tab overwrite each other's pins and muted_panes lists in the way the reproduction above shows. An optional expected_revision with 409 and the current document would let both sides retry once and keep each other's change. Old servers ignoring the field is fine for this.

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