Repository navigation
Commit 0b2dfbf
fix(channels): let published leave and delete confirm through access loss (#2357)
## Problem
Leaving a channel worked, but the app showed **"Leave channel failed —
The request may have taken effect. Refresh channels before trying
again."** The relay announces a departure live, before it acknowledges
the 9022. It does this through a 39002 roster push, a 44101
member-removed hint (with its strong roster refresh), or a CLOSED
`restricted:`. Discovery marks the channel denied, and the session's
`revokeAccess` calls `lifecycle.cancel()`. That aborted the leave's own
in-flight publish or confirmation read. Publication had already started,
so `run()` wrapped the abort as `ChannelLifecycleUnconfirmed` and the
dialog showed the failure toast.
The same abort had other effects:
- `completed()` never ran, so the app was left on "Select a channel to
read it." instead of moving to the neighbouring channel.
- `observeRemoval` listeners didn't fire, so queued follow-ups for the
departed channel were kept.
It is intermittent in production because the main trigger is a race
between the 44101 hint's full-roster read and the leave's own exact
confirmation read. CI missed it because the browser fixture's 9022
handler never pushes anything live.
**Delete and archive are affected too.** Delete confirms through the
same loop and also revokes the viewer's access. Archive can hit the race
when another channel's access changes during its confirmation. The fix
covers all three, because it applies to every published lifecycle
command.
## Fix
One production file, `src/features/relay/channel-lifecycle.ts`
(+48/−34).
- **Access loss no longer cancels a published command.** Lifecycle
scopes now record publication, and `cancel(ids)` / `cancel()` skip
published commands. Cancelling on access change is meant to stop
permission checks. Once a command is published there's nothing left to
authorise, and losing access is usually the command's own effect.
- **Retired confirmation reads are read again.** If the shared reader
retires a confirmation read as cancelled, the read is issued again under
the same 20 s deadline, as `load()` already does. One `reread(signal,
attempt)` helper now owns this rule for both paths. It yields a
macrotask before each retry, so a reader that rejects without one can't
starve the deadline timer and freeze the renderer.
Unchanged: the strong exact read is still the only confirmation, and
`PublishRejected` is still a real failure.
### What still stops a published command
These still abort it and still end as `ChannelLifecycleUnconfirmed`,
with nothing removed:
- the caller's own signal
- the 20 s deadline
- session `clear()`
- session `dispose()`
## Before / after
Both builds are recorded side by side in WebKit (browser harness,
fixture data only), with **Channel settings → Leave channel → confirm**.
In both, the test relay pushes the updated roster live before it
acknowledges the leave.
- **Before**, at merge base `3fabf1be4`: the row vanishes and "Leave
channel failed … Fetch is aborted" stays on screen. Nothing is selected.
- **After**: "Channel left: Lifecycle channel", and Beta is selected.
Each build sent exactly one 9022.
https://github.com/user-attachments/assets/38201361-9781-417d-8d00-1387c673a5b4

The after arm was recorded at `335430a61`, before the branch was rebased
onto `e2f29cccf`. `git range-diff` shows its 3 commits are identical to
this PR's (`8b22b05ed`, `fdd7bc892`, `3cf2b8894`). The live push came
from an uncommitted scratch fixture patch. The patch stands in for the
production 44101 path, which the fixture relay can't route.
## Review
Two rounds of agent review, run before this PR was opened:
1. **On `8b22b05ed`:** the fix was judged correct, with one fragile
invariant. The reread loop was bounded only while each retired read gave
the event loop a turn. A reader that rejected without a macrotask, which
a closed reader does, would retry entirely in microtasks, so the 20 s
timeout could never fire. The review also suggested hoisting one helper
shared with `load()`'s identical loop, renaming the parameter that
shadowed the module's `read()`, and testing the deadline directly.
`fdd7bc892` addresses all three.
2. **On `fdd7bc892`:** all three earlier points are resolved, with no
regression from the shared helper. An optional suggestion was to add
join to the survivor matrix, since join is the one action whose
surviving confirmation feeds `acceptDiscovery` after `revokeAccess`.
`3cf2b8894` adds that case and also renames the "synchronously" deadline
case to "without a macrotask", which is what it actually tests.
Neither round raised a blocker.
## Tests
- `membership-outbox`: the relay announces a leave live before
acknowledging it, by roster push, by hint (whose refresh retires the
held confirmation read) or by CLOSED. In each case the leave resolves,
removes the channel and publishes once.
- `channel-lifecycle`: a scoped cancel or a full cancel during a
published leave, delete or join, in publication or in a retired
confirmation read, still confirms. A surviving join accepts only the
roster from the post-revocation read. `clear`, `dispose` and caller
abort stay unconfirmed and remove nothing. If every confirmation read is
retired, the command is still pending at 19,999 ms and ends
`ChannelLifecycleUnconfirmed` at 20 s, on a controlled clock.
- Fail-before:
- All 11 leave/delete survivor cases fail without the fix.
- Without the reread, the 4 confirmation-read cases and the hint case
still fail.
- Without the yield, the "without a macrotask" deadline case fails.
- If the held read returns its pre-revocation roster instead of being
retired, the scoped-cancel and cancel join cases fail.
- No browser journeys were added or removed.
Validated locally: vitest over `src/features/relay`,
`src/features/channels`, `src/features/channel-navigation` and
follow-up-queue (144 files, 2963 passed, 4 skipped); `tsc --noEmit`;
`biome check --error-on-warnings`.
## Verification scope
**This change has been verified only in unit tests and in the WebKit
browser harness against a synthetic relay.** It has not been run in the
desktop app or against a production relay, and no human has tested it
yet. The main production trigger, the 44101 race, is covered only by the
session-level unit test, because the browser fixture can't model it. The
native app's failure-toast suffix (the abort reason after "trying
again.") hasn't been checked.
## Test plan
- [x] Session-level and lifecycle unit tests above (local)
- [x] Before/after leave in the WebKit browser harness with a live
roster push (video above)
- [ ] Desktop app against a real relay (human), steps below
Desktop app against a real relay:
1. Join a channel you can leave, open it, then choose **Channel actions
→ View channel details → Leave channel** and confirm.
- **Expected:** a brief "Leaving channel…" toast, then **"Channel left:
\<name\>"**. The channel leaves the sidebar, and the neighbouring
channel is selected.
- **Bug:** "Leave channel failed" appears, or the app stays on "Select a
channel to read it."
2. Repeat step 1 several times. The production trigger is a race, so a
single success isn't conclusive.
3. In a channel you own, run **Delete channel**.
- **Expected:** "Channel deleted: \<name\>", with no "Delete channel
failed" toast.
4. In a channel you own, run **Archive channel** and confirm.
- **Expected:** "Channel archived: \<name\>", with no "Archive channel
failed" toast.
## Deferred
- **Double revocation.** When the race fires, `removed(id)` runs after
access was already revoked, so `denyChannel` repeats a revocation pass
for the same channel. That retires other in-flight shared reads once
more. Review judged it harmless (extra work only), so it is left as a
follow-up to keep this change small.
- **Browser fixture live roster push.** Not added. The session-level
test drives the real session's live callbacks deterministically, the
dialog's error mapping is unchanged, and the fixture can't model the
production 44101 path.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Signed-off-by: Matt Toohey <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>1 parent 9f14241 commit 0b2dfbf
4 files changed
Lines changed: 266 additions & 94 deletions
File tree
- docs
- src/features/relay
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
559 | 559 | | |
560 | 560 | | |
561 | 561 | | |
562 | | - | |
563 | | - | |
| 562 | + | |
| 563 | + | |
564 | 564 | | |
565 | 565 | | |
566 | | - | |
| 566 | + | |
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
165 | 183 | | |
166 | 184 | | |
167 | 185 | | |
| |||
765 | 783 | | |
766 | 784 | | |
767 | 785 | | |
768 | | - | |
| 786 | + | |
769 | 787 | | |
770 | 788 | | |
771 | 789 | | |
| |||
775 | 793 | | |
776 | 794 | | |
777 | 795 | | |
778 | | - | |
779 | | - | |
780 | | - | |
781 | | - | |
| 796 | + | |
| 797 | + | |
782 | 798 | | |
783 | | - | |
784 | | - | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
785 | 806 | | |
786 | 807 | | |
787 | 808 | | |
| |||
884 | 905 | | |
885 | 906 | | |
886 | 907 | | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
887 | 912 | | |
888 | 913 | | |
889 | 914 | | |
| |||
1090 | 1115 | | |
1091 | 1116 | | |
1092 | 1117 | | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
1093 | 1257 | | |
1094 | 1258 | | |
1095 | 1259 | | |
| |||
1934 | 2098 | | |
1935 | 2099 | | |
1936 | 2100 | | |
1937 | | - | |
1938 | | - | |
1939 | | - | |
1940 | | - | |
1941 | | - | |
1942 | | - | |
1943 | | - | |
1944 | | - | |
1945 | | - | |
1946 | | - | |
1947 | | - | |
1948 | | - | |
1949 | | - | |
1950 | | - | |
1951 | | - | |
1952 | | - | |
1953 | | - | |
1954 | | - | |
1955 | | - | |
1956 | 2101 | | |
1957 | 2102 | | |
1958 | 2103 | | |
| |||
0 commit comments