Commit 11483fe
authored
fix: revive expired sessions with same ID to preserve provenance and dedup (#195)
* fix: revive expired sessions with same ID to preserve provenance and dedup
When a client reconnects after session expiry, handleExisting was calling
handleInitialize which generated a new random session ID. But MCP clients
(e.g. Claude Desktop) don't update their stored session ID from response
headers, so every subsequent request triggered another replacement —
breaking provenance tracking (0 tool calls) and enrichment dedup (never
fires).
Replace handleInitialize call with reviveSession that recreates the
session using the client's original ID. Delete-then-create avoids unique
constraint violations from expired-but-not-yet-cleaned rows.
* fix: remove dead ReplacedSessionID code and add upsert for revive race safety
Remove ReplacedSessionID/WithReplacedSessionID infrastructure that became
dead code after switching to same-ID session revival. The replaced-session
context value was never populated in the revive path, making the
harvestProvenance fallback and all related tests unreachable.
Add ON CONFLICT upsert to the Postgres session store's Create method so
concurrent revive attempts on the same expired session ID don't fail with
unique constraint violations.1 parent 957c3a6 commit 11483fe
File tree
5 files changed
+202
-161
lines changed- pkg
- middleware
- session
- postgres
5 files changed
+202
-161
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
| |||
124 | 122 | | |
125 | 123 | | |
126 | 124 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
136 | 128 | | |
137 | 129 | | |
138 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | 12 | | |
15 | 13 | | |
16 | 14 | | |
| |||
240 | 238 | | |
241 | 239 | | |
242 | 240 | | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | 241 | | |
311 | 242 | | |
312 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | 18 | | |
23 | 19 | | |
24 | 20 | | |
| |||
34 | 30 | | |
35 | 31 | | |
36 | 32 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | 33 | | |
54 | 34 | | |
55 | 35 | | |
| |||
63 | 43 | | |
64 | 44 | | |
65 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
66 | 49 | | |
67 | 50 | | |
68 | 51 | | |
| |||
112 | 95 | | |
113 | 96 | | |
114 | 97 | | |
115 | | - | |
| 98 | + | |
116 | 99 | | |
117 | 100 | | |
118 | 101 | | |
| |||
128 | 111 | | |
129 | 112 | | |
130 | 113 | | |
131 | | - | |
| 114 | + | |
132 | 115 | | |
133 | 116 | | |
134 | 117 | | |
| |||
151 | 134 | | |
152 | 135 | | |
153 | 136 | | |
154 | | - | |
| 137 | + | |
155 | 138 | | |
156 | 139 | | |
157 | 140 | | |
158 | 141 | | |
159 | | - | |
160 | | - | |
161 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
162 | 147 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
167 | 157 | | |
168 | 158 | | |
169 | 159 | | |
| |||
200 | 190 | | |
201 | 191 | | |
202 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
203 | 215 | | |
204 | 216 | | |
205 | 217 | | |
| |||
0 commit comments