Skip to content

fix(service): coalesce duplicate EnqueueTaskForIssue on the assignee path (#5914) - #6304

Open
kakiuwang-ui wants to merge 1 commit into
multica-ai:mainfrom
kakiuwang-ui:fix/duplicate-enqueue-issue-assignee
Open

fix(service): coalesce duplicate EnqueueTaskForIssue on the assignee path (#5914)#6304
kakiuwang-ui wants to merge 1 commit into
multica-ai:mainfrom
kakiuwang-ui:fix/duplicate-enqueue-issue-assignee

Conversation

@kakiuwang-ui

Copy link
Copy Markdown
Contributor

Follow-up to #5958, opened at the maintainer's suggestion on #5938:

One narrow difference remains around a concurrent duplicate EnqueueTaskForIssue call. If you would like to pursue that separately, please open a small PR rebased on the latest main, focused on that path and its regression test.

Problem

#5958 mapped the duplicate-pending-task race to ErrDuplicatePendingTask on the
mention path (enqueueMentionTaskWithCommentPlan), but the issue-assignee
path was left untouched. enqueueIssueTaskWithCommentPlan is the second write
point of the idx_one_pending_task_per_issue_agent unique index, so a concurrent
duplicate there still logged at slog.Error and returned a generic wrapped
create-task error — the same HTTP 500 with the leaked constraint name that #5914
set out to remove.

Changes

server/internal/service/task.go

  • enqueueIssueTaskWithCommentPlan: reuse the existing isDuplicatePendingTaskErr
    helper and return the existing ErrDuplicatePendingTask sentinel (slog.Debug,
    not Error) on the race — identical treatment to the mention path. No new
    helper or sentinel is introduced.

server/internal/handler/comment.go

server/internal/service/duplicate_pending_task_test.go

  • Add TestEnqueueTaskForIssueCoalescesDuplicatePendingTask next to the existing
    mention-path regression: a second EnqueueTaskForIssue for the same
    (issue, agent) returns ErrDuplicatePendingTask, does not leak the constraint
    name / SQLSTATE, and leaves exactly one pending task.

Other EnqueueTaskForIssue callers (autopilot.go, issue.go,
onboarding_shim.go) are intentionally out of scope: they already logged/wrapped
the pre-existing generic error, so their severity is unchanged; the sentinel is
now available via errors.Is should they want to special-case it later.

Test plan

  • go test ./internal/service/ ./internal/handler/ against live Postgres
    (migrated to latest, 251) — all pass, including the new regression test.
  • go vet ./internal/handler/ ./internal/service/ clean; changed files
    gofmt-clean.

Refs #5914, #5958, #5938

…path (multica-ai#5914)

Follow-up to multica-ai#5958, which mapped the duplicate-pending-task race to
ErrDuplicatePendingTask on the mention path (enqueueMentionTaskWithCommentPlan)
but left the issue-assignee path untouched. enqueueIssueTaskWithCommentPlan is
the second write point of the idx_one_pending_task_per_issue_agent unique
index, so a concurrent duplicate there still logged at ERROR and surfaced as a
generic create-task error (HTTP 500 leaking the raw constraint name).

- enqueueIssueTaskWithCommentPlan: reuse isDuplicatePendingTaskErr and return
  the existing ErrDuplicatePendingTask sentinel (slog.Debug, not Error) on the
  race — identical treatment to the mention path.
- enqueueSingleCommentTrigger (issue-assignee case): switch the plain slog.Warn
  to the shared logCommentEnqueueFailure helper so the now-typed sentinel is
  downgraded to debug and resolveCommentTriggerEnqueue can coalesce, matching
  the sibling squad-leader and mention cases.
- Add TestEnqueueTaskForIssueCoalescesDuplicatePendingTask alongside the
  mention-path regression: a second EnqueueTaskForIssue for the same
  (issue, agent) returns ErrDuplicatePendingTask, does not leak the constraint
  name/SQLSTATE, and leaves exactly one pending task.

Fixes the remaining EnqueueTaskForIssue case called out in multica-ai#5938.
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

@kakiuwang-ui is attempting to deploy a commit to the IndexLabs Team on Vercel.

A member of the Team first needs to authorize it.

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