Skip to content

[AI-3686] A data move keeps a given-back number as billing history - #2306

Open
kanat wants to merge 5 commits into
mainfrom
kanat/ai-3686-given-back-numbers-stay-history
Open

kanat wants to merge 5 commits into
mainfrom
kanat/ai-3686-given-back-numbers-stay-history

Conversation

@kanat

@kanat kanat commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Problem

A data move protects a phone number bought here only while it is still held: boughtHere also asks for released_at IS NULL (acceleration/internal/store/datamove.go). A number given back here is billing history. An imported sip_trunk row with its id turned it into a live trunk number, and a replayed delete of that id removed it. Billing skips trunk numbers, so a month that began before the release was never billed.

Found in the post-merge review of #2182 (R1.1).

Fix

boughtHere is now vendor <> 'sip_trunk': every number bought here is guarded, held or given back. Both callers already use it, the import conflict clause and the replayed delete.

Tests

Two new DataMoveSuite tests, each on a number bought here and then given back:

  • TestANumberGivenBackHereIsNotWrittenOverByARowWithItsID: an imported sip_trunk row with its id, by ImportRow and by a replayed update; the row stays released on its vendor.
  • TestAReplayedDeleteLeavesANumberGivenBackHere: the row stays.

Both fail on base 1029b8d and pass here. Mutations checked: restoring the released_at term, dropping the guard at the import site, dropping it at the delete site, inverting the vendor test, and a never-true guard each fail at least one test.

🤖 Generated with Claude Code

boughtHere no longer asks for released_at IS NULL, so an import or a replayed
delete aimed at a number bought here and given back leaves the row as it was.

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

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewed 2d0144e9d merged onto origin/main 8e6e0bc, and also with #2305 (5cd388f6e) merged on top: both merges are clean, and DataMoveSuite passes on each. CI: this is a draft, so go and integration are skipped; CodeQL, GitGuardian and labeler pass. The full run happens at gh pr ready.

[Should fix] R1.1 CHANGELOG.md:926 (Unreleased, Bug Fixes): the line still says "A number bought here and still held is never updated or deleted by an imported row or a replayed change, whatever id it names." This PR also guards a given-back number, and acceleration/README.md:2918 already says "held or given back". Change the sentence to "A number bought here, held or given back, is never updated or deleted ...". This line is not in the diff, so it is here and not inline.

Checked and sound:

  • boughtHere has two callers (import conflict, replayed delete). Both now guard every number with a vendor other than sip_trunk, held or given back.
  • A number given back here and then moved in on a trunk under another id imports live, and the given-back row stays as it was. A telnyx row naming a given-back id is skipped. A trunk number never bought here still imports, updates, is released and is deleted by a replayed delete. Another customer's row with a given-back id is refused with ErrAnotherCustomersRow, as for a held one.
  • Billing: a number bought 75 days ago and given back 10 days ago, then hit by an imported sip_trunk row with its id. Rentals.Bill bills 2 months on this head and 0 on base, where the row became a live trunk number.
  • The released_at term at datamove.go:882 tests the incoming row and is not a bought-here guard, so it is rightly left alone.
  • Mutations: 7 checked, 0 survived (restore the term, drop the guard at each site, invert, never-true, guard only given-back rows, old term at the delete site). Details: AI-3686/pr/reviewer-1.md in the ship-task ledger.

Verdict: no GO until R1.1 is fixed. There is no code finding.

conflict += fmt.Sprintf(" AND %s.status <> '%s' AND %s.credentials_kek_version = 0", spec.name, ConnectionConnected, spec.name)
}
// A number bought here and still held is this deployment's, whatever row names its id.
// A number bought here, held or given back, is this deployment's, whatever row names its id.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[Question] R1.2 The guard is by id. Ids are per-deployment sequences carried as they are, so a source trunk number whose id equals the id of a number bought here is skipped: ImportRow returns nil, nothing is written, and the importer is told nothing. Probe: a trunk row with a different e164 and the id of a given-back number, and the same with a held one, both give nil and no row. The held case on main already does this, so this PR does not add a new kind of loss, but it adds given-back rows to it. Not for this PR: ticket it if the importer should get a skipped-row count or the id should be remapped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kanat
kanat marked this pull request as ready for review November 23, 2026 23:13
@kanat

kanat commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

R1.1 fixed in b7bf242. The CHANGELOG now says a number bought here, held or given back, is never updated or deleted by an imported row or a replayed change. The commit changes only that one line (checked by diff). R1.2, the silent skip when an id matches a guarded number (the held case does the same on main), becomes a ticket. Verdict: GO at b7bf242.

@kanat
kanat marked this pull request as draft November 23, 2026 23:33

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: GO

Delta review, round 2. Head b7bf242, previous reviewed head 2d0144e.

Prior findings:

  • R1.1 (Should fix, CHANGELOG.md:926): fixed. The delta changes only that sentence, now "A number bought here, held or given back, is never updated or deleted by an imported row or a replayed change, whatever id it names." It matches the code: boughtHere in acceleration/internal/store/datamove.go:1626-1631 has no released_at term; the import conflict at datamove.go:958 and the replayed delete at datamove.go:2015 both use it. acceleration/README.md:2919 already says "held or given back". The tests behind the sentence are at acceleration/internal/store/datamove_test.go:3727, 3740 and 3752. They were not rerun, since the delta is one doc line.
  • R1.2 (Question, acceleration/internal/store/datamove.go:958): ticket, does not block. Unchanged by this delta. An imported number whose id equals a number bought here is skipped without an error. This is tracked as a ticket.

New findings: none in this delta.

CI at review time: every check passes except go, which is still in progress on this head.

kanat and others added 3 commits November 24, 2026 22:07
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
PhoneNumbers.Release is gone from main (#2377).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kanat

kanat commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Fixer round 3: the PR had gone stale against main. Merged origin/main (own commit). Main removed PhoneNumbers.Release (#2377), so the two new tests did not build; givenBackHere now releases through StreamTrunks.InGroup + TrunkGroupTx.ReleaseNumber, the way #2377 rewrote the other call sites. Reverted the CHANGELOG.md hunk to main's text (a PR does not edit it).

Mutation (restore released_at IS NULL in boughtHere): TestANumberGivenBackHereIsNotWrittenOverByARowWithItsID and TestAReplayedDeleteLeavesANumberGivenBackHere both fail; restored, DataMoveSuite passes.
Checks on the merged tree: go build ./..., go vet ./... and go vet -tags integration ./... clean, gofmt clean. TestStoreSuite, MeteringSuite and DataMoveSuite ran with only the known base failures (TestEveryHotTableIsReadByIndex, 5 subtests).

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: GO

Delta round 3 of #2306. Head ba8f2c2, previous reviewed head b7bf242 (round 2 GO). Nothing new to fix.

Prior findings

  • R1.1 (Should fix, CHANGELOG sentence): moot. The repo rule is that a pull request does not edit CHANGELOG.md, and the delta drops the hunk (git diff --stat origin/main...HEAD: datamove.go and datamove_test.go only). The sentence it fixed is gone from the PR, so nothing in it is left to be wrong.
  • R1.2 (Question, id collision skipped without an error): unchanged, ticketed, does not block.

The merge of main

  • git show --remerge-diff a1f024b7a is empty: a clean merge, no conflict resolution.
  • The PR's own change over its merge base, before (git diff 1029b8d34 b7bf24204) and after (git diff fca02d5cc ba8f2c20f): the +/- lines differ in exactly two places. The CHANGELOG hunk is gone, and givenBackHere (datamove_test.go) now releases through StreamTrunks.InGroup and TrunkGroupTx.ReleaseNumber instead of PhoneNumbers.Release. The three datamove.go hunks (the conflict term, and the boughtHere doc and body) and both tests are the same.
  • The release path is the one the store's own giveBack helper (phone_number_test.go:12) uses. ReleaseNumber with a zero time stamps now, as Release did (phone_number.go:470).
  • Nit, no block: giveBack(s.ctx, s.destination, "other", e164, time.Time{}) already exists in the package and would replace the inline closure in givenBackHere. Fix in this PR if you touch it again; not worth a round.

Checks

  • I merged ba8f2c2 onto the current origin/main cd3f737 in a scratch worktree (clean). go build ./..., go vet -tags integration ./... and gofmt -l internal/store are clean. go test -tags integration ./internal/store/ -run TestDataMoveSuite -count=1 -p 1 passes (91s, own database).
  • Mutation: restore released_at IS NULL in boughtHere. TestANumberGivenBackHereIsNotWrittenOverByARowWithItsID and TestAReplayedDeleteLeavesANumberGivenBackHere both FAIL; the two held-number controls still pass. Restored.
  • CI: the PR is a draft, so go and integration are skipping; CodeQL, Analyze (go, python, actions), labeler and GitGuardian pass.

@kanat
kanat marked this pull request as ready for review November 25, 2026 03:36

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant