Skip to content

fix(threads): queue background-task continuations behind a running turn - #630

Merged
nixuuu merged 1 commit into
devfrom
fix/queue-task-continuations
Nov 13, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/queue-task-continuations

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Two background-task completions could race a dispatched continuation or a provider wake-up and show a failed Work turn with THREAD_ERROR: a turn of this thread is already running. Notes now follow the existing steer/queue policy: a running turn receives a platform steer; notes arriving while its StartTurn is dispatched wait durably for turn_started instead of creating another continuation or speculative steers. Otherwise notes queue a continuation. Notes in a batch keep (ended_at, item_id) order.

Worker admission serializes StartTurn per thread without blocking control commands. Durable admission receipts prevent the same turn from executing again after restart, even with a fresh command ID. The gateway atomically requeues busy refusals with the same turn, input, note bindings, ordinal and expiry, logs the retry, and increments diagnostics metric 44. Recovery also dispatches note turns/steers committed before a gateway crash.

Related: #620, merged into dev; this branch is rebased onto 464fffffa. This builds on its task-end cancellation, ingest queue, ThreadLifecycle snapshots/deltas and Claude wake suppression, without changing core-workers.ts or those mechanisms. The stop query in thread-lifecycle.ts additionally interrupts dispatched queued starts before the running turn. Worker admission retains the lifecycle guard after waiting and rechecks it before provider admission; durable interrupt receipts also fence a cancelled turn after unarchive/restart. Diagnostics 41–43 remain unchanged; this adds 44. No PostgreSQL migration or protocol change is added.

Validation:

  • All CI checks are green for 4865aa66fbd88dbd10abe40369c6eb1be787d369: static checks, all four test shards through check:tmp, web/Linux builds, aggregate validation and commitlint. CI run. Tests (2/4) passed after one rerun of a missed SQL lock-wait observation in thread-range-send-locks.test.ts; that test also passed in the local full run without changes.
  • Local handover checks ran with nice -n 10: install, gen:check, typecheck, lint, format:check and web build passed. The worktree is clean.
  • Focused gRPC runs passed: 16 collision/background-note tests; 13 collision/admission tests covering ordered execution, controls, gateway/worker restart deduplication, archive, unarchive and new work. The real Claude archived-background regression from fix(gateway): stop worker reconnect loops on archived thread events #620 and journal receipt tests also passed. Temp directories were clean.
  • Local full sequential check:tmp --timeout 30000: 2722 passed, 166 skipped, one failed across 509 files; temp directory clean. The unrelated config-sync-projects.test.ts origin-attachment assertion returned attached=false. Its entire file then passed separately (12 tests, 92 assertions), with temp cleanup clean. The complete CI suite is green; no unrelated production code or test deadlines were changed.

Copy audit (§8): no metric → “Turn starts requeued”, a sentence-case diagnostics counter explaining internal retries. Existing “Could not finish this turn” remains for actual failures; busy collisions no longer produce it. No controls or layout changed.

@nixuuu
nixuuu force-pushed the fix/queue-task-continuations branch from 513615d to 8359a8d Compare November 13, 2026 10:13
@nixuuu
nixuuu force-pushed the fix/queue-task-continuations branch from 8359a8d to 4865aa6 Compare November 13, 2026 10:30
@nixuuu
nixuuu marked this pull request as ready for review November 13, 2026 11:02
@nixuuu
nixuuu merged commit b68c157 into dev Nov 13, 2026
18 of 20 checks passed
@nixuuu
nixuuu deleted the fix/queue-task-continuations branch November 13, 2026 11:03
nixuuu added a commit that referenced this pull request Nov 13, 2026
## Projekt workspace'u — zaakceptowany układ v2

Podgląd plików przechodzi z modala do zakładek jednego wątku. Sygnet
projektu, skracany tytuł i karty dzielą rząd nagłówka, z aktywną kartą
zawsze widoczną i przełącznikiem overflow. Prawy rail obsługuje jeden
minimalny moduł. Bez modułu podsumowanie jest dokowane i widoczne; z
modułem jest zamkniętą domyślnie kartą pływającą. Na wąskich ekranach
obie powierzchnie używają arkuszy.

Użytkownik zaakceptował układ v2 i udzielił jawnej zgody na
implementację. Przyjęte decyzje: jeden zastępowalny czysty preview,
utrwalany przez Edit/Keep tab/dwuklik, zakres cwd/worktree wątku i
mobilna edycja natywna bez kolorów podczas pisania (kolory w viewerze i
Preview changes). Usunięto sekcję otwartych decyzji.

Dokument uwzględnia jeden przycisk menu wiersza (#608), zachowanie
treści PR przy odświeżaniu (#611), bounded warming/cache transkryptu
(#622/#623/#629), niezależne sortowanie sidebara (#617/#619/#626),
kompaktowy tekst stanów preview (#634), poprawne stany ChoiceControl
(#637), kolejkę kontynuacji (#630) i podsumowania jej wierszy (#633).
Nie dodaje pełnych snapshotów ani prefetch plików podczas warming.

Siedem kompletnych warstw będzie osobnym stosem z podstawą dev.
Wszystkie PR implementacyjne pozostaną draftami do ukończenia i
weryfikacji całości oraz wspólnego scalenia przez maintenera. Migracje
muszą zachować monotoniczność względem aktualnego dev. Dokumentacyjny PR
po zielonym CI jest gotowy do scalenia przez maintenera.

## Weryfikacja i ograniczenia

- Rebase na dev `1626a3e6b05494e7aec77942bd818950468a3b58` bez
konfliktów.
- `nice -n 10 bun run format` i `nice -n 10 bun run format:check`
przeszły. Konfiguracja pomija Markdown; dokument sprawdzono ręcznie.
`git diff --check` bez błędów po usunięciu pustej linii końcowej.
- Brak zmian kodu aplikacji i kontraktów; testy wykonania oraz pomiary
budżetów należą do stosu implementacyjnego.
- Samodzielna makieta v2 poza repozytorium, 32 435 bajtów, przezroczyste
html/body, trzy stany × trzy szerokości × dwa motywy. Poprzednio
wyrenderowana i obejrzana bez błędów konsoli.

## Copy audit (§8)

Brak zmian produkcyjnych etykiet. Projekt zachowuje `Thread`, `Keep
tab`, `Thread details`, `Open in tab`, `Collapse panel` / `Show panel`
oraz dostępne nazwy obu kontekstów `+`. Zachowuje jeden przycisk menu
wiersza i kompaktowy tekst statusów pliku. Krótkie i długie etykiety są
pokazane w makiecie; rzeczywiste powierzchnie i stany będą audytowane w
każdej warstwie UI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant