fix(factory): local-E2E sync tolerance + Slack reply-watcher rehydration
Two related reliability fixes surfaced while proving the factory's local/internal-backend E2E (Linear AR-291 → triage → dispatch → pear PR #376).
1. Sync tolerance (commit b0bfe6c)
The relayfile-synced Linear/SDK payloads drop fields the factory relied on. Three tolerances so a real local run isn't rejected:
- Name-only state sync — synced payloads carry
state.namebut nostate.id; the factory matches state by UUID, so every issue was rejected as "not ready-for-agent". Backfill name→UUID via the state resolution + alinear.states(role→name) config, falling back to pinnedstateIdswhen the/linear/statescatalog is unreadable. - Label-less dispatch —
labelsis dropped by sync, so label-only dispatch (repos.byLabel) skipped every issue.labelDerivedDispatchDecisionnow falls back torepos.defaultas a single implementer. - Resource-less events — polling-fallback/degraded-sync
ChangeEvents arrive withoutresourcedespite the SDK type. A module-levelchangeEventPath()guard replaces everyevent.resource.pathread so one malformed event can't wedge the subscription handler.
Upstream issues filed for the root causes: relayfile-adapters#205 (synced record omits state.id + labels), relayfile#296 (SDK delivers ChangeEvent without resource).
2. Slack reply-watcher rehydration (commit 2e82dca)
The Slack reply watcher was only armed at dispatch/escalation and lived only as long as the dispatching process. On restart, the guard in #ensureSlackDispatchThread saw the persisted thread id and returned early without re-watching, so human replies in an existing dispatch thread were watched by nobody and dropped forever. The loop/run-once CLI paths never call start(), compounding it.
#rearmSlackReplyWatchers()— onstart()(both branches) and atrunLoop()init, re-arm a watcher for any in-flight issue with a persisted thread but no live watcher.#rearmSlackWatcher()— idempotent re-attach helper; counts genuine re-arms via aslackWatchersRearmedcounter.- The
#ensureSlackDispatchThread/#escalateTriageToSlackguards now re-arm when a thread exists but no watcher is live, instead of returning early.
Reply routing itself was already sound (handle → #readSlackReply → #routeSlackAnswerToImplementers → fleet.sendInput); this restores the watcher that feeds it across restarts.
Tests
npm run build + npx vitest run green (30 files, 499 tests). New focused coverage: guard re-arm on a persisted thread (no re-post), start() rehydration across a simulated restart routes a post-restart reply, and a negative case (no persisted thread → no re-arm).
🤖 Generated with Claude Code
Summary by cubic
Tolerates gaps in locally synced Linear payloads and rehydrates Slack reply watchers so local E2E runs keep dispatching and human replies are processed after restarts.
- Bug Fixes
- Name-only state sync: backfill
state.idfromstate.nameusing configuredlinear.states(per-team or global), with a graceful fallback to pinnedstateIdswhen/linear/statesis unreadable. - Label-less dispatch: when
labelsare absent in the synced record, fall back torepos.defaultand dispatch a single implementer (plus reviewer) instead of failing. - Resource-less events: added
changeEventPath()and replaced all directevent.resource.pathreads so subscriptions and the Slack reply watcher safely ignore malformed events from polling/degraded sync. - Slack reply watcher rehydration: on
start()and at loop init, re-arm watchers for in-flight issues that have a persisted thread but no live watcher; guards in#ensureSlackDispatchThreadand#escalateTriageToSlacknow re-attach instead of returning early. Tests cover re-arm on restart and the negative case (no persisted thread).
- Name-only state sync: backfill