fix(factory): local-E2E sync tolerance + Slack reply-watcher rehydration

Merged
KH
6mo ago
+438-35

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.name but no state.id; the factory matches state by UUID, so every issue was rejected as "not ready-for-agent". Backfill name→UUID via the state resolution + a linear.states (role→name) config, falling back to pinned stateIds when the /linear/states catalog is unreadable.
  • Label-less dispatch — labels is dropped by sync, so label-only dispatch (repos.byLabel) skipped every issue. labelDerivedDispatchDecision now falls back to repos.default as a single implementer.
  • Resource-less events — polling-fallback/degraded-sync ChangeEvents arrive without resource despite the SDK type. A module-level changeEventPath() guard replaces every event.resource.path read 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() — on start() (both branches) and at runLoop() 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 a slackWatchersRearmed counter.
  • The #ensureSlackDispatchThread / #escalateTriageToSlack guards 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.id from state.name using configured linear.states (per-team or global), with a graceful fallback to pinned stateIds when /linear/states is unreadable.
    • Label-less dispatch: when labels are absent in the synced record, fall back to repos.default and dispatch a single implementer (plus reviewer) instead of failing.
    • Resource-less events: added changeEventPath() and replaced all direct event.resource.path reads 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 #ensureSlackDispatchThread and #escalateTriageToSlack now re-attach instead of returning early. Tests cover re-arm on restart and the negative case (no persisted thread).