fix(sync): history derives from lifecycle state — legacy deletions visible, honest attribution #1367
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/sync-history-legacy"
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?
Fixes the production bug from the 0.10.5 AVD report: the backup screen correctly showed "18 bewusst nicht in Memories" (change feed = pure
lifecycle_state) but the view history answered "Momentan ist nichts aus der Mediathek entfernt". Also fixes oracle finding F5 (bulk-attribution lie). Lane 3 of 4; base = origin/main05c432db, no overlap with the other lanes' files.Root cause (verified, not re-diagnosed)
RemovedLibraryHistoryQueryService.PAGE_SQLbuilt its base set fromFROM media_deletion_decisions d JOIN media_items mi …— an INNER JOIN on the V178 provenance table. The user's items were deleted 2026-10-23, before the sync server (PR-D/V178) deployed 2026-10-24 → no decision rows → history empty while the change feed correctly reportedpermanently_deletedand the client shadowed all 18 rows.A. Server — lifecycle-driven history, provenance as enrichment
media_itemswithlifecycle_state IN ('trashed','permanently_deleted');media_deletion_decisionsis LEFT JOINed for attribution only. A missing decision row is a legacy entry, still listed.decision.decided_at → permanently_deleted_at → trashed_at → updated_at— legacy rows carry the item's real removal timestamp; keyset pagination orders on the same coalesced expression (cursor wire format unchanged; cursors are ephemeral per pull/poll anyway).active, entry drops out (verified by the existing restore test, still green).B. Attribution ruling (F5)
TrashService.emptyTrash(ownerId, actorUserId, confirm)now records the authenticated session user asactor_user_idon every purged item,decided_by='user'(C6 arbitration unchanged). Ruling, documented on the method: the originalNULLrationale ("no single actor in endpoint contract") misread the contract — the authenticated owner session IS who pressed the button, exactly as for the single-item permanent delete, which always recorded its actor.actor_user_id NULLis reserved for "no human decided this" (retention sweep/unknown), never "a human decided this but we collapsed who".trash_retention_untilis displayed, never enforced (V178 header says the same); no scheduled sweeper calls emptyTrash or any purge path.retention_sweepis defined for a future sweeper.userrequires POSITIVE evidence (decided_by='user'AND actor recorded);sweepon theretention_sweepmarker;legacyfor no decision row / user decision with unrecorded actor / unknown futuredecided_by.displayNamenon-null exactly whenuser.C. Android copy (de/en/da, intent-not-failure register)
Attribution → copy mapping (
attributionShapeFor, pure + tested):user(+name)sweeplegacynull(older server) / unknown future value /userwith missing nameThe card's title still shows the live state ("Im Papierkorb"/"Endgültig entfernt"); no "du hast", no false "Automatisch" (S7a/S8). Purged entries keep the no-button + honest copy from PR #1364; trashed entries keep the working "Wiederherstellen" — no regression.
Contracts & specs
specs/001-v1-baseline/contracts/core-api.openapi.yaml):RemovedLibraryHistoryEntry.attribution(user|sweep|legacy, required, add-only + unknown-fallback documented),displayNamenullability tightened, endpoint description amended (legacy entries listed; base set = lifecycle).spec-query(sanctioned writer), following cod-12's pattern:AMENDED (2026-10-24, legacy-history fix + honest attribution)— lifecycle-derived base set, absent-provenance entries stay listed,user|sweep|legacyvocabulary with neutral no-actor client duty, emptyTrash session-actor ruling.media:uploadfor intents,media:readfor the read feeds, 403 request-level) + S5: its request-level scope note.spec-md/specs/065/spec.mdregenerated with the official exporter and verified: my export is byte-identical to a clean-main export apart from spec 065 (the other export drift on main is pre-existing and left to CI, as in #1365).Tests (all green)
:apps:api:test --rerun-tasks— 198 suites / 2310 tests, 0 failures, 0 errors (9 pre-existing skips). New/extended: legacy deletion (decision row deleted, the pre-V178 shape) → listed withattribution=legacy+ coalescedtrashed_at; user decision with stripped actor → legacy; mixed legacy/new keyset pagination across two pages; owner scoping (existing); trashed+restored drops out (existing);emptyTrashrecords the session actor on every row + history rendersuser+ display name; controller pins the actor plumbing (MediaControllerTest), bulk semantics + idempotence + owner scope (TrashServiceTest), change-feed allocation (SyncChangeFeedIntegrationTest).:core:test --rerun-tasks— 12 suites / 143 tests, 0 failures.:app:testDebugUnitTest --rerun-tasks— 62 suites / 669 tests, 0 failures. New: attribution→copy-shape mapping table incl.legacy, older-servernull, unknown future value, degradeduser-without-name; existing history VM tests stay green (15/15 in the suite).KNOWN_ISSUES
ISSUE-200 (
high/mitigated/area:sync, ref[fix/sync-history-legacy]) — history invisible for pre-provenance deletions + bulk-attribution lie, fixed.Scope discipline
No core engine/binder changes, no intent-queue changes, no trash screen redesign, no schema migration (V178 shape unchanged — only the query and the recorded actor changed).