Housekeeping expires assigned executions but never re-evaluates the task close

Open
#71 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
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
fastapi, python
Domain
backend, devops

Research direction

Start with _EXPIRE_ASSIGNED_SQL and _expire_assigned in server/orcaster_server/housekeeping.py, then read _SQL_MAYBE_CLOSE_TASK and its caller in server/orcaster_server/api/tasks.py. Run the housekeeping and task completion tests to understand both event orders and the protected pre-assignment case. Done means the shared close check updates only eligible all_available tasks after expiry, with tests, a changelog entry, and the user manual note updated.

Written by the indexing model from the issue text.

Description

bug P1 server

Problem

An all_available task closes only when every execution of its current snapshot epoch is terminal (server/orcaster_server/api/tasks.py:328-335). That close check, _SQL_MAYBE_CLOSE_TASK, runs only from the worker complete route (server/orcaster_server/api/tasks.py:726-729).

Housekeeping expires assigned executions whose claim_timeout_seconds has passed (server/orcaster_server/housekeeping.py:255-275). _expire_assigned returns only a row count (housekeeping.py:445-448), and the caller only logs it (housekeeping.py:555-560). The task status is never re-evaluated.

So if the expired execution was the last non-terminal one, the task stays dispatching for good. The operator sees no error. This happens whenever a worker in the snapshot never claims its pre-assignment, for example a worker that went offline after the snapshot, or a worker that cannot receive the task's stored secrets (the residual case in docs/user-manual.md:3928-3933).

The result depends on the order of events. If the execution expires before the last other execution completes, the complete route runs the close check and the task closes. If it expires after, the task never closes.

Steps to reproduce

  1. Create an all_available task with a short claim_timeout_seconds while two workers are enrolled.
  2. Stop one worker before it claims its execution.
  3. Let the other worker complete its execution.
  4. Wait until housekeeping expires the remaining assigned execution.
  5. The task stays dispatching.

Proposed change

  1. Make _EXPIRE_ASSIGNED_SQL return the task id and workspace id of each expired row (RETURNING).
  2. After the expiry, run the same close check as the complete route once per distinct task, in the same transaction.
  3. Move _SQL_MAYBE_CLOSE_TASK to a module that both server/orcaster_server/api/tasks.py and server/orcaster_server/housekeeping.py can import, or expose a helper. Do not copy the SQL.
  4. Keep the close rule unchanged. An expired execution counts as terminal but not completed, so the task closes failed, exactly as it does today when the expiry happens before the last complete.
  5. Log the number of tasks closed by this step.
  6. Update the residual-case note in docs/user-manual.md:3928-3933 with the final task status.

Tasks with claim_timeout_seconds unset never expire an execution. That is out of scope here.

Compatibility

  • No schema change and no API change.
  • After the upgrade, the first housekeeping pass closes tasks that are stuck in dispatching with an expired execution. Most will close failed. Operators and scripts that list dispatching tasks will see them leave that list.
  • Upgrade note: to see the affected tasks before the upgrade, list all_available tasks in dispatching whose remaining executions are all expired or terminal.

Acceptance criteria

  • A test with an all_available task where one worker completes and the other's assigned execution then expires shows the task closed after one housekeeping pass, with the same status, outcome and completed_at that the complete route would set.
  • A test with the opposite order (expiry first, complete second) still closes the task as today.
  • A test with a count task shows that an expired execution does not change its status, as today.
  • A test shows that the protected pre-assignment (worker refused secret delivery) is still not expired and the task is not closed.
  • _SQL_MAYBE_CLOSE_TASK has one definition used by both callers.
  • Tasks in other states and tasks without expired executions are not changed. Existing deployments keep working without config changes.
  • CHANGELOG entry under Unreleased, with an upgrade note that stuck dispatching tasks close on the first housekeeping pass.
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.