Startup grace holds preassigned executions of any worker ever refused secrets, and logs nothing

Open
#81 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
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
fastapi, postgresql, python

Research direction

Start with server/orcaster_server/housekeeping.py:255-279 and inspect the grace branch in _run_once at server/orcaster_server/housekeeping.py:544-551. Check how polling updates refusal and heartbeat timestamps in server/orcaster_server/api/poll.py, then review the existing housekeeping tests and changelog. Done when the grace predicate excludes old refusal marks and deleted workers, the warning reports the held count only when nonzero, the specified tests pass, and an Unreleased note documents earlier expiry after restart.

Written by the indexing model from the issue text.

Description

enhancement P2 server

Problem

Housekeeping expires overdue assigned executions (server/orcaster_server/housekeeping.py:255-279). It skips an execution whose task declares task_env and whose worker was refused secret delivery recently, because that worker is still asking for the task.

During the startup grace, the age of the refusal mark is ignored: any non-NULL workers.task_secrets_refused_at is enough (server/orcaster_server/housekeeping.py:270-271). This is meant for the case "configure the keys file and restart", where the mark aged while the server was down.

Two problems:

  1. The shield is too wide. The mark is only written by a refused poll (server/orcaster_server/api/poll.py:986-989) and nothing ever resets it to NULL. So during every grace, the shield covers every worker that was refused once, even long ago. The join on workers also has no deleted_at filter, so a soft-deleted worker that still owns assigned rows is covered too. A soft delete without ?force=true does not cancel the worker's executions (server/orcaster_server/api/admin_workers.py:346). The cost is bounded: expiry is delayed by at most one grace (STARTUP_GRACE_SECONDS, server/orcaster_server/config.py:146) plus one housekeeping interval. No data is lost.
  2. No signal. The lease shield logs a WARNING with a count during grace (server/orcaster_server/housekeeping.py:544-551). This shield logs nothing. The operator cannot tell from the log whether the protection engaged after a restart.

Proposed change

  1. Bound the grace branch by the worker's own last poll. A refused poll also updates last_heartbeat_at (server/orcaster_server/api/poll.py:92), and server downtime freezes it. In grace, require w.task_secrets_refused_at >= w.last_heartbeat_at - interval '120 seconds', plus w.deleted_at IS NULL:
    • a worker refused at its last poll keeps the shield, however long the server was down;
    • a worker that polled normally after its last refusal does not;
    • a soft-deleted worker does not.
  2. In the grace branch of _run_once, count (read-only, same predicate) the overdue preassigned executions that the shield holds. If the count is above zero, log one WARNING, for example housekeeping: startup grace holding N overdue preassigned execution(s) of workers refused task secrets; they expire after the grace unless the worker polls. Log nothing when the count is zero.
  3. Keep STARTUP_GRACE_SECONDS, its default and the non-grace predicate unchanged.

Compatibility

No migration, no API change and no setting change. Existing deployments see one behavior change: after a restart, a preassigned execution of a worker that was refused long ago, or of a soft-deleted worker, now expires in the first housekeeping pass instead of after the grace. The task follows the normal expiry path it would follow anyway a few minutes later. Workers refused at their last poll keep the current protection. The release note states this.

Acceptance criteria

  • Test (in_grace=True): a worker whose mark is much older than its last_heartbeat_at does not shield its overdue preassigned execution.
  • Test (in_grace=True): a worker whose mark is within 120 s of its frozen last_heartbeat_at still shields the execution, whatever the age of both timestamps.
  • Test (in_grace=True): a soft-deleted worker does not shield its execution.
  • Test: outside grace, behavior is unchanged.
  • Test with caplog: a grace pass that holds N > 0 executions logs one WARNING with N, and a pass that holds none logs nothing.
  • Existing deployments keep working without config changes. STARTUP_GRACE_SECONDS and its default are unchanged.
  • CHANGELOG entry under Unreleased, with the note that some held executions may expire earlier after a restart.

Open questions

  • Does any path other than the poll (for example worker registration) write last_heartbeat_at in a way that breaks the bound in step 1?
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.