Repository navigation
fix(store): a session's later writes name the app that owns it - #2197
Conversation
e38cb1f to
fb80b64
Compare
kanat
left a comment
There was a problem hiding this comment.
Reviewed 648c9ce merged onto current main (129b3c4). CI on the head: all green.
[Should fix] R1.2 PR body: Fixes AI-3480 closes the ticket, but its fix step 2 is not here. That step is to end a session whose opening write was refused, or to reserve the id, plus a test that two apps opening one id leave one session running. It depends on #2177's refused-upsert error, which is not on main yet. Fix: change the body to Part of AI-3480 and keep step 2 open, or add it once #2177 lands.
[Nit] R1.3 internal/store/response.go:124: ErrIDTaken and #2177's ErrSessionTaken are two sentinels for the same thing, "this id belongs to another customer's row". The two PRs also conflict in call_test.go and session_test.go (a local merge of #2177 on top of this one). Whichever lands second can fold the two into one sentinel. Ticket.
Checked and sound:
- Every write the ticket lists now has a customer predicate.
- The recorder carries the customer, and the callers pass the row's own customer.
SessionTools.Upsertrefuses a session the customer does not have.- No triggers fire on the new
DO UPDATE. generated.shis in step.- 38 mutants checked: 34 killed, 4 survived (R1.1). The call-site mutants in
session.go,manager.go,records.go,recordings.goandcampaign.goare all killed. - Siblings #2181, #2182, #2183, #2189, #2190 and #2195 overlap only in
CHANGELOG.md.
Verdict: request changes, for R1.1 (untested rules) and R1.2 (the ticket would close with its fix incomplete).
648c9ce to
579508a
Compare
|
On R1.2: you're right, step 2 isn't here. It needs the refused-upsert error from #2177, which is still open. I changed the last line to On R1.3: left as is. Whichever of this and #2177 lands second folds |
Each write that found a session, response, call or other row by id alone now also takes the customer and changes only that customer's row: session close, tool timeout, video and voice, session tools, response and call finish, call model changes, recordings, a scheduled task run finished by hand, a connection's OAuth client and validation, a simulation run and a campaign dial. The session recorder carries the customer with each write. A response, branch switch or conversation document inserted under an id another customer's row has is refused with ErrIDTaken instead of being reported as written; a retry of the same customer's row is still not an error.
…ites Recordings.Start and Finish, ScheduledTaskRuns.FinishManual and CampaignAttempts.End refuse an empty customer and id as the other writers do, and SessionTools.Upsert checks its customer first. The changelog entry gets its blank line.
…d turn's items A finish by another customer of an app's own response leaves the app's session clock alone, a same-customer retry of each insert is not an error, and every owner-scoped writer refuses an empty customer, each now with a test. A branch switch refused because its id is another customer's is answered with a 409, and the recorder writes no items for a turn whose row was refused.
579508a to
3849e38
Compare
Problem
Writes that found a session's, response's, call's or connection's row by id alone changed it whoever asked. Ids are chosen by callers and
agent_sessionsand its neighbours are keyed onidfor all apps, so a write could land on another app's row of the same id.Fix
Each of these names its customer and matches on it:
Responses.Finishand the stamp it writes on the session.SessionTools.Upsert, which writes only beside a session of the customer's.Responses.Insert,BranchSwitches.InsertandConversationDocuments.Insertrefuse another customer's id with the newErrIDTaken.For callers:
SessionTools.Upserton a missing session returnsErrNoSession.Calls.ChangeModelsandSimulationRuns.Finishread the customer from the struct and refuse an empty one.ErrIDTakenis answered with a 409.ErrIDTaken.Left for after #2177: ending a session whose opening write was refused (or reserving its id), with a test that two apps opening one id leave one session running.
Tests
Each failed with its rule taken out.
TestAnotherCustomersWriteToASessionIdChangesNothing: the four session writes.TestAnotherCustomersToolsForASessionIdAreNotKept: tools are neither replaced nor created.TestAnotherCustomersWriteToAResponseIdChangesNothing: response insert and finish.TestAnotherCustomersFinishedTurnDoesNotMoveASessionsClockandTestAnotherCustomersFinishOfAnAppsResponseDoesNotMoveItsSessionsClock: the session stamp.TestTheSameCustomerWritingARowAgainUnderItsIdIsNotAnError: a retry of each of the three inserts.TestAnOwnerScopedWriteWithoutACustomerIsRefused: each writer refuses an empty customer.TestAnotherCustomersWriteToACallIdChangesNothing: call finish and model change.TestAnotherCustomersWriteToARecordingIdChangesNothing: recording start and finish.TestAnotherCustomersFinishOfARunIdChangesNothing: manual task run.TestAnotherCustomersFinishOfASimulationRunIdChangesNothing.TestAnotherCustomersEndOfADialIdChangesNothing.TestAnotherCustomersWriteToAConnectionIdChangesNothing: client and validation.TestAnotherCustomersSwitchUnderASwitchIdIsRefusedandTestAnotherCustomersDocumentUnderADocumentIdIsRefused.TestASwitchUnderAnIDAnotherCustomerHasIsAConflict: the 409.TestAnotherCustomersCloseOfTheSameSessionIdLeavesItOpen(RecordFlushSuite): a close through the recorder for another customer leaves the session open.TestTheItemsOfATurnWhoseIdIsAnotherCustomersAreNotWritten(RecordFlushSuite): no item lands under another customer's turn.Part of AI-3480