Task output without --attempt can serve an older execution after a retry on another worker

Open
#64 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
50/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
fastapi, go, python

Research direction

Start with _SQL_LATEST_EXECUTION and the output endpoint in server/orcaster_server/api/v1.py, then read the task execution query and schema in server/orcaster_server/schemas/api_v1.py. Trace the response through orcaster/internal/api/types.go and orcaster/cmd/task.go; the issue names server/tests/test_api_v1_tasks_output.py and the orcaster/cmd/testdata/task_get.golden files. Done means the default selects by execution time, task details expose execution IDs, and the documented CLI behavior and acceptance tests are updated.

Written by the indexing model from the issue text.

Description

bug cli P1 question server

Problem

GET /api/v1/tasks/{id}/output without attempt should serve the most recent execution of the task. orcaster/README.md:128-129 and the --attempt flag help (orcaster/cmd/task.go:214, "default: latest") promise this.

The server picks the execution with ORDER BY attempt_index DESC, id DESC LIMIT 1 (server/orcaster_server/api/v1.py:220-223, used at server/orcaster_server/api/v1.py:595-596). This does not give the most recent execution:

  • attempt_index counts per (task_id, worker_id), not per task. The claim insert computes MAX(attempt_index) for that pair, plus 1 (server/orcaster_server/api/poll.py:265-266). A retry that runs on another worker starts again at 1.
  • The tie-break is id, a random UUID (server/orcaster_server/models.py:459-463). With two executions at index 1 on two workers, the pick has no relation to time. The existing test accepts either result (server/tests/test_api_v1_tasks_output.py:146-166).
  • If worker A ran attempts 1 and 2 and worker B then ran the newest execution at index 1, the default always serves the older execution on A.

So after a retry on another worker, orcaster task output <id> can show the log of an attempt that did not close the task.

The same detail route does not help the user reach the right execution. _SQL_TASK_EXECUTIONS does not select the execution id (server/orcaster_server/api/v1.py:207-215), TaskExecutionSummary has no id field (server/orcaster_server/schemas/api_v1.py:192-204), and the Go struct has none either (orcaster/internal/api/types.go:153-162). orcaster task output --execution <uuid> exists, but the CLI user has no way to learn the UUID from task get.

Steps to reproduce

  1. Start only worker A. Create a count-mode task with target 1 whose command fails. Wait until it is failed.
  2. Stop A, start worker B, and run orcaster task retry <id> (any eligible worker). Wait until B finishes.
  3. Run orcaster task output <id>. When the UUID of the execution on A is larger than the one on B, the log of A is served.
  4. Run orcaster task get <id> --json. Both executions have attempt_index 1, and neither has an id.

For a deterministic test, seed the older execution with a larger UUID than the newer one.

Proposed change

  1. Pick the default execution by time: ORDER BY assigned_at DESC NULLS LAST, id DESC in _SQL_LATEST_EXECUTION. id stays only as the last tie-break for equal timestamps.
  2. Add the execution id to _SQL_TASK_EXECUTIONS, to TaskExecutionSummary and to the Go TaskExecutionSummary. Show it in task get (table and --json) and update the golden files (orcaster/cmd/testdata/task_get.golden).
  3. Keep the meaning of ?attempt=N (per-worker index) in this issue. Document it in the endpoint docstring (server/orcaster_server/api/v1.py:584-585), the flag help and orcaster/README.md: --attempt N is the N-th execution on one worker, and --execution <uuid> reaches any execution.

Compatibility

  • Existing clients see a different default pick only for tasks whose executions ran on more than one worker. The response format does not change.
  • ?attempt=N keeps its current meaning, so scripts that pass a per-worker index keep getting the same execution.
  • The new id field in GET /api/v1/tasks/{id} is additive. Older CLI binaries ignore it.
  • No database migration.

Acceptance criteria

  • A server test seeds two executions of one task on two workers, both with attempt_index 1, gives the older one the larger UUID, and asserts that the default serves the newer one.
  • A server test seeds worker A with attempts 1 and 2, then worker B with attempt 1 as the newest, and asserts that the default serves the execution on B.
  • GET /api/v1/tasks/{id} returns an id for each execution, and orcaster task get shows it. Golden files are updated.
  • ?attempt=N returns the same execution as before for existing data (test).
  • Existing clients keep working without changes: no field is removed or renamed, and ?attempt=N keeps its meaning.
  • The docstring, the flag help and orcaster/README.md state the default rule and the meaning of --attempt.
  • CHANGELOG entry under Unreleased that names the new default pick.

Open questions

  • Should --attempt N later become a per-task number (the N-th execution of the task by time), matching the attempt_number that task retry prints (server/orcaster_server/api/admin_tasks.py:1013-1016, orcaster/cmd/task.go:1009)? That changes the meaning of a public query parameter and breaks clients that send a per-worker index. Keeping the current meaning, as proposed above, keeps existing deployments working.
  • The dashboard task detail may use its own "latest" rule. Should it follow the same rule here or in a follow-up?
Dominant language
Python
Stars
0
Forks
0
Avg merge
1d 1h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AInvirion/orcaster

All issues in AInvirion/orcaster

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.