Skip to content

feat: add task queue management API - #395

Merged
houko merged 2 commits into
mainfrom
feat/task-queue-api-184
Mar 17, 2026
Merged

houko merged 2 commits into
mainfrom
feat/task-queue-api-184

Conversation

@houko

@houko houko commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add queue management endpoints: GET /api/queue/status, GET /api/queue/list, DELETE /api/queue/{id}, POST /api/queue/{id}/retry
  • Provides visibility into queued, processing, and failed tasks

Closes #184

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions Bot added area/docs Documentation and guides area/runtime Agent loop, LLM drivers, WASM sandbox type/agent-template New or updated agent template (TOML only) area/kernel Core kernel (scheduling, RBAC, workflows) area/sdk JavaScript and Python SDKs labels Mar 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Binary Size: 47.32MB (45.8KB vs main 47.27MB)

@github-actions

Copy link
Copy Markdown
Contributor

✅ Binary Size: 47.50MB (45.7KB vs main 47.46MB)

@houko

houko commented Mar 15, 2026

Copy link
Copy Markdown
Contributor Author

Code Review: feat: add task queue management API

Merge Conflicts

This PR has merge conflicts with main and needs a rebase before it can be merged.

Code Review

Overall: The core implementation is clean and follows existing project patterns well. The layer separation (routes -> kernel -> memory substrate) is correct. However, there are a few issues to address:

1. DELETE endpoint lacks authorization/safety guard (Medium)

queue_delete allows deleting any task, including those with status in_progress. Deleting a task that is currently being processed could cause data inconsistency or orphaned work. Consider either:

  • Rejecting deletion of in_progress tasks (return 409 Conflict), or
  • Adding a force query parameter to explicitly opt in to deleting active tasks.

2. task_retry allows retrying in_progress tasks (Medium)

The doc comment says "Re-queue a completed/failed/in_progress task" and the SQL WHERE clause includes in_progress. Retrying a task that is actively being processed seems dangerous — it could cause duplicate execution. Recommend removing in_progress from the retry eligibility unless there's a specific use case for it (e.g., stuck task recovery with a timeout).

3. queue_status iterates tasks by parsing JSON status field (Low)

queue_status calls task_list(None) which fetches all tasks as serde_json::Value, then manually counts statuses by string-matching on t["status"]. This works but is inefficient for large queues — a SELECT status, COUNT(*) FROM task_queue GROUP BY status query in MemorySubstrate would be more efficient and avoid deserializing all task data just to count them. Not blocking, but worth considering.

4. No pagination on queue_list (Low)

queue_list returns all tasks matching a status filter with no limit/offset. For a production system with many queued tasks, this could return very large payloads. Consider adding optional ?limit= and ?offset= query params, consistent with other list endpoints in the project.

5. No tests for new endpoints

The PR adds 4 new API endpoints but includes no unit or integration tests. The only test change is the mock KernelHandle stubs returning Err("not used"). At minimum, tests for the substrate-level task_delete and task_retry methods would be valuable.

6. Version bump scope (Nit)

The PR bundles a full version bump (beta3 -> beta4) across 43 files including all agent TOML files, SDKs, and a large CHANGELOG entry covering many unrelated PRs. This makes the diff noisy and could cause merge conflicts with any other in-flight PR. Consider separating the version bump into its own PR.

Summary

The feature implementation is solid in structure. The main concerns are:

  1. Rebase needed — merge conflicts exist
  2. Safety guards — delete and retry of in_progress tasks need consideration
  3. No tests — new endpoints should have test coverage

@houko
houko force-pushed the feat/task-queue-api-184 branch from dbff7e3 to 919900c Compare March 15, 2026 13:12
@github-actions github-actions Bot removed area/docs Documentation and guides type/agent-template New or updated agent template (TOML only) area/sdk JavaScript and Python SDKs labels Mar 15, 2026

@houko houko left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: feat: add task queue management API

Overall: Clean, well-structured PR that adds useful CRUD operations for the task queue. The layering (substrate → kernel → trait → routes → server) is consistent with the existing codebase patterns. CI is green.

Issues

  1. queue_status fetches all tasks just to count them — queue_status calls task_list(None) which deserializes every row into serde_json::Value, then iterates to count by status. For a large queue this is wasteful. Consider adding a dedicated SELECT status, COUNT(*) FROM task_queue GROUP BY status query in the substrate layer. Not a blocker for merge, but worth a follow-up.

  2. No pagination on queue_list — The list endpoint returns all matching tasks with no limit/offset. If the queue grows large this could be a problem. Consider adding ?limit= and ?offset= query params (can be a follow-up).

  3. queue_status silently ignores unknown statuses — The match arm _ => {} means any task with an unexpected status string won't be counted, but will appear in total. The total will be > sum of the four counters. Consider adding an "other" counter or documenting this behavior.

  4. No tests for the new task_delete / task_retry substrate methods — The existing test file has test_task_post_and_list and test_task_claim_and_complete, but no tests for delete or retry. These are straightforward to add and would be valuable.

  5. task_retry allows retrying in_progress tasks — The SQL WHERE status IN ('completed', 'failed', 'in_progress') means a task currently being processed can be reset to pending. This could cause duplicate execution if a worker is still processing it. Consider excluding in_progress or documenting this as intentional.

  6. DELETE endpoint has no guard against deleting in_progress tasks — Similarly, deleting a task while it's being processed could lead to issues if the worker tries to update it upon completion.

Nits

  • The queue_list handler takes Query(params): Query<HashMap<String, String>> — consider using a typed struct (e.g., QueueListParams { status: Option<String> }) for better documentation and validation.
  • The retry SQL string is quite long on one line — could use a const or multi-line string for readability.

Verdict

The code is correct and follows established patterns well. The main concerns (no pagination, status counting efficiency, in-progress guards) are non-blocking and can be addressed in follow-ups. LGTM for merge with the suggestion to file follow-up issues for items 1, 2, and 5.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Binary Size: 58.05MB (41.7KB vs main 58.01MB)

@houko
houko force-pushed the feat/task-queue-api-184 branch from 919900c to 9ec5067 Compare March 15, 2026 13:42
@github-actions

Copy link
Copy Markdown
Contributor

✅ Binary Size: 58.37MB (41.8KB vs main 58.33MB)

@SenZhangAI SenZhangAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Task queue management API

Useful observability endpoints. SQLite persistence is properly async with spawn_blocking. Route registration is correct.

Must fix

  1. Race condition in task_retry — Allows retrying tasks that are `in_progress`. If an agent is still processing the task, retry resets it to `pending`, and the agent's eventual completion overwrites the result. Fix: only allow retry for `failed` status, or add a generation counter.
    -- Current (unsafe):
    WHERE status IN ('completed', 'failed', 'in_progress')
    -- Fix:
    WHERE status IN ('completed', 'failed')

Should fix

  1. Endpoint naming conflict — `/api/queue/status` redefines the existing queue status endpoint that reports command lane occupancy. Use `/api/tasks/status` instead to avoid confusion.
  2. No task creation endpoint — Only agents can create tasks via `kernel.task_post()`. Consider adding a POST endpoint for admin use.

Context

The task queue is currently observe-only (list, delete, retry) with no automatic executor. This is acceptable as an MVP but should be documented as a known limitation.

@houko
houko force-pushed the feat/task-queue-api-184 branch from 9ec5067 to 80c3bd8 Compare March 17, 2026 05:56
@houko
houko dismissed SenZhangAI’s stale review March 17, 2026 05:57

All requested changes addressed: task_retry excludes in_progress, endpoints renamed to /api/tasks/*, rebased onto main.

@houko houko left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review & Fixes Applied

Rebased onto main and addressed all review feedback. Code placed in the new module structure (routes/system.rs).

Fixed issues:

  1. Race condition in task_retry (SenZhangAI #1) — Removed in_progress from the SQL WHERE clause. Only completed and failed tasks can be retried. Error message explicitly states this constraint.

  2. Endpoint naming conflict (SenZhangAI #2) — Renamed all endpoints from /api/queue/* to /api/tasks/* to avoid conflict with existing /api/queue/status (command lane occupancy).

  3. Rebased onto main — routes.rs was split into modules in #452. Task queue handlers now live in routes/system.rs.

Endpoints:

Endpoint Method Purpose
/api/tasks/status GET Summary counts by status
/api/tasks/list GET List tasks (?status= filter)
/api/tasks/{id} DELETE Remove a task
/api/tasks/{id}/retry POST Re-queue completed/failed task

Acknowledged (non-blocking, follow-ups):

  • No pagination on list endpoint
  • queue_status fetches all rows to count (could use GROUP BY)
  • No task creation endpoint (agents create via kernel.task_post())

Verification

  • cargo build --workspace --lib ✅
  • cargo test --workspace ✅
  • cargo clippy --workspace --all-targets -- -D warnings ✅

@houko
houko force-pushed the feat/task-queue-api-184 branch 2 times, most recently from 9cb29f7 to cc4a01f Compare March 17, 2026 06:10
@houko houko closed this Mar 17, 2026
@houko houko reopened this Mar 17, 2026
Add CRUD endpoints for task queue management:
- GET /api/tasks/status — summary counts by status
- GET /api/tasks/list — list tasks with optional ?status= filter
- DELETE /api/tasks/{id} — remove a task
- POST /api/tasks/{id}/retry — re-queue a completed/failed task

Uses /api/tasks/* namespace to avoid conflict with existing
/api/queue/status (command lane occupancy) endpoint.

task_retry only allows resetting 'completed' or 'failed' tasks —
'in_progress' is excluded to prevent duplicate execution race
conditions.

Closes #184
@houko
houko force-pushed the feat/task-queue-api-184 branch from cc4a01f to 7cd2e0c Compare March 17, 2026 06:17
@houko

houko commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on top of #394 (event webhooks) which just merged to main — conflict in system.rs and server.rs resolved. Both feature sets coexist cleanly.

Build ✅ / Tests ✅ / Clippy ✅ — ready to merge.

@houko
houko merged commit d31e250 into main Mar 17, 2026
11 checks passed
@houko
houko deleted the feat/task-queue-api-184 branch March 17, 2026 06:39
@houko houko mentioned this pull request Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/kernel Core kernel (scheduling, RBAC, workflows) area/runtime Agent loop, LLM drivers, WASM sandbox

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add task queue management API

2 participants