Poll of a worker below the secrets version floor scans every queued task that uses stored secrets
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- backend, databases, performance
Research direction
Start with the claim picks and _TASK_USES_STORED_SECRETS in server/orcaster_server/api/poll.py, then read the query in server/orcaster_server/task_secrets/gate.py. First add a reproducible benchmark for current and below-floor workers that records poll time and EXPLAIN (ANALYZE, BUFFERS); use its results to decide whether to add a schema option. Done means the benchmark can be rerun, slow polls are logged and tested, and any chosen schema option meets the compatibility and migration criteria with a CHANGELOG entry.
Written by the indexing model from the issue text.
Description
Problem
A worker whose version is below the task secrets floor must not receive tasks that use stored secrets. The three claim picks in server/orcaster_server/api/poll.py enforce this with a predicate under :exclude_stored_secrets (:235-236, :296-297, :401-402).
That predicate, _TASK_USES_STORED_SECRETS (server/orcaster_server/api/poll.py:185), expands to an EXISTS subquery on task_secrets for every candidate row (server/orcaster_server/task_secrets/gate.py:110-139). It looks inside the JSONB payload.task_env of each task, so no index can serve it.
A current worker stops at the first candidate in priority, run_at order. A below-floor worker rejects every queued task that uses stored secrets, one row at a time, before it finds a task it can take or returns no task. The cost of each idle poll of such a worker therefore grows in a straight line with the number of queued tasks that use stored secrets. Every old worker pays it on every idle poll.
The same subquery also runs for every push pick in a busy poll (server/orcaster_server/api/poll.py:1066-1068).
Proposed change
- Measure first. Add a reproducible benchmark (test or script) that fills a test database with a large backlog of queued tasks using stored secrets and records
EXPLAIN (ANALYZE, BUFFERS)and the poll time for a current worker and a below-floor worker. - Make poll cost visible. Log the poll duration at DEBUG, and log a WARNING when a single poll takes longer than a threshold, with the worker id and whether
exclude_stored_secretswas set. - Only if the measurement shows the scan dominates, pick one of the schema options in Open questions.
Compatibility
Steps 1 and 2 do not change the poll result, the API, the database schema or any setting. Existing deployments and workers see no difference.
If a schema option is chosen:
- The migration is additive: a new nullable column or a new index. Old code ignores it.
- A NULL column means "unknown", never "declares nothing". Tasks queued before the migration, or created by an old server after a rollback, have NULL. For them a below-floor worker still runs the
EXISTSpredicate, so the gate (server/orcaster_server/api/poll.py:235-236) is never bypassed. A backfill in the migration is optional and does not remove this rule. - Migrations run in one transaction under an advisory lock (
server/orcaster_server/migrations/env.py:55-63), and by default they run at server startup (MIGRATE_ON_STARTUP,server/orcaster_server/config.py:151).CREATE INDEX CONCURRENTLYcannot run there. The index uses plainCREATE INDEX IF NOT EXISTSwithSET LOCAL lock_timeout, one statement perop.execute, likeserver/orcaster_server/migrations/versions/0061_te_worker_assigned_idx.py. - Lock cost: the index build takes a SHARE lock on
tasks. It blocks writes, not reads, for the length of the build, at startup before the server serves traffic. The benchmark from step 1 records the build time on a large table, and the release note states it. A backfill, if any, runs in the same transaction, so its row locks and its time are measured and stated the same way. - The poll result is the same before and after for every worker (same tasks offered, same order).
Acceptance criteria
- A benchmark test or script measures the open claim query for a current worker and a below-floor worker with a large backlog, and it can be re-run.
- Poll duration is logged, with a WARNING above a documented threshold (test for the WARNING).
- If a schema option ships: an Alembic migration that is additive, builds its index with plain
CREATE INDEX IF NOT EXISTSandSET LOCAL lock_timeout, and runs underMIGRATE_ON_STARTUPat server startup (test), plus a test that a below-floor worker and a current worker get the same tasks as before, and a test that a queued task with a NULL column that uses stored secrets is still withheld from a below-floor worker. - Existing deployments keep working without config changes, and the poll response format is unchanged.
- CHANGELOG entry under Unreleased.
Open questions
Which schema option, if any, after the measurement?
- Option 1: static column. At task creation, store whether
payload.task_envdeclares at least one name (the same rule aspayload_declares_task_env_sql,server/orcaster_server/task_secrets/gate.py:142). Add a partial index on queued tasks for it. A below-floor worker can skip tasks that declare nothing without theEXISTS. The value never changes once set, so it cannot drift. NULL rows fall back to theEXISTS(see Compatibility). The scan stays linear in the number of tasks that declare a name. - Option 2: maintained flag. Store
uses_stored_secretsand recompute it for queued tasks when a secret is set or deleted. Fastest poll, but it adds writes to the secret paths and the flag can drift, so it needs a repair step. - Option 3: no schema change. Keep only steps 1 and 2.
Option 3 changes nothing for existing deployments. Option 1 is the safer schema option, because the column is set once, an old server ignores it, and NULL falls back to today's check.
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 10
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AInvirion/orcaster
-
enhancement P3 server
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
enhancement good first issue P3 server
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug P2 server
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
bug P3 server
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
enhancement P3 server
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
All issues in AInvirion/orcaster
Similar issues
-
[Resource]: SpaicelyOpenresource-submission validation-passed
Difficulty 1/5 Under an hour Newbie friendliness 68/100
hesreallyhim/awesome-claude-code#3875 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
bvis/aegis-hass#725 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
datasektionen/cashflow#468 ·
-
dont call alembic upgrade until we check whether or not the cache DB has an alembic version stampOpen
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Bug: AttributeError: 'GptOssConfig' object has no attribute 'rope_scaling_factor' with transformers >= 5.xPossibly taken @NimaVaziri claimed this today. OpenPytorch
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NVIDIA/TensorRT-LLM#23406 ·
Maintainers usually reply within 1 day