Commit 931252c
* Drop SessionRegistry threading.RLock — single asyncio loop, YAGNI
Closes #350 (Audit v2 finding #6).
The RLock provided no asyncio-level mutual exclusion (it wasn't awaited)
and the only callers run inside the single asyncio WS handler — single
event loop, no thread crossings. It misled readers into assuming
thread-safety the registry doesn't deliver. If a future caller ever runs
from another thread, asyncio.Lock is the right answer for this
async-first code, not threading.RLock — so the existing lock wasn't even
the future-proof choice.
Removed:
- `from threading import RLock`
- `self._lock = RLock()`
- every `with self._lock:` block (10 sites)
Renamed `_find_matching_session_locked` → `_find_matching_session` since
the "_locked" suffix is now misleading. Updated the wait_for_session
docstring's "registry lock" reference.
Added a class docstring on SessionRegistry making the asyncio-only
invariant explicit and naming asyncio.Lock as the future-proof choice
should a thread crossing ever appear.
Tests: TestSessionRegistryNoThreadingLock pins the deletion against
accidental re-introduction (no `_lock` attribute, no `threading` /
`RLock` imported in the module). All 28 test_session_registry.py tests
plus the full 769-test pytest suite pass. Live smoke: GDScript
test_run via MCP against a real Godot 4.6.2 editor — 1157 passed, 0
failed (registry exercised end-to-end via session_manage list,
editor_state, and every test that round-trips through the WS handler).
Refs umbrella #343.
https://claude.ai/code/session_optimistic-tesla-84obZ
* Trim docstrings + drop narrating comment per /simplify
- SessionRegistry class docstring: trim 5 lines re-litigating the removed
RLock down to 3 lines stating the asyncio-only invariant and the
forward-looking choice (asyncio.Lock).
- TestSessionRegistryNoThreadingLock: collapse the 7-line docstring into
one line — test names already convey the invariant.
- Drop "# Notify any waiters blocked on wait_for_session()" — the loop
body, the to_notify name, and future.set_result(session) already say
this. Per CLAUDE.md, avoid comments narrating WHAT.
https://claude.ai/code/session_optimistic-tesla-84obZ
* Drop prescriptive cross-thread advice from docstrings (Copilot review)
asyncio.Lock is a cooperative-scheduling primitive within a single
event loop — it does NOT make cross-thread access safe. Recommending
it as the future-proof choice for a hypothetical thread crossing was
misleading and would steer the next maintainer toward the wrong fix.
Drop the "use asyncio.Lock" prescription entirely. Class docstring now
states only the current invariant (single asyncio loop, no locking).
Test docstring trimmed to neutral framing.
If a thread crossing is ever genuinely introduced, the right answer is
to marshal through the event loop (asyncio.run_coroutine_threadsafe /
loop.call_soon_threadsafe), not to add a lock — but that decision
belongs to whoever has the actual cross-thread requirement, not to
this docstring.
https://claude.ai/code/session_optimistic-tesla-84obZ
* Cover the done-waiter skip branch in register() (Codecov patch)
The if future.done(): continue branch in register() was uncovered;
Codecov flagged it as the one missing line in the patch. Added a
regression test that pre-completes a future, sticks it in
_session_waiters, and verifies the next register() doesn't re-resolve
it. This pins the "don't double-resolve out-of-band-completed waiters"
invariant that was previously untested.
https://claude.ai/code/session_optimistic-tesla-84obZ
---------
Co-authored-by: Claude <noreply@anthropic.com>
1 parent aac5483 commit 931252c
2 files changed
Lines changed: 80 additions & 61 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
75 | 74 | | |
76 | 75 | | |
77 | 76 | | |
78 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
86 | | - | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
127 | 126 | | |
128 | 127 | | |
129 | 128 | | |
130 | 129 | | |
131 | 130 | | |
132 | 131 | | |
133 | 132 | | |
134 | | - | |
135 | | - | |
| 133 | + | |
136 | 134 | | |
137 | 135 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
142 | 139 | | |
143 | 140 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
148 | 144 | | |
149 | 145 | | |
150 | | - | |
151 | | - | |
| 146 | + | |
152 | 147 | | |
153 | 148 | | |
154 | 149 | | |
155 | | - | |
156 | | - | |
| 150 | + | |
157 | 151 | | |
158 | 152 | | |
159 | 153 | | |
| |||
166 | 160 | | |
167 | 161 | | |
168 | 162 | | |
169 | | - | |
| 163 | + | |
170 | 164 | | |
171 | 165 | | |
172 | 166 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
187 | 178 | | |
188 | 179 | | |
189 | 180 | | |
190 | 181 | | |
191 | 182 | | |
192 | | - | |
193 | | - | |
| 183 | + | |
194 | 184 | | |
195 | 185 | | |
196 | 186 | | |
197 | | - | |
| 187 | + | |
198 | 188 | | |
199 | 189 | | |
200 | 190 | | |
| |||
228 | 218 | | |
229 | 219 | | |
230 | 220 | | |
231 | | - | |
232 | | - | |
| 221 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
127 | 141 | | |
128 | 142 | | |
129 | 143 | | |
| |||
221 | 235 | | |
222 | 236 | | |
223 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
224 | 254 | | |
225 | 255 | | |
226 | 256 | | |
| |||
0 commit comments