Repository navigation
Conversation
A release now marks its field as released for holdFor instead of deleting it, and the hold script refuses to write over that mark, so a renewal or a timed-out hold that reaches Redis after the release cannot bring the hold back (AI-4368, AI-4369). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
Text review: 5 unclear of 5
The four comments are hard to read cold (T1.1, a Should fix since there are three or more). The PR opening is a nit (T1.2).
[Should fix] T1.1 comment, outside the diff hunk: directory.go:358-360 (only line 360 changed). The sentence ends with a "which would leave" clause, so I read it twice. Suggested:
// The release is retryable because a hold that timed out breaks the client's connection, and the next command then fails without being sent.
// Without the retry the call stays held for up to holdFor, and another customer's session with the same id is refused. Sending it twice does no harm.
[Nit] T1.2 PR opening: it has four sentences, and the third is long. "Hold" and "field" are not explained. Suggested:
A call hold that a session had released could reappear in Redis, and another customer's session on the same call was then refused for up to 30 seconds. This happened when a renewal read the hold just before the release, or when a hold write that timed out still ran in Redis after the release. A release now leaves a "released" mark on the hold for 30 seconds, and the hold script never writes over that mark.
The ticket links can go after the chart.
kanat
left a comment
There was a problem hiding this comment.
[security R1] VERDICT: GO for 59c6f7c.
No findings. What I checked:
- A released hold stays released inside the hold's lifetime: a renewal or a late hold that reaches Redis after the release is refused, and sending the release twice only rewrites the mark.
- A release marks only the hold its own session made. A mark never refuses another customer's session, and a live hold beside a mark still does.
- The holds guard whose call an id is. The calls-at-once limit counts call legs in Postgres (
internal/dlc/limits.go:98), so it does not depend on them. - A router of the previous release reads a mark as no holder and deletes it, so a rollout or a rollback falls back to the base behaviour and opens nothing new.
- A release never shortens the hash's expiry under another live hold.
- No internal error text reaches a caller or a stored field.
Each new guard was removed in turn, and the PR's tests failed every time (8 of 8). The new order-dependent tests pass 50 times each with the default flags, with -cpu 1 and with -race.
kanat
left a comment
There was a problem hiding this comment.
VERDICT: NO-GO
Reviewed 59c6f7c on the current main (d734ca0, the PR's merge base). The design closes both races: a release leaves a mark on its own field, the hold script refuses to write over a live mark, and a new hold always gets a new field, so the mark never blocks a later hold of the same call. One Should fix remains: no test pins how long the mark lasts (R1.1).
Checked and sound
- The two new race tests fail on the base with "Should be empty, but was acme". The controls (
BesideAReleasedOne,NodeThatRestarted,DropsWhatLapsed) pass on the base and on the head. - A live hold renews exactly as on the base: same value, same key TTL, and lapsed holds are still deleted.
- Each script is one
EVAL, so it runs atomically. Release and hold both set the key to expireholdForafter Redis's own time, so the key never expires before a live hold lapses. - Rolling deploy, probed with the base Lua: a previous-release script deletes a mark as lapsed, and a late renewal after that brings the hold back. This is what the PR body describes, and it is what happens on every release today. A previous-release hold for another customer right after a new release succeeds. A previous-release live hold beside a new release keeps renewing.
- Rollback: marks left behind read as empty on the base scripts, which delete them.
- Growth: 300 hold/release cycles on one call leave 300 marks for 30 s, and the first read after they lapse removes all of them.
- 18 mutants: 14 killed. R4 (a mark without its customer) is equivalent, since nothing reads a mark's customer. R5 is the order change in R1.2. R6 and R7 are R1.1.
go test -tags integration -race ./internal/node/,./internal/session/ -run TestCallHoldSuiteand./internal/api/ -run 'TestPhoneSuite|TestCallStatusSuite'pass. The PR is a draft, sogoandintegrationCI run at ready.
Verdict: request changes, for R1.1.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…reword the comments A late renewal of a released hold answered 0 once another customer had taken the call, so the renewal logged a refusal by another customer. The hold script now checks the field's mark before it walks the call. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
VERDICT: GO
Reviewed 011067d on base d734ca0 (main has nothing newer).
Prior findings
- R1.1 fixed. I applied the two mutants again: a mark that lapses after holdFor/2, and a liveCall that drops marks 15 s early. Both now fail
TestAReleasedHoldStaysMarkedUntilItWouldHaveLapsed; both passed before. - R1.2 fixed. The hold script now checks its own field's mark before the walk, in the same EVAL as the walk and the write, so it stays atomic. A live hold is never matched by the check, so renewals write the same value and TTL (
TestAHoldBesideAReleasedOneRenewsAsBeforepasses). Moving the check back after the walk fails the new test (expected -1, got 0). - T1.1 fixed. I checked each rewritten comment against the code (counter and random start, mark skipped for every customer, old routers delete a negative value, -1 before the walk, retryable release): all true.
- T1.2 fixed. The opening and the "own field" row are right.
Runs
- Node integration suite with
-race,TestCallHoldSuite,TestPhoneSuite|TestCallStatusSuite: pass. The seven hold/release tests with-count=50 -cpu 1and with-race -count=50: pass. gofmt and vet clean. - 20 mutants of the hold/release code (the author's M1-M11 and mine): all killed except three equivalent ones (a refusal for an already lapsed mark, a refusal limited to the mark's own customer, a no-op piece in the holder script).
- CI on the draft: labeler and GitGuardian pass, go and integration skipped, CodeQL pending.
New finding
- [Nit] PR body details block: "the five new or changed tests" and the 11-row mutation table are out of date (seven tests now, and the mark-lapse, early-drop and late-renewal rows are missing). Refresh it before merge.
A call hold that a session had released could reappear in Redis, and another customer's session on the same call was then refused for up to 30 seconds. This happened when a renewal read the hold just before the release, or when a hold write that timed out still ran in Redis after the release. A release now leaves a "released" mark on the hold for 30 seconds, and the hold script never writes over that mark.
How it works
sequenceDiagram participant Session as Session (node A) participant Renewal as Renewal tick (node A) participant Redis Renewal->>Renewal: copy the holds to renew Session->>Redis: release: HSET field "-<now+30s> acme" Renewal->>Redis: hold script for the same field Redis-->>Renewal: -1, the field is marked released, nothing written Note over Redis: the call is free for another customer at onceTickets: AI-4368 (renewal after release) and AI-4369 (timed-out hold after release).
A hold write that timed out and reaches Redis after the release meets the same mark and gets the same -1.
-<now+holdFor> <customer>into its own field and sets the key to expire in holdForTestAHoldThatRunsAfterItsReleaseStaysReleasedTestAHoldReleasedDuringARenewalStaysReleased,TestAHoldThatRunsAfterItsReleaseStaysReleasedliveCallnever counts a mark as a holder, and deletes it once it lapsesTestACallIsHeldUntilTheLastSessionOnItIsGoneand the other release tests,TestAHoldDropsWhatLapsedTestAHoldBesideAReleasedOneRenewsAsBeforeTestANodeThatRestartedHoldsACallItsLastRunReleased<now+30s> acme, key TTL 30 sWhy a mark and not "renew only what is still there"
A renewal that only refreshes fields still present would close the first race, but not the second: a timed-out first hold also creates its field, so only something the release leaves behind can refuse it. It would also break a promise the code makes today: a hold that Redis never got is written by the next renewal (
TestAHoldThatWasNotSaidIsSaidWithTheNextRenewal). One mark, checked by the one script that writes holds, closes both races and keeps that promise.Rolling deploy
A router of the previous release reads
-<until>as a lapsed hold and deletes it, astonumbergives a negative number. While old and new routers share Redis, a mark can therefore be removed early by an old router. That is the old behaviour, not a new failure: old routers already release with a plain delete.Mutations, commands and runs
Base repro (tests only, on d734ca0):
TestAHoldReleasedDuringARenewalStaysReleasedandTestAHoldThatRunsAfterItsReleaseStaysReleasedfail with "Should be empty, but was acme". The control tests (TestAHoldBesideAReleasedOneRenewsAsBefore,TestANodeThatRestartedHoldsACallItsLastRunReleased,TestAHoldDropsWhatLapsed) pass on the base.Mutations of
acceleration/internal/node/directory.go, all killed (one script, each applied, tested and restored in turn):liveCalldeletes live marks too (else HDEL)liveCallnever deletes lapsed marksnowinstead ofnow + holdFor)now + holdFor/2in the release script)liveCalldrops marks 15 s before they lapseThe seven hold and release tests are TestAHoldDropsWhatLapsed, TestAHoldReleasedDuringARenewalStaysReleased, TestAHoldThatRunsAfterItsReleaseStaysReleased, TestAReleasedHoldStaysMarkedUntilItWouldHaveLapsed, TestALateRenewalOfAReleasedHoldIsToldItWasReleasedWhenAnotherCustomerHasTheCall, TestAHoldBesideAReleasedOneRenewsAsBefore and TestANodeThatRestartedHoldsACallItsLastRunReleased.
Commands, in
acceleration/, withROUTER_REDIS_ADDRset to a separate Redis per run:go test -tags integration ./internal/node/ -count=1and once more with-race: pass-count=50 -cpu 1and with-race: passgo test -tags integration ./internal/session/ -run TestCallHoldSuiteand./internal/api/ -run 'TestPhoneSuite|TestCallStatusSuite': passgofmt -l,go vet ./internal/node/,go vet -tags integration ./internal/node/: cleanReview rounds: the main reviewer gave NO-GO in round 1, the security review gave GO, and round 2 gave GO.
🤖 Generated with Claude Code