Files
loki/drizzle/0042_stiff_sprite.sql
a74c5a4069 feat(orchestration): per-run dispatch attribution via work-level serialization (#128)
Two dispatches to one project used to merge into a single agent session:
the claim gate released the younger command on prompt DELIVERY (executed_at),
not run close, and one READY handoff then closed every open run with
identical summaries — close-the-loop could resolve feedback item B (and
email its visitor "your feedback shipped") off item A's work.

- claimNextPendingCommand: an older open run now blocks a younger
  dispatch/inject until it CLOSES (60-min stale floor unchanged). Derived-tab
  (sessionTab) runs are exempt in both directions so parallel worktree
  dispatch keeps working; no-runId lifecycle commands never block.
- purgeStalePendingCommands: gate-held commands (own run open + fresh) are
  exempt from the 20-min purge — purging them silently dropped the work and
  wedged the project; they become purgeable once their run closes.
- Runner ack (PATCH /api/control/commands/[id]): ok:true stamps
  payload.deliveredAt on the run (never startedAt — that's the serialization
  order); ok:false closes the run as error immediately so a failed dispatch
  can't head-of-line block the queue.
- Close paths: handoff-freshness floor is now deliveredAt ?? startedAt, and
  a run whose command is still queued (undelivered) is never closed by
  another run's handoff (close-sweep + /api/control both).
- Migration 0042: partial expression index on pending_commands
  ((payload->>'runId')) WHERE executed_at IS NULL.

Behavioral test vs local DB: 9/9 (block-until-close, lifecycle escape,
sessionTab exemptions both directions, purge exemption round-trip).

Co-authored-by: test <test@test>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-31 11:26:30 +02:00

1 line
129 B
SQL

CREATE INDEX "idx_pending_commands_open_run" ON "pending_commands" USING btree (((payload->>'runId'))) WHERE executed_at IS NULL;