Enable Task status updates via POST requests#174
Open
declan-scale wants to merge 6 commits intomainfrom
Open
Conversation
6624cb8 to
ebd3487
Compare
ebd3487 to
58d2723
Compare
PUT /tasks/{id_or_name}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates
resolves AGX1-153
Greptile Summary
This PR adds five new POST endpoints (
/complete,/fail,/cancel,/terminate,/timeout) to transition running tasks to terminal states, along with UI changes that disable the prompt input and display the terminal status when a task is no longer running.Key changes:
transition_statusrepository method usesUPDATE WHERE status = expected_statusto safely handle concurrent transition requests — directly addressing the race condition flagged in the previous review round._transition_to_terminalinTasksUseCaseprovides a unified pre-flight check (DELETED → 404, non-RUNNING → 400) and surfaces concurrent-modification conflicts as a retryable 400 rather than silently clobbering state.task-messages.tsxis refactored to support agent-only message pairs (no preceding user message), enabling tasks that start with agent-initiated output.Minor items to address:
task_repository.py:session.get()result used without a null check beforemodel_validate— defensive guard recommended.prompt-input.tsx:'RUNNING'is a hardcoded magic string; an enum reference from the SDK (if available) is preferred per the project style guide.Confidence Score: 4/5
session.get()result, and replacing the hardcoded'RUNNING'string with an enum reference. Neither blocks correctness in practice.agentex/src/domain/repositories/task_repository.py(missing null guard) andagentex-ui/components/primary-content/prompt-input.tsx(hardcoded status string).Important Files Changed
transition_statusmethod using an atomicUPDATE WHERE status = expected_statuspattern to handle concurrent modifications correctly; minor: missing null check onsession.get()result.transition_task_statusservice method that delegates to the repository and publishes atask_updatedstream event on success; error is swallowed (logged only) to avoid masking the status change, consistent with the existingupdate_taskpattern._transition_to_terminalhelper and five public methods (complete/fail/cancel/terminate/timeout). The previous race condition concern is addressed via the atomic UPDATE; concurrent modification is surfaced as a 400 with a retry hint./complete,/fail,/cancel,/terminate,/timeout) with optionalTaskStatusReasonRequestbody; authorization and routing look correct.TaskStatusReasonRequestschema with a single optionalreasonfield; straightforward and correct.isTaskTerminalcomputed flag to disable the prompt input and show task status in the placeholder when a task reaches a terminal state; uses a hardcoded'RUNNING'string instead of an enum reference.pairStartedflag and makinguserMessagenullable; the "thinking" shimmer now only shows when a user message is present.Sequence Diagram
sequenceDiagram participant Client participant Route as POST /tasks/{id}/complete participant UseCase as TasksUseCase participant Service as AgentTaskService participant Repo as TaskRepository participant DB as PostgreSQL participant Stream as Redis Stream Client->>Route: POST /tasks/{task_id}/complete {reason} Route->>UseCase: complete_task(id, reason) UseCase->>Service: get_task(id) Service->>DB: SELECT task WHERE id=task_id DB-->>Service: TaskEntity Service-->>UseCase: TaskEntity alt task.status == DELETED UseCase-->>Route: raise ItemDoesNotExist (404) else task.status != RUNNING UseCase-->>Route: raise ClientError (400) end UseCase->>Service: transition_task_status(task_id, RUNNING→COMPLETED, reason) Service->>Repo: transition_status(task_id, expected=RUNNING, new=COMPLETED) Repo->>DB: UPDATE tasks SET status=COMPLETED WHERE id=task_id AND status=RUNNING DB-->>Repo: rowcount (0 or 1) alt rowcount == 0 (concurrent modification) Repo-->>Service: None Service-->>UseCase: None UseCase-->>Route: raise ClientError "concurrently modified, retry" (400) end Repo->>DB: SELECT task WHERE id=task_id DB-->>Repo: Updated TaskORM Repo-->>Service: TaskEntity (COMPLETED) Service->>Stream: publish task_updated event Service-->>UseCase: TaskEntity (COMPLETED) UseCase-->>Route: TaskEntity Route-->>Client: 200 Task{status: COMPLETED}Prompt To Fix All With AI
Reviews (4): Last reviewed commit: "add better tests for tasks" | Re-trigger Greptile
Context used:
Learnt From
scaleapi/scaleapi#126557