Repository navigation
fix(gateway): stop worker reconnect loops on archived thread events - #620
Merged
Merged
Conversation
nixuuu
force-pushed
the
fix/gateway-worker-event-recovery
branch
2 times, most recently
from
November 13, 2026 09:42
2a59f87 to
6eef63d
Compare
Isolate event persistence per thread, resolve archived and deleted backlogs durably, and retain legacy delivery until the gateway is upgraded. Add redacted ingest diagnostics and recovery coverage. Related: #51
nixuuu
force-pushed
the
fix/gateway-worker-event-recovery
branch
from
November 13, 2026 09:45
6eef63d to
aa005da
Compare
nixuuu
marked this pull request as ready for review
November 13, 2026 10:08
This was referenced Nov 13, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 13, 2026
Adds owner-scoped manual sidebar positions with one thread write per move. New threads receive a fractional key before existing threads; old rows fall back to creation order without a backfill. Adds a separate last-agent-reply timestamp and device-local sorting preference. The stack is rebased on dev `464fffffa` (#620). Migration `0133_thread_order` follows `0132_worker_ingest_outcomes`; the registration, expected schema list and Polish documentation use 0133. Number 0134 is left free for the thread-cache warming stack. The schema/order checks passed 28/28 after this rebase. Validation (commands run with `nice`): installation, generated-code check, full typecheck, lint, formatting and web build passed. Focused gateway order and schema checks passed 28/28; they cover ownership, invalid/stale bounds, concurrent moves, key growth, old rows, durable reads, new-thread placement and reply timestamps. CI passed on all three rebased heads, including every test shard, static checks and builds. The PRs remain drafts at the maintainer's request. Native gesture checks are deferred to nightly testing and do not block this handoff. Local failure investigation: the earlier full run had 2690 pass, 166 skip and one transient checkout-alias busy-directory rejection. Later runs under heavy host load hit 5-second deadlines and linked-computer heartbeat/disconnection failures. None of the ten failing test files is changed by this stack. All ten were then rerun **one file at a time, with the default timeouts**, through `nice -n 10 bun run check:tmp`: **85 pass, 0 fail**. The move file includes all 20 repeated history/file transfers plus its restart, owner and move-all cases. No production code, tests or timeout values were changed to obtain these results. Earlier linked-computer failures also reproduced on original base `38214a54c` without this feature. | Isolated file | Passed | |---|---:| | `scripts/channel-identity.test.ts` | 3 | | `scripts/release.test.ts` | 18 | | `tests/integration/ask-user.test.ts` | 13 | | `tests/integration/bench-plans.test.ts` | 1 | | `tests/integration/bot-outgoing-files.test.ts` | 6 | | `tests/integration/bot-workspace.test.ts` | 4 | | `tests/integration/bot-view-deltas.test.ts` | 5 | | `tests/integration/composer-shell-linked.test.ts` | 1 | | `tests/integration/thread-branches.test.ts` | 8 | | `tests/integration/computer-moves.test.ts` | 26 | Every isolated `check:tmp` run reported nothing left in its private temp directory. The complete local suite was not rerun after this investigation; the full-suite evidence is the green CI on each current head. Remote thread positions remain editable at their home and travel through incremental metadata replication. Polish API, data-model and linked-computer docs define grouping and Working behavior. Copy audit (§8): no UI surface is added in this layer. New gateway errors state the problem and an action (for example, absent → “The order changed elsewhere. Refresh the list and try again.”). Sort choice labels use sentence case and existing terminology. Width/theme checks belong to the web layer.
nixuuu
added a commit
that referenced
this pull request
Nov 13, 2026
…rn (#630) 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](https://github.com/itsoltech/canopy/actions/runs/43409611147). 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 #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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A background task can outlive its thread's archive. When Claude reports its completion by starting a native follow-up turn, the visibility trigger rejects it. The previous ingest drain disconnected the entire worker every 11 seconds and interrupted unrelated running turns.
Archived threads now retain late output for existing turns and background-task state, while completion notes are durably cancelled in the task-end transaction. Background processes keep running; neither the platform note nor a native Claude follow-up starts a new turn after archive. Unarchiving shows the completed task without replaying its continuation. An additive lifecycle snapshot/live message tells capable workers to suppress native wakes and stale StartTurn commands; snapshot ordering preserves newer lifecycle updates.
Gateway ingest resolves older journals automatically: unknown archived turns become durable quarantine notices; deleted threads receive only an ACK cursor, without retaining new payload/history/quarantine or resurrecting the thread. Other storage failures retry per thread with backoff, then quarantine the original event. An unavailable durable fallback retains the worker journal without draining the connection.
WorkerLink protocol remains 1. Old workers recover against the new gateway. New workers encountering an old gateway's ingest drain durably defer all then-unacknowledged journals (the old message identifies no offending thread) and resume them when the gateway is upgraded. Diagnostics recognize failed, dropped, quarantined and deferred ingest templates, redact thread/worker IDs and payloads, and expose aggregate counters. Polish execution, lifecycle, durability, protocol and diagnostics documentation describes the policy.
Validation:
Copy audit (§8): adds sentence-case diagnostic labels (“Event storage failures”, “Events dropped after deletion”, “Events quarantined”, “Journals deferred until gateway update”) and the plain timeline notice “Automatic follow-up skipped because this thread is archived or deleted.” The notice explains why work did not start and contains no user content or identifiers. No controls/layout changed; no browser verification was performed.
Related: #51