Skip to content

feature: task queue manual reorder - #10049

Open
mmontes11 wants to merge 2 commits into
multica-ai:mainfrom
mmontes11:feature-task-reorder
Open

mmontes11 wants to merge 2 commits into
multica-ai:mainfrom
mmontes11:feature-task-reorder

Conversation

@mmontes11

@mmontes11 mmontes11 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds manual reordering of an agent's queued tasks: a member can move one queued task a step up or down in the agent's claim order — priority DESC, created_at ASC, id ASC, the exact order ClaimAgentTask uses. The move runs in a transaction under the agent's claim lock (the same row lock ClaimTask takes before selecting work), so a reorder cannot race an in-flight claim, and the tenancy/privacy gates mirror CancelTaskByUser exactly (workspace-scoped task load, chat-session creator privacy, private-agent visibility). The UI adds hover ↑/↓ buttons to queued rows in the agent Activity tab; queued rows now render in claim order, and reorders propagate to every open client through the existing task:queued WS event.

Related Issue

None, this is a new feature.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Refactor / code improvement (no behavior change)
  • Documentation update
  • Tests (adding or improving test coverage)
  • CI / infrastructure

Changes Made

  • server/pkg/db/queries/agent.sql — MoveQueuedTaskUp / MoveQueuedTaskDown: rank-based swap on the coarse 0–4 priority scale (take the neighbor's level across levels, step one level on a same-level tie, no-op at the queue edge); generated code in server/pkg/db/generated/agent.sql.go
  • server/internal/handler/task_lifecycle.go — MoveTaskByUser handler + MoveTaskResponse ({task_id, priority, moved})
  • server/cmd/server/router.go — POST /api/tasks/{taskId}/move
  • server/internal/handler/task_move_test.go — 12 handler tests: reorder semantics (up/down, same-level step, clamp at both edges, edge no-ops), 409 non-queued, 404 unknown/foreign-workspace, 400 bad direction, private-agent gate, chat-creator-only gate
  • packages/core/types/agent.ts, packages/core/types/index.ts, packages/core/api/schemas.ts, packages/core/api/client.ts — MoveTaskResponse type, zod schema + empty fallback, api.moveQueuedTask(taskId, direction)
  • packages/views/agents/components/tabs/activity-tab.tsx — hover chevron actions on queued LiveTaskRows, queued rows sorted in claim order, edge-reached toast
  • packages/views/locales/{en,es,fr,ja,ko,zh-Hans,zh-Hant}/agents.json — 7 new strings per locale

How to Test

  1. make dev (bootstraps env + Postgres + migrations; API on :8080, web on :3000), log in.
  2. Queue 2–3 workflow tasks for one agent (assign issues / @mention it); they stay queued while its runtime is busy or absent.
  3. Agents → agent → Activity tab: hover a queued row, click ↑/↓. Row moves one step in claim order; at either edge the buttons no-op with a toast.
  4. Verify priority changed: select id, priority from agent_task_queue where status='queued' order by priority desc, created_at asc.
  5. Second browser window re-sorts live via the task:queued event.
  6. API: POST /api/tasks/{taskId}/move {"direction":"up"} → 200 {task_id, priority, moved}; 409 non-queued, 404 foreign workspace, 403 others' chat tasks / inaccessible private agents.

Checklist

  • I have included a thinking path that traces from project context to this change (precedent: CancelTaskByUser for the id-only tenancy/privacy gates; PrioritizeQueuedChatTask for the claim-lock-during-queue-mutation pattern; reorder expressed on the existing 0–4 priority column so ClaimAgentTask needed no changes)
  • I have run tests locally and they pass (12/12 new handler tests under -race; go build/go vet clean; sqlc regeneration idempotent; @multica/core 2710 TS tests pass; @multica/web build passes)
  • I have added or updated tests where applicable
  • If this change affects the UI, I have included before/after screenshots (screenshot to be added at PR open)
  • I have updated relevant documentation to reflect my changes (n/a — no docs page covers the task queue API; endpoint is user-scoped like cancel/rerun)
  • If I added a new runtime / coding tool / UI tab, I synced the change to landing copy and relevant docs (n/a — no new tab/runtime)
  • If this PR touches Chinese product copy, I checked it against apps/docs/content/docs/developers/conventions.zh.mdx
  • I have considered and documented any risks above (reorder is best-effort on the coarse 0–4 scale: a same-level bump can clear several peers at once; the response's moved flag and the UI toast make edge no-ops explicit; dispatched/running rows are not reorderable — only queued)
  • I will address all reviewer comments before requesting merge

AI Disclosure

AI tool used: Multica agent (Beaver)

Prompt / approach:
Scouted per-agent queue reorder as the contribution shape; the agent implemented it against repo conventions (AGENTS.md), reusing CancelTaskByUser's gates and the ClaimTask lock, with equivalence tests written first. Human validated the diff and will open the PR.

Screenshots (optional)

Before supporting feature, there was no ⬆️ / ⬇️ in the queued tasks:

0_before

With the changes in this branch, new ⬆️ / ⬇️ actions are introduced in the queued task, which are very handy for low-concurrent agents like our Beaver (concurrency=1) 🦫 :

⬇️ move down:
1_move_down

⬆️ move up:
2_move_up

The cancel button ❌ is still available:

3_cancel_run

This is what we see after ⬆️ moving up the "Write bubble sort in Go" task:

4_moved

If we click again in ⬆️ move up, a pop-up is displayed informing that we are already at the front of the queue:

5_front_queue

The tasks that have been moved are eventually scheduled:

6_scheduled

Finally, if we click in ⬇️ move down in the task that is at the end of the queue, a pop-up is also displayed:

7_end_queue

@vercel

vercel Bot commented Nov 6, 2026

Copy link
Copy Markdown

@mmontes11 is attempting to deploy a commit to the IndexLabs Team on Vercel.

A member of the Team first needs to authorize it.

@mmontes11 mmontes11 changed the title feature: task queue reorder feature: task queue manual reorder Nov 6, 2026
mmontes11 and others added 2 commits November 6, 2026 09:41
Adds POST /api/tasks/{taskId}/move so a member can hand-reorder one agent's queued tasks one step at a time in claim order (priority DESC, created_at ASC, id ASC). The move runs under the agent's claim lock, reuses the CancelTaskByUser tenancy and privacy gates, and broadcasts the existing task:queued event so clients re-sort live.

Co-authored-by: multica-agent <github@multica.ai>
Adds hover chevron actions to queued rows in the agent activity tab that call the new /api/tasks/{taskId}/move endpoint. Queued rows now sort in claim order (priority DESC, created_at ASC) so the row order matches what the daemon claims next; reorders propagate through the existing task:queued WS event.

Co-authored-by: multica-agent <github@multica.ai>
@mmontes11
mmontes11 force-pushed the feature-task-reorder branch from 75d3697 to 38c2090 Compare November 6, 2026 08:41

This branch has not been deployed

No deployments
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