Follow-up to #38.
Problem #
PATCH /api/automations/:rkey writes the record to the owner's PDS with active = body.active ?? auto.active, where auto was read at the start of the request. The database update right after it is a compare-and-set on active: if a background worker turned the automation off in between (rate-limit breach, session loss), the CAS re-reads the row and keeps the disable, and the database gets the resulting nextActive.
So when a worker disables the automation during a PATCH that doesn't touch active, the PDS record says active: true while the index says active: false. The two copies of the automation now disagree, and a later sync or rewrite from the PDS can turn the disabled automation back on.
Evidence #
app/routes/api/automations/[rkey].ts:169:const active = body.active ?? auto.active;app/routes/api/automations/[rkey].ts:236:activeis whatputRecordsends.app/routes/api/automations/[rkey].ts:257-294: the compare-and-set and its retry, which computenextActive.app/routes/api/automations/[rkey].ts:317:nextActiveis what the response and the database use.
Expected #
The PDS record and the database row end a PATCH with the same active value: the one the compare-and-set settled on.
Acceptance criteria #
Out of scope #
Reconciling PDS and index copies that already disagree.
Queued: the loop will work on this version of the issue.
loop:queued cid=bafyreicnfedw6jq2gbepetwar62jlsb2kq72mt6c45dwzpni6fa2tj3hxm