fix(vector): propagate cancel in cleanup task; cover 403 + sweep-failure

Address round-1 review on #913 and the SonarCloud new_reliability_rating gate:

- credential_cleanup_task no longer catches the cancellation exception
  (Sonar python:S7497). A task-group cancel must propagate for structured-
  concurrency teardown; graceful shutdown still flows through shutdown_event,
  so the sleep no longer needs a cancel/break.
- Parametrize the scanner self-heal tests over 401 AND 403 (handled
  identically at both call sites) and add a test that a failing periodic
  sweep is logged non-fatally and does not crash the task.
- Log the stored-user count before the startup sweep (operability signal),
  add a debug line when the credential row was already gone, and document
  the at-most-one extra-401 convergence in _remove_stale_credential.

Refs Deck #198.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-16 19:23:46 +02:00
co-authored by Claude Opus 4.8
parent 3790cf6d60
commit 7a9e4a8681
3 changed files with 67 additions and 15 deletions
+9
View File
@@ -2076,6 +2076,15 @@ def get_app(transport: str = "streamable-http", enabled_apps: list[str] | None =
# drive an endless scanner re-spawn/401 loop (Deck #198). The
# credential_cleanup_task started below repeats it on a cadence.
try:
# Log the cohort first: the sweep makes one OCS validation
# call per stored user before readiness, so the count is the
# operability signal if startup latency ever climbs.
stored = await token_storage.get_all_app_password_user_ids()
if stored:
logger.info(
"Running startup credential sweep for %s stored user(s)",
len(stored),
)
removed = await token_storage.cleanup_invalid_app_passwords(
nextcloud_host=nextcloud_host_for_sync
)