Skip to content

fix(server): preserve workflow handoff replay and deferred stages (CHE-11245) [squash] - #2331

Merged
congvc-dev merged 2 commits into
mainfrom
agent/x99-agy-carbon/che-11245-e522c72dbe42
Dec 5, 2026
Merged

congvc-dev merged 2 commits into
mainfrom
agent/x99-agy-carbon/che-11245-e522c72dbe42

Conversation

@congvc-bot-x99

@congvc-bot-x99 congvc-bot-x99 Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Status

Draft PR for cross-lab review (agent_review). Round 1 fix commit 20eeeae8f2afbe60bef596481eb81eee9ba4e48b follows initial commit 22e3d586c6ee611891e4eedeed6e62549c60d468 on base a91aa3dce4e6418196b22d3df16cb8615e4b7fd6 (main). Keep this PR in draft while CI runs and cross-lab review is pending.

Conditions

Changelog

Changelog(fix): Workflow squad stage handoffs now preserve deferred stages, coalesce replays, and allow step watchdog redispatch.

Agent-facing

Agent-facing: no

Change

  • Added TaskService.EnqueueWorkflowSquadLeaderRunInTx (server/internal/service/task_handoff_tx.go) and handler helpers (server/internal/handler/issue_workflow_edge_tx.go, server/internal/handler/issue_handoff_dispatch.go, server/internal/handler/system1_route_endpoint.go).
  • Non-watchdog workflow squad handoffs (issue_handoff_dispatch, workflow edges, RouteIssue) stamp workflow_handoff_revision and fire_at under LockIssueRunBudget then LockWorkflowSquadHandoff. Each call promotes due deferred rows after commit.
  • Step watchdog watchdog: squad intents (server/internal/handler/issue_handoff_dispatch.go) keep pending-run deduplication (enqueueSquadLeaderRunWithOverlayInTx). A stalled squad step whose prior leader run ended at the same issue.Revision now starts a new leader run.
  • Skipped CancelStaleStepRuns and CancelStaleStepRunsInTx when trigger.WorkflowHandoff is true (server/internal/handler/issue.go, server/internal/handler/issue_workflow_edge_tx.go, server/internal/handler/system1_route_endpoint.go). Entering a subsequent squad workflow stage preserves pending and deferred prior squad stages.
  • Aligned createWorkflowSquadHandoffTask (server/internal/service/workflow_squad_handoff.go) to acquire LockIssueRunBudget before LockWorkflowSquadHandoff and execute inside TxScoped(q).
  • Treated ErrDuplicatePendingTask as coalesced debug output in server/internal/service/task.go.
  • Added TestWorkflowSquadHandoffConcurrentIntentAndServiceReplay, TestWorkflowSquadHandoffBatchStageOrderingAndStopChoices, and TestWorkflowSquadHandoffWatchdogRedispatchesAfterFailedLeaderRun in server/internal/handler/issue_workflow_squad_test.go.
  • State machines: none touched — preserves existing issue_handoff_dispatch and agent_task_queue states without adding columns or transitions.
  • Four lenses: not applicable — backend Go handler and service bug fix. No template, workflow YAML, or CI/CD file changed.

Blast Radius

  • Touches workflow squad handoff enqueue, step watchdog squad redispatch, and stale-step cancellation paths in server/internal/handler and server/internal/service.
  • Callers affected: UpdateIssue, BatchUpdateIssues, dispatchHandoffIntent, moveIssueOnEdgeTx, RouteIssue, and EnqueueTaskForWorkflowSquadLeader.
  • Detection: integration failures in server/internal/handler and server/internal/service backend CI shards, duplicate agent_task_queue leader rows on replay, dropped deferred squad stages, or stalled squad steps failing watchdog redispatch.
  • Proof level: 3 (Integration — handler and service paths executed against a migrated isolated pgvector/pgvector:pg17 PostgreSQL database).

Cost delta

  • C1 Cost delta: 0 extra LLM tokens or USD. Prevents duplicate squad-leader agent runs on replayed handoffs (saves >= 1 redundant agent run per replay). Adds one indexed LockIssueRunBudget + GetWorkflowSquadHandoffTask lookup per workflow squad handoff transaction.
  • C2 Optimality check: reusing PendingTaskForIssueAndAgent for status handoffs is cheaper by one advisory lock call. That alternative fails because it coalesces distinct squad stages and ignores workflow_handoff_revision after task completion. Keying status handoffs on (issue_id, agent_id, squad_id, workflow_handoff_revision) while keeping watchdog: intents on pending-run deduplication is the minimal exact mechanism.
  • C3 Watch and rollback threshold: watch agent_task_queue duplicate leader runs per (issue_id, workflow_handoff_revision) and Postgres lock-wait errors in backend logs. Revert commits 22e3d586c6ee611891e4eedeed6e62549c60d468 and 20eeeae8f2afbe60bef596481eb81eee9ba4e48b if lock contention or missing squad dispatch occurs.

Evidence

  • Lessons checked: 5f736b3b-2efe-4427-af0f-a464254bccdf (bounded Go compile parallelism -p=2). No diff violation.
  • Isolated PostgreSQL 17 (pgvector/pgvector:pg17, fresh ./cmd/migrate up) repro before fix confirmed TestWorkflowHandoffCancelsDeferredSquadStages failed (fixture did not retain a deferred stage handoff). It also confirmed TestWorkflowSquadHandoffReplayDoesNotDuplicate failed (same handoff replay = <nil>, want coalesced), matching CHE-11169 comment 01a24640-e41f-743d-b4a6-de257e50fdf0.
  • Passing verification commands and output on head 20eeeae8f2afbe60bef596481eb81eee9ba4e48b:
$ DATABASE_URL="postgres://multica:multica@127.0.0.1:32779/multica_test?sslmode=disable" go test -p=2 -count=1 ./internal/handler -run '^(TestWorkflowHandoffCancelsDeferredSquadStages|TestWorkflowSquadHandoffReplayDoesNotDuplicate|TestWorkflowSquadHandoffPreservesPendingStages|TestWorkflowHandoffToSquadStartsLeaderAtEachStep|TestWorkflowSquadHandoffKeepsAssignmentGates|TestDeleteSquadHandsItsWorkflowStepsToTheLeader|TestWorkflowSquadHandoffConcurrentIntentAndServiceReplay|TestWorkflowSquadHandoffBatchStageOrderingAndStopChoices|TestWorkflowSquadHandoffWatchdogRedispatchesAfterFailedLeaderRun|TestStepWatchdog.*|TestDispatchHandoffIntent_.*)$' -v
--- PASS: TestDispatchHandoffIntent_NoSecondRunAfterTheFirstEnded (0.61s)
--- PASS: TestDispatchHandoffIntent_RaceMakesOneRun (0.21s)
--- PASS: TestDispatchHandoffIntent_EventWakeupRuleGivesOneRunAndSettlesReceipt (0.20s)
--- PASS: TestDispatchHandoffIntent_CommentWakeupRuleGivesOneRunAndSettlesReceipt (0.18s)
--- PASS: TestDispatchHandoffIntent_ConnectedAppOverlaySurvivesAHandoffWithoutAComment (0.17s)
--- PASS: TestDispatchHandoffIntent_DeliveryAndReceiptSettleTogether (0.17s)
--- PASS: TestDispatchHandoffIntent_MentionedThirdAgentKeepsItsRun (0.15s)
--- PASS: TestWorkflowHandoffCancelsDeferredSquadStages (1.30s)
--- PASS: TestWorkflowSquadHandoffReplayDoesNotDuplicate (0.49s)
--- PASS: TestWorkflowSquadHandoffPreservesPendingStages (1.84s)
--- PASS: TestWorkflowSquadHandoffToSquadStartsLeaderAtEachStep (0.31s)
--- PASS: TestWorkflowSquadHandoffKeepsAssignmentGates (0.06s)
--- PASS: TestWorkflowSquadHandoffConcurrentIntentAndServiceReplay (0.26s)
--- PASS: TestWorkflowSquadHandoffBatchStageOrderingAndStopChoices (1.74s)
--- PASS: TestWorkflowSquadHandoffWatchdogRedispatchesAfterFailedLeaderRun (0.25s)
--- PASS: TestStepWatchdogRedispatchIssueStaysInStep (0.14s)
--- PASS: TestStepWatchdogRedispatchRunMovesIssueAtOnce (0.15s)
--- PASS: TestStepWatchdogRedispatchTwoConcurrentSweepsMakeOneRun (0.20s)
ok  	github.com/multica-ai/multica/server/internal/handler	12.331s

$ go vet ./internal/handler
(exit 0)

Closes CHE-11245

@congvc-bot-x99
congvc-bot-x99 Bot marked this pull request as ready for review December 5, 2026 19:54
@congvc-bot-x99

congvc-bot-x99 Bot commented Dec 5, 2026

Copy link
Copy Markdown
Author

Merge-Eligibility: REFUSED
Head: 20eeeae
Source: sweep: receipt, review, merger and scope facts unread; coverage_complete and defaulted_paths unread

  • unverified by the sweep: receipt, cross-lab review, merger and scope; only the merge step can decide them

@congvc-dev
congvc-dev added this pull request to the merge queue Dec 5, 2026
Merged via the queue into main with commit 95a8c20 Dec 5, 2026
55 checks passed
@congvc-dev
congvc-dev deleted the agent/x99-agy-carbon/che-11245-e522c72dbe42 branch December 5, 2026 23:25
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