[P1 data integrity] Concurrent agent record saves can orphan records from the secondary index #139
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
needs-review
quasar
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nsaspy/quasar-ui#139
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Finding
Agent records are written as two independent PouchDB operations:
updateIndex()performs an unguarded read-modify-write of one shared index document:putState()itself reads the current revision once and performs oneput(), with no conflict retry.If two agent-system records are saved concurrently:
listAgentRecords()cannot discover it, because listing trusts only the index.Deletes have the same race. Concurrent runs, tool calls, imports, UI edits, and recovery writes make this realistic. The caller may see an error even though the primary record was already committed.
Required fix
Prefer eliminating the fragile secondary index. Record IDs already share a sortable prefix, so list directly from the database:
If an index is still required for scale, treat it as rebuildable derived state and update it with a bounded compare-and-swap retry:
A repair/rebuild command should scan prefix records and recreate any derived index.
Primary-record mutation also needs explicit optimistic concurrency semantics. Do not silently overwrite a newer agent configuration after reading an old revision.
Acceptance criteria
listAgentRecords().