Skip to content

feat(planning): save conflict detection (409) for plans, empires and cx, and per-key preference merge for multi-tab planning - #77

Merged
jplacht merged 3 commits into
mainfrom
feat/multi-tab-safety
Oct 3, 2026
Merged

jplacht merged 3 commits into
mainfrom
feat/multi-tab-safety

Conversation

@jplacht

@jplacht jplacht commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

What and why

When people plan in several tabs, plan, empire and CX saves silently overwrite each other (last write wins). A preference PATCH replaces the whole plan_overrides dict, so per-plan settings from another tab are lost. With this change, a save based on an outdated version is rejected with 409 instead of overwriting, and a preference PATCH only changes the keys and plan overrides it sends.

Changes

  • Version and conflict check:
    • Plan, empire and CX responses carry modified_at.
    • PUT accepts an optional base_modified_at and answers 409 ({"detail", "code": "conflict", "modified_at"}) when the row has changed since.
    • The check runs under a row lock inside the saving transaction (planning/api/serializers/conflict.py).
  • Empire version: empires get config_modified_at (migration with backfill) as their version, so empire state syncs and cx-junctions never cause a conflict. It is read-only in the admin.
  • Preferences: PATCH /user/preferences/ merges planOverrides per plan uuid, and null deletes one.
  • Plan deletion: deleting a plan removes its override from the owner's preferences.
  • Backward compatible: without base_modified_at, saves work as before.

How it was verified

QA passed after 2 rounds (1 full, 1 scoped).

  • Definition of Done: uv run ruff check, ruff format --check, ty check and pytest (849 passed).
  • Code review: all 11 acceptance criteria pass.
  • In the running app (e2e stack, current main frontend):
    • All 11 criteria pass at the API level, covering 200/409/overwrite for plan, empire and CX, state sync, preference merge and plan delete.
    • In the browser, plan, empire, CX and profile saves and the Management delete all work, with no validation errors.
  • UI audit: 0 regressions versus baseline.
  • /sync-api: spectacular --validate is clean and nothing breaks for the frontend.

Deploy order

This can deploy on its own, any time before the frontend counterpart (multitab-02-frontend), which will send base_modified_at and handle the 409.

🤖 Generated with Claude Code

…cx, and per-key preference merge for multi-tab planning

- Plan, empire and CX responses carry modified_at; PUT accepts an optional
  base_modified_at and answers 409 (code "conflict", current modified_at)
  when the row changed since, checked under a row lock in the saving transaction
- Empires get config_modified_at (migration with backfill) as their version,
  so state syncs and cx-junctions never cause a conflict; read-only in the admin
- PATCH /user/preferences/ merges planOverrides per plan uuid; null deletes one
- Deleting a plan removes its override from the owner's preferences
- Backward compatible: without base_modified_at saves work as before

Spec: specs/2026-10-03-multitab-01-backend.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 15 complexity · 0 duplication

Metric Results
Complexity 15
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.05% coverage variation

Metric Results
Coverage variation ✅ +0.05% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (56c2521) 4895 4685 95.71%
Head commit (1d9d7cb) 4947 (+52) 4737 (+52) 95.76% (+0.05%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#77) 65 65 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

jplacht and others added 2 commits October 3, 2026 10:46
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jplacht
jplacht merged commit 02cfc13 into main Oct 3, 2026
9 checks passed
@jplacht
jplacht deleted the feat/multi-tab-safety branch October 3, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant