Skip to content

fix(store): forgetting a user leaves nothing of theirs in the recorded changes, and an import naming another customer's row is refused - #2221

Merged
thesyncim merged 2 commits into
mainfrom
fix/ai-3485-store-hardening
Nov 23, 2026
Merged

thesyncim merged 2 commits into
mainfrom
fix/ai-3485-store-hardening

Conversation

@thesyncim

@thesyncim thesyncim commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Problem
Forgetting an end user rewrote or deleted their rows but left the changes data_changes had recorded of those rows, so GET /v1/data/changes still served the user's id and the words of their hidden messages until the retention prune. Separately, importRow resolved a conflict on a table's key with an update guarded by who holds the row, so an imported row whose id another customer already held here was dropped without an error.

Fix

  • Requests.RenameUser and ForgetUserSettings replace the user's id with the replacement in every recorded change of the app's requests and campaigns that names them, deleted rows' included, in the same statement as the rewrite. A request recorded after the statement, which a later forget-user run rewrites, keeps its change.
  • BranchMessages.DeleteUser and Sessions.Delete turn the recorded inserts and updates of the copies of hidden messages they delete into deletes that carry nothing. The copy's own delete change stays, so a move still removes it.
  • Changes are rewritten in place, never deleted: Changes refuses a cursor below the oldest change kept of any customer, so deleting one would send other apps' followers back to a full copy.
  • Changes of rows forget leaves in place (sessions, users, tasks) stay, since the export carries those rows as they are.
  • importRow returns ErrAnotherCustomersRow when it wrote nothing and another customer holds the row's key. An import or an applied change stops there with a 400 where it used to skip the row. Re-importing the importer's own row still succeeds. A request is not refused this way: since fix(store): give an imported request a usage id of the importing deployment's #2189 an imported request takes a usage id of this deployment's, so it lands beside the other customer's row.

Tests
Each failed before its fix:

  • TestForgettingAUserRenamesThemInTheChangesRecordedOfTheirCampaigns: another app's change under the same campaign id and user id stays.
  • TestForgettingAUserRenamesThemInTheChangesOfTheRequestsRewrittenAlone: a late request and a session keep their changes.
  • TestForgettingAUserRenamesThemInTheChangesOfACampaignDeletedBefore and TestRenamingAUserRenamesThemInTheChangesOfARequestDeletedBefore
  • TestForgettingAUserOfOneAppLeavesAnotherAppsFollowerWhereItWas: another app's follower is not expired.
  • TestForgettingAUserEmptiesTheChangesRecordedOfTheirCopies: covers the copy's delete change, change numbers and a call of the session.
  • TestForgettingAUserAfterTheirSessionWasDeletedLeavesNoChangeOfItsCopies
  • TestAnImportCannotOverwriteAnotherCustomersRow, and TestAReplayedChangeCannotDeleteAnotherCustomersRow for a replayed insert.

These fail under a broken check rather than before the fix:

  • TestARequestWhoseIDsAnotherCustomerHoldsHereLandsBesideTheirs
  • TestALogTakenBackWhereItCameFromIsNotRefusedOverAnotherAppsLogWithItsCopysID
  • TestReimportingTheImportersOwnRowsIsTheSameAsImportingThemOnce

Part of AI-3485

@thesyncim
thesyncim force-pushed the fix/ai-3485-store-hardening branch from b3f63d6 to 49da1e5 Compare November 23, 2026 14:43
@thesyncim
thesyncim marked this pull request as ready for review November 23, 2026 14:44
@thesyncim thesyncim added the data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review label Nov 23, 2026
@thesyncim
thesyncim requested a review from kanat November 23, 2026 14:57

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 49da1e5 merged onto main 1c87c73. CI on the head is green, but it ran before #2189 merged. On the merged tree, TestDataMoveSuite/TestAnImportedRequestWhoseUsageIDAnotherCustomerHoldsIsRefused fails (R1.1). The merges with #2201 and #2208 are clean and add no other failure.

Checked and sound: the copies' changes are deleted on every shard, in the same statement as the rows. The campaigns' changes are deleted in the forget's transaction. Another user's changes, the replacement's changes and the delete changes stay. Re-importing the importer's own rows (including requests under derived usage ids, and logs moved back) is not refused. Mutations: 17 checked, 7 survived (R1.4), 2 equivalent.

Verdict: request changes, for R1.1 (the merged tree fails a test) and the Should fix items R1.2 (forgetting a user of one app expires another app's move cursor), R1.3 (a late request of the forgotten user loses its change) and R1.4 (surviving mutants).

Comment thread acceleration/internal/store/forget.go Resolved
Comment thread acceleration/internal/store/forget.go Resolved
Comment thread acceleration/internal/store/datamove.go Resolved
@thesyncim thesyncim removed the data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review label Nov 23, 2026
@thesyncim
thesyncim force-pushed the fix/ai-3485-store-hardening branch from 49da1e5 to 9da9a43 Compare November 23, 2026 15:53
@thesyncim thesyncim changed the title fix(store): forgetting a user deletes their pending changes, and an import naming another customer's row is refused fix(store): forgetting a user leaves nothing of theirs in the recorded changes, and an import naming another customer's row is refused Nov 23, 2026
@thesyncim
thesyncim requested a review from kanat November 23, 2026 15:54
@thesyncim thesyncim added the data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review label Nov 23, 2026

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 9da9a43, merged onto main 1c87c73 (the branch is rebased on it, so no merge was needed). CI is green. Verdict: not yet. One new Should fix, R2.1, in code this round added. Everything from round 1 is fixed or ticketed.

Prior findings

  • R1.1 fixed. TestARequestWhoseIDsAnotherCustomerHoldsHereLandsBesideTheirs passes on the merged tree and the body no longer claims requests are refused.
  • R1.2 fixed. Nothing is deleted from data_changes any more. Probe: another app's follower, current at its export cursor, still reads its change after the forget (Store and Sharded suites).
  • R1.3 fixed. Probe: a request inserted between RenameUser and the forget keeps its row and its change.
  • R1.4 fixed. The 7 mutants are killed (F2, B1, S1, D3, D4, D5; F5's table set no longer exists, and the same mutation on its table check is equivalent).
  • R1.5 and R1.6 are in AI-3602 (Marcelo's replies). They do not block.

Redaction, not deletion. Confirmed: renamedChanges and forgottenCopies are UPDATEs of data_changes, the sequence numbers stay, and a copy's insert and update become payload-free deletes. datamove.go is unchanged since round 1. Of the other mutants I added (CTE not attached in RenameUser, Sessions.Delete and DeleteUser; the user id set to itself; payload not emptied; op not set; the session filter dropped), all were killed.

Suites. The store, sharded and data-move suites pass on the head. Only TestEveryHotTableIsReadByIndex fails here (5 subtests, planner choice on this machine). The same 5 fail on main 1c87c73, and CI's integration (store) passes.

Comment thread acceleration/internal/store/forget.go Resolved
Comment thread acceleration/internal/store/request.go Resolved
…d changes, and an import naming another customer's row is refused

- Requests.RenameUser and ForgetUserSettings rename the user in every recorded change of the
  app's requests and campaigns that names them, deleted rows' included, in the same statement
  as the rewrite. A request recorded after the statement keeps its change.
- BranchMessages.DeleteUser and Sessions.Delete turn the recorded inserts and updates of the
  copies they delete into deletes that carry nothing. The copy's own delete change stays.
- Every change keeps its number, so no follower of any app is told to export again.
- importRow returns ErrAnotherCustomersRow when it wrote nothing because another customer
  holds the row's key here, instead of dropping the row. A re-import of the importer's own
  row is still a no-op.
@thesyncim
thesyncim force-pushed the fix/ai-3485-store-hardening branch from 9da9a43 to 4a52396 Compare November 23, 2026 16:21
@thesyncim
thesyncim requested a review from kanat November 23, 2026 16:22

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: GO. Reviewed 4a52396 (merged onto current main 31fd2dd, clean).

Prior findings

  • R2.1 fixed. Both key->>'id' IN (...) clauses are gone (forget.go:134, request.go:724), so a campaign or request deleted before the forget or RenameUser keeps no change naming the user. The two new tests, TestForgettingAUserRenamesThemInTheChangesOfACampaignDeletedBefore and TestRenamingAUserRenamesThemInTheChangesOfARequestDeletedBefore, pass. I put each clause back in a scratch copy and the matching test failed. The request test skips on the sharded suite, as it should. Dropping the customer, table or user filter from renamedChanges fails a test each.
  • R1.1 to R1.4 stay fixed. The earlier probes for P1, P2, B1, S1, F2, D3, D4 and D5 all pass on this head.
  • R1.5 and R1.6 stay with ticket AI-3602 and do not block.

What changed since round 2. I compared the PR patch of 9da9a43 with that of 4a52396, line by line. They differ only by the two removed clauses, the two new tests and reworded comments. The rest is identical.

Tests. I ran the Store, ShardedStore and DataMove suites on this head merged onto main. Only TestEveryHotTableIsReadByIndex fails (five subtests, the planner picks another index on my machine). The same five failed on main in round 2, and CI integration (store) passes. gofmt and go vet are clean. CI is green on all checks.

Mutations. 5 checked, 0 survived.

One nit, inline, does not block.

Comment thread acceleration/internal/store/forget.go Resolved

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving on the reviewer's GO (findings in the review comments above).

@thesyncim
thesyncim merged commit 06816a9 into main Nov 23, 2026
13 checks passed
@thesyncim
thesyncim deleted the fix/ai-3485-store-hardening branch November 23, 2026 17:43
thesyncim added a commit that referenced this pull request Nov 23, 2026
…copes' policies, and forget cached rows a move wrote (#2227)

**Problem**
`deleteRow` matched a replayed delete on every primary key column, the
customer column included, so for `users`, `scheduled_tasks`,
`customer_activity` and the app's `policies` a delete replayed under
another app id matched nothing. A policy change is recorded under its
scope id whatever its scope, so the change feed listed an organization's
policy sharing the app's id, and the replay wrote it as the app's.
`ImportRow` and `ApplyChanges` dropped no cached rows, so configs,
skills, voices and policies they wrote were served stale until the cache
TTL.

**Fix**
- `deleteRow` leaves the customer column out of the key conditions; the
destination's customer condition still scopes the delete.
- `Changes` lists a `policies` change only when its key's scope is
`app`, filtered before the limit so a page stays full and `caught_up`
holds. `applyChanges` replays only those too, for changes from a source
without the filter.
- `importRow` and `deleteRow` collect the cache keys of the row as it
reads after and before the write, so a rename drops the old name too.
Only a delete from a cached table returns its row. `ImportRow` forgets
the keys after its statement, `ApplyChanges` after its transaction
commits, using the existing key functions and `forget`.
- The second expiry check in `Changes` is left for a separate change.
- Conflicts with #2221 and #2201 near the end of `importRow`; either
merge order needs only a small rebase.

**Tests**
Each failed before its fix, except `TestAnAppsPolicyChangeIsReplayed`,
which guards the scope filter.
- `TestADeletedTaskIsReplayedUnderTheIDTheAppMovedTo`: a delete replayed
under another app id removes that task and keeps its sibling.
- `TestChangesCarryNoOrganizationsPolicyOfTheAppsID`: the feed leaves
the organization's policy out and still fills the page.
- `TestAnOrganizationsPolicyIsNotReplayedOverTheAppsOfTheSameID`: an
organization's policy change leaves the app's as it was.
- `TestAPolicyChangeNamingNoScopeIsNotReplayed`: a change with no scope
in its key is not replayed.
- `TestAnAppsPolicyChangeIsReplayed`: an app's own policy change still
lands.
- `TestAnImportedConfigIsServedRightAfterTheImport`: a cached missing
config is dropped by an import.
- `TestAConfigImportedWithANumericNameIsServedRightAfterTheImport`: the
same for an id sent as a number.
- `TestARouterConfigImportedIsServedRightAfterTheImport`: the same for a
router config.
- `TestAVoiceImportedIsServedRightAfterTheImport`: the same for a voice.
- `TestAnImportedPolicyIsServedRightAfterTheImport`: the same for an app
policy.
- `TestAnImportedPolicyDecidesTheAppsRequestsRightAfterTheImport`: the
app's merged policies are dropped too.
- `TestAReplayedConfigChangeIsServedRightAfterIt`: a replayed update is
served at once.
- `TestAReplayedRouterConfigChangeIsServedRightAfterIt`: the same for a
router config by id.
- `TestAReplayedVoiceChangeIsServedRightAfterIt`: the same for a voice
by id.
- `TestAReplayedSkillChangeIsServedRightAfterIt`: the same for a skill.
- `TestAConfigRenamedByAReplayIsNoLongerServedByItsOldName`: a replayed
rename drops the old name.
- `TestAConfigDeletedByAReplayIsNoLongerServed`: a replayed delete drops
the config.
- `TestAPolicyDeletedByAReplayIsNoLongerServed`: a replayed delete drops
the app's policy.
- `TestACursorPastAnOrganizationsPolicyLeftOutIsNotExpiredByItsPruning`:
a page that leaves out an organization's policy still moves the cursor
past it, so pruning that change does not expire the follower.
- `TestAFullPageOfChangesResumesAfterItsLastChange`: a full page ends at
its last change and skips nothing.
- `TestARunWhosePageCarriesNoChangeStillMovesItsCursor`: `follow` saves
the newer cursor from an empty page.
- `TestASkillMovedByAReplayLeavesItsOldConfig`: a skill moved to another
config is no longer served from the old one.
- `TestAVoiceRenamedByAReplayIsNoLongerServedByItsOldName`: a replayed
voice rename drops the old name.

Part of AI-3495
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants