Commit f921147
fix(core): restore sessions and propagate errors on session/within/retryTo error paths
Fixes four of the latent error-path divergences characterized in #5622, by
making the error paths symmetric with the success paths. The characterization
assertions are updated to the corrected behavior in the same commit.
- within() async error (lib/effects.js): the catch now calls finishHelpers()
(so helpers' _withinEnd runs on error, not just success) and returns
recorder.promise() (so the error propagates through within() instead of being
detached onto a trailing task that a caller awaiting within() never sees).
- session() async error (lib/session.js): the catch now calls finalize() — the
same cleanup the success path uses (awaited restoreVars + recorder.session
.restore) — instead of an ad-hoc cleanup that never restored the recorder
session, leaking the session id after an error.
- session() sync error (lib/session.js): the finally recorder.catch now calls
recorder.session.restore before re-throwing. finalize()'s restore task is
skipped on a rejected chain, so the catch handler is the only place that can
restore the session id on the sync-throw path.
- retryTo() (lib/effects.js): a thrown callback no longer reject()s the outer
promise prematurely — it routes through recorder.throw so the retry logic
owns the outcome (retry, or reject once maxTries is exhausted). A callback
that throws then succeeds on a later attempt now resolves instead of
rejecting. tries now starts at 1 on the first attempt (was 2); the retry
count is preserved (tries < maxTries).
Verified: unit 748/0, runner 273/0 (incl. all retryFailedStep/rerun tests),
acceptance within/session/els all green.
Not changed here (would be unsafe or out of scope, see PR):
recorder.retries clearing (retryFailedStep depends on it), the stopped-recorder
no-op contract, and nested cross-level restore ordering.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 5f51d3e commit f921147
3 files changed
Lines changed: 41 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
203 | 205 | | |
204 | 206 | | |
205 | 207 | | |
206 | | - | |
| 208 | + | |
207 | 209 | | |
208 | 210 | | |
209 | 211 | | |
| |||
216 | 218 | | |
217 | 219 | | |
218 | 220 | | |
219 | | - | |
| 221 | + | |
220 | 222 | | |
221 | 223 | | |
222 | 224 | | |
| |||
228 | 230 | | |
229 | 231 | | |
230 | 232 | | |
231 | | - | |
| 233 | + | |
232 | 234 | | |
233 | 235 | | |
234 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
110 | | - | |
111 | | - | |
| 109 | + | |
112 | 110 | | |
113 | 111 | | |
114 | 112 | | |
| |||
124 | 122 | | |
125 | 123 | | |
126 | 124 | | |
| 125 | + | |
127 | 126 | | |
128 | 127 | | |
129 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | 103 | | |
105 | 104 | | |
106 | | - | |
| 105 | + | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
118 | 116 | | |
119 | 117 | | |
120 | | - | |
121 | | - | |
| 118 | + | |
| 119 | + | |
122 | 120 | | |
123 | 121 | | |
124 | 122 | | |
| |||
134 | 132 | | |
135 | 133 | | |
136 | 134 | | |
137 | | - | |
| 135 | + | |
138 | 136 | | |
139 | 137 | | |
140 | 138 | | |
141 | 139 | | |
142 | | - | |
143 | | - | |
144 | | - | |
| 140 | + | |
145 | 141 | | |
146 | 142 | | |
147 | | - | |
| 143 | + | |
148 | 144 | | |
149 | 145 | | |
150 | 146 | | |
151 | 147 | | |
152 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
153 | 169 | | |
154 | 170 | | |
155 | 171 | | |
| |||
165 | 181 | | |
166 | 182 | | |
167 | 183 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 184 | + | |
| 185 | + | |
173 | 186 | | |
174 | | - | |
175 | | - | |
176 | | - | |
| 187 | + | |
| 188 | + | |
177 | 189 | | |
178 | 190 | | |
179 | 191 | | |
| |||
0 commit comments