feat(tasks): add async task tracking API for background operations#476
Conversation
Follow-up to volcengine#472. When `wait=false`, background commit failures were silently lost — callers had no way to know if memory extraction succeeded. This adds a lightweight in-memory TaskTracker that returns a `task_id` on async commit, which callers can poll via new `/tasks` endpoints to check completion status, results, or errors. Key changes: - New TaskTracker singleton with TTL-based cleanup (24h completed, 7d failed) - New API: GET /api/v1/tasks/{task_id} and GET /api/v1/tasks (with filters) - Atomic duplicate commit detection (eliminates race condition) - Error message sanitization (keys/tokens redacted) - Defensive copies on all public reads (thread safety) - 35 tests (26 unit + 9 integration), all existing tests pass Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
CI Status: The This same error occurs on other PR branches ( All tests pass locally (39 tests including 26 unit + 9 integration + 4 regression). |
|
/review |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Summary
TaskTrackerfor tracking async background operations (session commit withwait=false)GET /api/v1/tasks/{task_id}(single task) andGET /api/v1/tasks(list with filters)POST /sessions/{id}/commit?wait=falsenow returns atask_idthat callers can poll to check completion/failureMotivation
Follow-up to #472. When
wait=false, background commit failures were silently lost — callers had no way to know if memory extraction succeeded. This PR closes that gap by providing a polling API.As discussed with @r266-tech on #472 — this addresses the status tracking concern raised there. Would appreciate your review!
Design
GET /tasks/{id}returns 404 after restart (expected behavior for ephemeral async tasks)TaskTracker— designed to support future task types (resource ingest, skill ingest) in Phase 2threading.Lockfor compatibility with QueueManager's thread-based workersAPI
Files changed (4 modified + 4 new)
openviking/service/task_tracker.pyopenviking/server/routers/tasks.pytests/test_task_tracker.pytests/test_session_task_tracking.pyopenviking/server/routers/sessions.pyopenviking/server/routers/__init__.pyopenviking/server/app.pytests/conftest.pyTest plan
Future work
callback_urlparameter for push-based notification🤖 Generated with Claude Code