Commit d650c97
committed
fix(sync[indicator]) Atomic spinner→permanent transition; close render race
why: Reporter saw a flicker (and occasionally a doubled
``✓ Synced clap`` line) when a repo finished. Two interacting causes:
1. ``_render_tty`` snapshotted state under ``_lock`` then released the
lock before the actual ``stream.write``. A concurrent ``stop_repo``
could clear the screen between the snapshot and the write, letting
the spinner thread paint a stale frame on top of the new state.
Rich avoids this by holding ``self._lock`` across every refresh tick
*and* re-checking ``done.is_set()`` inside the lock
(``rich/live.py:_RefreshThread.run``); the same pattern applies here.
2. ``stop_repo`` cleared the spinner, then the caller printed the
permanent line in a *separate* stream call. Even on a fast terminal
the spinner row blinks to blank between the two writes, which
reads as flicker. The atomic transition pattern (single
``\x1b[?2026h ... \x1b[?2026l`` block that erases the panel and
replaces the spinner row with the permanent line) eliminates the
flash.
what:
- ``_render_tty``: hold ``_lock`` from snapshot through the stream
write. Re-check ``self._active_repo`` under the lock at the top --
if it changed (``stop_repo`` ran), skip the tick entirely so a
stale frame never lands on screen.
- ``stop_repo`` gains an optional ``final_line: str | None`` argument
and now returns ``bool``. When the indicator is actively rendering
on a TTY *and* a ``final_line`` is given, build one atomic ANSI
block under the lock that walks up the panel rows, erases each
going down, and replaces the spinner row with ``final_line + \n``.
Returns ``True`` to tell the caller "I owned the print; skip your
``formatter.emit_text``" -- which is what kills the doubled
``✓ Synced clap`` artefact.
- Headless / disabled-indicator paths still return ``False`` so the
caller's ``formatter.emit_text`` keeps running unchanged.
- ``cli/sync.py``: replace the ``with indicator.repo(...)`` context
manager (which fired ``stop_repo()`` with no args before the
outcome was known) with manual ``start_repo`` + post-outcome
``stop_repo(final_line=permanent if is_human else None)``. Skip
the separate ``formatter.emit_text(permanent)`` when ``stop_repo``
reported it owned the print. Applies uniformly to the ``synced``,
``failed``, and ``timed_out`` branches.
- ``cli/sync.py`` exception path: any ``BaseException`` (incl. the
KeyboardInterrupt the SIGINT handler relies on) tears the indicator
down with ``stop_repo()`` (no replacement line) and re-raises so
the surrounding ``except KeyboardInterrupt`` in ``_sync_impl`` still
owns the partial-summary print.
- 4 new tests in ``tests/cli/test_sync_progress.py``:
``stop_repo(final_line=...)`` writes inside one synchronized-output
bracket and returns ``True``; the no-arg path returns ``False``;
non-TTY stays caller-owned even with a ``final_line``;
``_render_tty`` skips writes when the active repo was cleared
(the lock-protected stale-tick guard).1 parent 0eb04f2 commit d650c97
3 files changed
Lines changed: 278 additions & 60 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
177 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
178 | 196 | | |
179 | | - | |
| 197 | + | |
180 | 198 | | |
181 | 199 | | |
182 | 200 | | |
183 | 201 | | |
184 | 202 | | |
| 203 | + | |
| 204 | + | |
185 | 205 | | |
186 | 206 | | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
192 | 249 | | |
193 | 250 | | |
194 | 251 | | |
| |||
341 | 398 | | |
342 | 399 | | |
343 | 400 | | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
350 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
351 | 418 | | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
387 | 452 | | |
388 | 453 | | |
389 | 454 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1468 | 1468 | | |
1469 | 1469 | | |
1470 | 1470 | | |
1471 | | - | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
1472 | 1482 | | |
1473 | 1483 | | |
1474 | 1484 | | |
1475 | 1485 | | |
1476 | 1486 | | |
1477 | 1487 | | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
1478 | 1495 | | |
1479 | 1496 | | |
1480 | 1497 | | |
| |||
1491 | 1508 | | |
1492 | 1509 | | |
1493 | 1510 | | |
1494 | | - | |
1495 | | - | |
| 1511 | + | |
1496 | 1512 | | |
1497 | 1513 | | |
1498 | | - | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
1499 | 1518 | | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
1500 | 1522 | | |
1501 | 1523 | | |
1502 | 1524 | | |
| |||
1524 | 1546 | | |
1525 | 1547 | | |
1526 | 1548 | | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
1527 | 1556 | | |
1528 | 1557 | | |
1529 | 1558 | | |
1530 | 1559 | | |
1531 | 1560 | | |
1532 | 1561 | | |
1533 | 1562 | | |
1534 | | - | |
1535 | | - | |
1536 | | - | |
1537 | | - | |
| 1563 | + | |
| 1564 | + | |
1538 | 1565 | | |
1539 | 1566 | | |
1540 | 1567 | | |
| |||
1545 | 1572 | | |
1546 | 1573 | | |
1547 | 1574 | | |
1548 | | - | |
1549 | | - | |
| 1575 | + | |
1550 | 1576 | | |
1551 | | - | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
1552 | 1581 | | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
1553 | 1585 | | |
1554 | 1586 | | |
1555 | 1587 | | |
| |||
0 commit comments