Skip to content

fix(store): replay deletes under the importing app's id, skip other scopes' policies, and forget cached rows a move wrote - #2227

Merged
thesyncim merged 1 commit into
mainfrom
fix/ai-3495-change-replay
Nov 23, 2026
Merged

thesyncim merged 1 commit into
mainfrom
fix/ai-3495-change-replay

Conversation

@thesyncim

@thesyncim thesyncim commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

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

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

@thesyncim
thesyncim force-pushed the fix/ai-3495-change-replay branch from a4c08a5 to 57561a9 Compare November 23, 2026 16:19
@thesyncim
thesyncim marked this pull request as ready for review November 23, 2026 16:20
@thesyncim
thesyncim requested a review from kanat November 23, 2026 16:20
@thesyncim thesyncim added data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review and removed data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review labels Nov 23, 2026
@thesyncim
thesyncim force-pushed the fix/ai-3495-change-replay branch from 57561a9 to 3fdc202 Compare November 23, 2026 18:09

@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 3fdc202 merged onto main ce41c39. I used my own test database and Redis.

Rebase: your importRow resolution matches mine. The stale keys are added right after the insert, before RowsAffected and ErrAnotherCustomersRow. A refused import returns before ImportRow forgets anything, and in ApplyChanges it rolls the transaction back, so nothing is forgotten.

Tests: TestDataMoveSuite passes in full, with Redis, on the merged tree. CI is green except integration (api). Its three TestChannelsSuite failures also fail on main at ce41c39 (Integration run 45233683234), so this PR does not cause them.

Mutations: 21 checked, 1 survived (R1.2). Every new rule fails a test when broken except that one: the customer-column skip, the scope filter in SQL and after the limit, appPolicy, both forgets, the old and new keys, the policy and app-policies keys, the id and name keys per table, and UseNumber.

Checked and sound:

  • A delete replayed under one app cannot reach another customer's row with the same key. I probed it with two customers holding the same task id and app policies, using a key that names the other customer: only the replaying app's rows go. No table has the customer column as its whole primary key.
  • An old source's organization-policy change is skipped on replay.
  • No other moved table has a cached read.
  • No migration. Nothing changes for an old router.

[Nit] R1.3 The Tests list in the body names TestAConfigImportedWithANumericIDIsServedRightAfterTheImport. The test is TestAConfigImportedWithANumericNameIsServedRightAfterTheImport.

Verdict: request changes, for R1.1. It is a regression on the feed path this PR changes. R1.2 can land as a follow-up.

Comment thread acceleration/internal/store/datamove.go Resolved
Comment thread acceleration/internal/store/datamove.go Resolved
…copes' policies, and forget cached rows a move wrote
@thesyncim
thesyncim force-pushed the fix/ai-3495-change-replay branch from 3fdc202 to daf5e90 Compare November 23, 2026 18:55
@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

Copy link
Copy Markdown
Member Author

R1.1 and R1.2 are fixed in daf5e90 (replied on both threads). R1.3: the Tests list now names TestAConfigImportedWithANumericNameIsServedRightAfterTheImport. Ready for another look.

@thesyncim
thesyncim requested a review from kanat November 23, 2026 19:38

@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 daf5e90 merged onto main d575e6e, on my own test database and Redis. Verdict: GO (a COMMENT review, not an approval). One follow-up test is listed below.

Prior findings

  • R1.1: fixed. A page that is not full now returns the highest seq of the customer's rows at or below the mark, read in the same transaction as the rows. follow takes page.Cursor whenever it is past its own, also on an empty page.
    • My probe from round 1 (your TestACursorPastAnOrganizationsPolicyLeftOutIsNotExpiredByItsPruning) passes on the head and on main. It failed on 3fdc202.
    • Mutations, each killed: cursor block off, < limit to <= limit (TestAFullPageOfChangesResumesAfterItsLastChange), mark bound dropped (four in-flight tests), COALESCE default 0, follow moving the cursor only with changes, follow never moving it (TestARunWhosePageCarriesNoChangeStillMovesItsCursor).
  • R1.2: fixed. Both tests are in. Under the was-only-for-configs mutant, TestASkillMovedByAReplayLeavesItsOldConfig and TestAVoiceRenamedByAReplayIsNoLongerServedByItsOldName fail. The config rename test still passes, as it should.
  • R1.3: fixed, the PR body names the right test.

New

  • [Should fix, follow-up] R2.1 The query that moves the cursor (datamove.go:1836) filters by customer_id, and no test needs that. With the filter dropped, every PR test still passes, and a follower is handed another customer's global change numbers as its cursor. The head is correct, so this is a test gap and does not block. Test row, checked to fail under that mutant (expected: 43, actual: 44) and pass on the head, for DataMoveSuite next to TestChangesStopAtTheCustomerAskingForThem:
func (s *DataMoveSuite) TestAPageCursorNeverPassesTheCustomersOwnLastChange() {
	s.capture("acme")
	s.capture("other")
	s.seedAgentConfig(s.source, "acme", "greeter")
	_, ownCursor, err := s.source.Changes(s.ctx, "acme", 0, 100)
	s.Require().NoError(err)
	s.seedAgentConfig(s.source, "other", "not-yours")

	_, cursor, err := s.source.Changes(s.ctx, "acme", 0, 100)

	s.Require().NoError(err)
	s.Equal(ownCursor, cursor)
}
  • [Nit] R2.2 The PR body's Tests list does not name the five tests added in this push.

Checks

  • TestDataMoveSuite and the replicate suites in cmd/router: pass. go build, go vet with the integration tag, and gofmt are clean.
  • An old source answers an empty page with cursor = after, and an old follower ignores the cursor of an empty page, so a mixed pair behaves as before.
  • CI on this head: all green when I read it.

Comment thread acceleration/internal/store/datamove.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 in delta round 2. R1.1 to R1.3 are fixed. R2.1 is a follow-up: no test pins the customer filter in the cursor query, and a ready test row is in the review. R2.2 is a body Nit.

@thesyncim
thesyncim merged commit 8f71e5d into main Nov 23, 2026
13 checks passed
@thesyncim
thesyncim deleted the fix/ai-3495-change-replay branch November 23, 2026 19:43
thesyncim added a commit that referenced this pull request Nov 23, 2026
…nge (#2286)

**Changes**
- None to the product code: this adds a test for the cursor a page of
changes returns.

**Tests**
- `TestAPageCursorNeverPassesTheCustomersOwnLastChange`: with two
customers recording changes, a page for one customer returns the same
cursor after the other customer's rows are written. It fails when the
`customer_id` condition is dropped from the cursor query in `Changes`
(cursor 4, want 3).

Follow-up to #2227 (Kanat's R2.1)

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