Repository navigation
AI-3511: fix five small wrong results in spend, prices, activity and call legs - #2270
Merged
Loschcode merged 8 commits intoNov 24, 2026
Merged
Conversation
Spend summed every group outside the biggest few into the value "other", so a cost label whose value is "other" was merged into it. The remainder row now carries other: true; a label of that value is a row of its own. The field is optional, so clients reading an older router still parse. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cancel compared the change's effective time with now(), the start of its transaction, which is taken before the wait of up to 5 s for the price list's lock. A change that came into force during that wait could still be cancelled. It now reads clock_timestamp() once the lock is held. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A BYOK row is priced at the BYOK fee with no cost at the vendor's rates, since the vendor bills the customer, so drift read every such row as billed 100% under what the vendor reported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An inbound leg opens started at the call's arrival. A join delivered after it kept that start (Connect), but a join delivered before it was taken as the leg opened and moved the start to the join, so the same call billed a second more or less by delivery order. The kept join now starts only a leg not started yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…twice The activity upsert adds each write's counts to the stored ones, and the recorder kept a failed write's deltas for the next. A commit whose answer was lost may have landed, so writing it again counted it twice. A write that failed in its commit is now ErrActivityUnsure, and the recorder drops and logs it: an ambiguous commit undercounts rather than double counts. A write that failed before its commit is still written again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s other Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
/jeffery review |
|
Thanks for asking Jeffery for review. I'll stay on this PR until I can approve it. How it works
Commands (each as a whole comment)
|
database/sql answers a context that ended before the commit with ErrTxDone or the context's error, without sending COMMIT, and pgdriver sends COMMIT on a context of its own. Those, and an error the server answered, are a commit that did not land, so the write is kept and written again. Only another failure, such as a connection cut after COMMIT was sent, is ErrActivityUnsure. A dropped write holds nothing back, so write reports true and a full record is written again at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cancel is checked against clock_timestamp(), so the change's time and the wait past it are read off the database's clock too. The SDK note lists every SDK regenerated for spend's other. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
getstream-metis
Bot
dismissed
their stale review
November 23, 2026 19:43
Withdrawing approval until eab2263 is reviewed.
Contributor
Author
|
/jeffery review |
Nothing changed since round 2 on |
Loschcode
deleted the
laurentschaffner/ai-3511-small-wrong-results-spend-other
branch
November 24, 2026 08:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
https://linear.app/stream/issue/AI-3511/small-wrong-results-spend-other-cancelling-a-price-already-in-force
Five small wrong results from the data layer review. Each one reproduced on current
main, and each is fixed in its own commit.What changed
store/request.go,store/shard_merge.go,api/server.go).other: true, and keepsvalue: "other".otheris now a row of its own, without the flag, instead of being merged into the remainder.omitemptyand optional in the spec, so a client reading an older router still parses its rows. An old client that picks the remainder byvalue == "other"will now see two rows with that value when a label really isother. Before, it saw them summed into one.openapi.yamland the Go, Python, JS, .NET, PHP, Ruby and Rust SDKs. Swift's generator is not available locally, but the Swift client has noSpendBucket, and its CI check passes..claude/skills/sdk/notes/.value == "other". Follow-up: AI-3653.store/price_change.go).Cancelnow checksEffectiveAtagainstclock_timestamp(), read once the price list's lock is held, and writes the same time ascancelled_at.price_changestrigger that backs this up still usesnow(), so it has the same gap. The new test shows the trigger lets such a cancel through when the Go check does. Fixing the trigger needs a migration, which I left out while chore(store): squash migrations into one per set #2247 squashes them. Follow-up: AI-3654, which also coversInsertandsyncPrices, both still stamped fromnow()after the same lock wait.store/activity.go,activity/activity.go).store.ErrActivityUnsure, and the recorder drops and logs it instead of keeping its deltas. A dropped write holds nothing back, sowritereports true and a full record is not left waiting for the next tick.ErrTxDoneor the context's error, without sending COMMIT; pgdriver sends COMMIT oncontext.Background(), so neither comes from a COMMIT on the wire. An error the server answered (pgdriver.Error) is a commit it refused.TestAFailedWriteIsWrittenByTheNextOne).store/call_leg.go,joinTaken).ConnectusesCOALESCE).store/request.go,vendorCosts).byokcolumn existed readfalseand stay in. The default 168 h window ages them out.Tests
apiTestALabelValuedOtherIsKeptApartFromTheRest: a spend query grouped by a tag with a valueotherreturns it apart from the remainder.storeTestACancelThatWaitedPastTheChangesTimeIsRefused: a cancel whose transaction starts before the change's time and waits on the lock past it is refused. The change's time is read off the database's clock. Withnow()it fails: the cancel goes through.activity, three tests:TestAWriteWhoseCommitAnswerWasLostIsNotWrittenAgain: a TCP proxy passes COMMIT on and then cuts the client's connection, so the commit lands and its answer is lost. The row is counted once. Without the drop it is counted twice.TestAWriteWhoseContextEndedBeforeItsCommitIsWrittenAgain: a query hook ends the context after the upsert. Commit returns without sending COMMIT, nothing is written, and the error is notErrActivityUnsure, so it is retried.TestACommitTheDatabaseRefusedIsNotUnsure: a deferred constraint fails the commit with an answer from the server, which is notErrActivityUnsure.phoneTestACallerIsBilledFromTheArrivalWhicheverEventIsDeliveredFirst: before the fix it billed 59 s in one order and 60 s in the other. It now bills 60 s both ways.cmd/routerTestDriftLeavesOutWorkOnTheCustomersOwnKey: fails without the filter (2 rows,drift).go test -tags integrationoninternal/store(price, call leg, activity,TestEveryHotTableIsReadByIndex,TestRequestQueryBudgets),internal/phone,internal/activity, the spend tests ofinternal/apiTestServerSuite, and the drift tests ofcmd/routerTestPriceSyncSuite.go vet ./...andgofmtare clean.🤖 Generated with Claude Code