Commit 98099a6
committed
fix(chat): keep a withdrawn send in its own chat, and release stranded claims
Audit follow-ups, two of them real defects in the previous commit.
A withdrawn send routed unconditionally through the cross-surface lanes. Those
deliver to whatever chat is mounted next, so sending in one chat and switching
to another re-sent the message into the second one. The dispatcher already drew
the distinction; the idle path now draws it too — a chat-bound key is the stable
chat id, so re-queueing under it both retries durably and keeps the message
where the user put it. Only a chatless key, which dies with its mount, goes to
the lanes.
The claim release sat in `catch`, so the two paths that return a response
without throwing — a rejected branch, and a missing chat — stranded an
in-progress claim for its full 60s TTL, and a retry inside that window got a
spurious "already sent" instead of the real error. Moved to `finally`.
Also: `userMessageId` is now length-bounded, since it becomes part of a Postgres
key and an oversized one would throw inside the claim; `requestId` was still
empty at claim time, so both dedup logs printed a blank prefix; the provider
segment said `mothership` on a handler that also serves the workflow copilot,
and now says what the key identifies; `retryFailures` was dead config, only read
by `executeWithIdempotency`, which this caller never invokes; the doc pointed at
`billingIdempotency`, which has no consumers, and now points at the live Stripe
analogue.
Trimmed: `sendClaimRecorded` folded into clearing `sendClaim`, the unread `kind`
discriminant dropped from a one-arm union, the single-use `claimedChatId`
inlined, and the prose on all three of those cut back to what the code does not
already say.1 parent ac7a732 commit 98099a6
5 files changed
Lines changed: 147 additions & 76 deletions
File tree
- apps/sim
- app/workspace/[workspaceId]/home/hooks
- lib
- copilot/chat
- core/idempotency
Lines changed: 65 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
148 | 185 | | |
149 | 186 | | |
150 | 187 | | |
| |||
260 | 297 | | |
261 | 298 | | |
262 | 299 | | |
| 300 | + | |
263 | 301 | | |
264 | 302 | | |
265 | 303 | | |
| |||
444 | 482 | | |
445 | 483 | | |
446 | 484 | | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
447 | 512 | | |
Lines changed: 33 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
3905 | 3905 | | |
3906 | 3906 | | |
3907 | 3907 | | |
3908 | | - | |
| 3908 | + | |
3909 | 3909 | | |
3910 | 3910 | | |
3911 | 3911 | | |
| |||
4031 | 4031 | | |
4032 | 4032 | | |
4033 | 4033 | | |
4034 | | - | |
4035 | | - | |
4036 | | - | |
4037 | | - | |
4038 | | - | |
4039 | | - | |
4040 | | - | |
| 4034 | + | |
| 4035 | + | |
| 4036 | + | |
| 4037 | + | |
| 4038 | + | |
| 4039 | + | |
| 4040 | + | |
| 4041 | + | |
| 4042 | + | |
| 4043 | + | |
| 4044 | + | |
| 4045 | + | |
4041 | 4046 | | |
| 4047 | + | |
| 4048 | + | |
| 4049 | + | |
| 4050 | + | |
| 4051 | + | |
| 4052 | + | |
| 4053 | + | |
| 4054 | + | |
| 4055 | + | |
| 4056 | + | |
4042 | 4057 | | |
4043 | 4058 | | |
4044 | 4059 | | |
| |||
4578 | 4593 | | |
4579 | 4594 | | |
4580 | 4595 | | |
| 4596 | + | |
| 4597 | + | |
| 4598 | + | |
| 4599 | + | |
4581 | 4600 | | |
4582 | 4601 | | |
4583 | 4602 | | |
| |||
4604 | 4623 | | |
4605 | 4624 | | |
4606 | 4625 | | |
4607 | | - | |
4608 | | - | |
4609 | | - | |
| 4626 | + | |
| 4627 | + | |
| 4628 | + | |
4610 | 4629 | | |
4611 | 4630 | | |
4612 | 4631 | | |
4613 | 4632 | | |
4614 | 4633 | | |
4615 | | - | |
| 4634 | + | |
4616 | 4635 | | |
4617 | 4636 | | |
4618 | 4637 | | |
| |||
4631 | 4650 | | |
4632 | 4651 | | |
4633 | 4652 | | |
| 4653 | + | |
4634 | 4654 | | |
4635 | 4655 | | |
4636 | 4656 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| |||
758 | 758 | | |
759 | 759 | | |
760 | 760 | | |
761 | | - | |
| 761 | + | |
762 | 762 | | |
763 | 763 | | |
764 | 764 | | |
| |||
798 | 798 | | |
799 | 799 | | |
800 | 800 | | |
801 | | - | |
| 801 | + | |
802 | 802 | | |
803 | 803 | | |
804 | 804 | | |
| |||
817 | 817 | | |
818 | 818 | | |
819 | 819 | | |
820 | | - | |
| 820 | + | |
821 | 821 | | |
822 | 822 | | |
823 | 823 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
264 | 267 | | |
265 | 268 | | |
266 | 269 | | |
| |||
945 | 948 | | |
946 | 949 | | |
947 | 950 | | |
948 | | - | |
949 | | - | |
| 951 | + | |
| 952 | + | |
950 | 953 | | |
951 | 954 | | |
952 | 955 | | |
953 | 956 | | |
954 | | - | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | | - | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
959 | 960 | | |
960 | | - | |
961 | | - | |
962 | | - | |
| 961 | + | |
| 962 | + | |
963 | 963 | | |
964 | 964 | | |
965 | 965 | | |
966 | | - | |
967 | | - | |
| 966 | + | |
968 | 967 | | |
969 | 968 | | |
970 | 969 | | |
| |||
973 | 972 | | |
974 | 973 | | |
975 | 974 | | |
976 | | - | |
| 975 | + | |
977 | 976 | | |
978 | 977 | | |
979 | 978 | | |
980 | 979 | | |
981 | 980 | | |
982 | 981 | | |
983 | 982 | | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | 983 | | |
991 | 984 | | |
992 | 985 | | |
| |||
997 | 990 | | |
998 | 991 | | |
999 | 992 | | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
1007 | 997 | | |
1008 | 998 | | |
1009 | 999 | | |
| |||
1018 | 1008 | | |
1019 | 1009 | | |
1020 | 1010 | | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
| 1011 | + | |
1026 | 1012 | | |
1027 | | - | |
1028 | 1013 | | |
1029 | 1014 | | |
1030 | 1015 | | |
| |||
1059 | 1044 | | |
1060 | 1045 | | |
1061 | 1046 | | |
1062 | | - | |
| 1047 | + | |
1063 | 1048 | | |
1064 | | - | |
| 1049 | + | |
1065 | 1050 | | |
1066 | 1051 | | |
1067 | 1052 | | |
| |||
1156 | 1141 | | |
1157 | 1142 | | |
1158 | 1143 | | |
1159 | | - | |
1160 | | - | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
1164 | 1148 | | |
1165 | | - | |
| 1149 | + | |
1166 | 1150 | | |
1167 | 1151 | | |
1168 | 1152 | | |
| |||
1176 | 1160 | | |
1177 | 1161 | | |
1178 | 1162 | | |
| 1163 | + | |
1179 | 1164 | | |
1180 | 1165 | | |
1181 | 1166 | | |
| |||
1482 | 1467 | | |
1483 | 1468 | | |
1484 | 1469 | | |
1485 | | - | |
1486 | | - | |
1487 | | - | |
1488 | | - | |
1489 | | - | |
1490 | | - | |
1491 | | - | |
1492 | | - | |
1493 | | - | |
1494 | | - | |
1495 | | - | |
1496 | | - | |
1497 | | - | |
1498 | 1470 | | |
1499 | 1471 | | |
1500 | 1472 | | |
| |||
1524 | 1496 | | |
1525 | 1497 | | |
1526 | 1498 | | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
1527 | 1514 | | |
1528 | 1515 | | |
0 commit comments