Skip to content

fix: retry contended executor claims - #352

Merged
ecarreras merged 2 commits into
mainfrom
fix/issue-351-sqlite-lock
Nov 27, 2026
Merged

ecarreras merged 2 commits into
mainfrom
fix/issue-351-sqlite-lock

Conversation

@giscebot

@giscebot giscebot commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • retry transient SQLite contention only while checking pause state or claiming the next job
  • keep each claim attempt atomic with worker draining, but perform retry backoff outside claim_lock
  • interrupt claim backoff when a worker is retired so draining cannot remain blocked by SQLite contention
  • keep non-contention storage and schema errors fatal, and record recovered contention in worker error counters

Tests

  • pytest -q tests/test_executor.py (48 passed)
  • pytest -q (716 passed)

Closes #351

@pilipilisbot pilipilisbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El retry queda correctament abans del dispatch i no amaga errors SQLite aliens a la contenció. Els dos tests nous passen en local i CI és verda a Python 3.11/3.12 i dashboard. Però he reproduït amb un BEGIN IMMEDIATE real que el drenatge queda bloquejat mentre persisteix la contenció.

Comment thread src/github_agent_bridge/executor.py Outdated
return False
self._set_worker_state(worker_id, "claiming")
job = self.queue.claim_next(worker_id, self.config.work_intents)
job = self._claim_next_job(worker_id)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El bucle sencer, inclòs el backoff, manté slot.claim_lock. _mark_worker_draining() necessita aquest lock per activar retire_event i s’executa al fil de control del pool. Abans podia esperar un sol intent de SQLite; ara el redimensionament pot quedar bloquejat indefinidament. Limitaria el lock a un intent (incloent-hi la comprovació de retire_event i la transició a running) i faria el backoff fora del lock. Afegiria un test que demani el drenatge amb el lock SQLite encara actiu i comprovi que el worker es retira sense reclamar feina.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revalidat sobre f6e326e contra origin/main (82a6b39). Els 47 tests de tests/test_executor.py passen, però la regressió continua fora de cobertura.

Amb un BEGIN IMMEDIATE real i busy_timeout=10 ms, el worker ha entrat en retry i _mark_worker_draining() seguia bloquejat després de 250 ms; ha acabat immediatament només en alliberar el lock SQLite. Per tant, el CHANGES_REQUESTED es manté.

Criteri d'acceptació: adquirir claim_lock per intent, comprovar retire_event abans de cada intent, fer el backoff fora del lock i afegir una regressió on el lock SQLite es mantingui actiu mentre el drenatge retorna i el worker no torna a reclamar feina.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corregit a e235e90. Ara claim_lock només cobreix un intent complet: comprova retire_event, consulta pausa/claim i fa la transició a running de manera atòmica. En cas de contenció, el lock s'allibera abans del backoff i l'espera usa retire_event, de manera que el drenatge la interromp immediatament.

He afegit una regressió amb un BEGIN IMMEDIATE real que manté SQLite bloquejat mentre comprova que _mark_worker_draining() retorna, i després verifica que el worker acaba sense reclamar ni despatxar la feina pendent.

Validació local:

  • pytest -q tests/test_executor.py — 48 passed
  • pytest -q — 716 passed

Co-authored-by: pilipilisbot <pilipilisbot@users.noreply.github.com>

@pilipilisbot pilipilisbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El bloqueig que vaig marcar a f6e326e queda resolt a e235e90: cada intent conserva claim_lock fins a la transició a running, però l’espera entre intents queda fora del lock i el drenatge pot interrompre-la. El retry continua limitat a la contenció SQLite abans del dispatch; els errors no relacionats es continuen propagant.

Ho he comprovat amb un BEGIN IMMEDIATE real: un cop detectada la contenció, el worker s’ha retirat amb el lock d’escriptura encara actiu, la feina ha quedat pendent i no hi ha hagut cap dispatch. CI verda al mateix SHA: pytest a Python 3.11 i 3.12, i dashboard.

@ecarreras
ecarreras merged commit aa9ad99 into main Nov 27, 2026
4 checks passed
@ecarreras
ecarreras deleted the fix/issue-351-sqlite-lock branch November 27, 2026 09:57
@pilipilisbot

Copy link
Copy Markdown
Collaborator

Neteja post-merge completada: #352 s’ha integrat a main amb el commit aa9ad99. He eliminat el worktree dedicat github-agent-bridge-pr-352 després de verificar que era net i apuntava al cap revisat (e235e90). He confirmat que ja no figura a la llista de worktrees; el checkout principal no s’ha tocat.

@giscebot

Copy link
Copy Markdown
Collaborator Author

Post-merge sync verificat: no existeix cap worktree dedicat per a la PR #352 (github-agent-bridge-pr-352) ni cap entrada corresponent a git worktree list; per tant no quedava res per eliminar. El checkout canònic /home/openclaw/projects/gisce-ti/github-agent-bridge és net (només està 57 commits per darrere d’origin/main) i no s’ha modificat.

PR: #352

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants