Repository navigation
feat(worker): stage-class workers with concurrent slots (D146) - #533
Conversation
a567879 to
edf945f
Compare
Address Codex round 1 on #533: a slot probes for due routes before taking a claim token, so idle wake-ups never drain the bucket; the upgrade guide stops with `docker compose down --remove-orphans` so retired per-stage workers do not keep running. Rebased onto the merged library seams (D144): the class worker builds on the profile's `_worker`, now over several stages; this decision is D146 and the claim-lease decision is D145. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
90610c4 to
3c2d4bd
Compare
Codex review round 1 (gpt-6.1-sol, max)VERDICT: REQUEST_CHANGES Reviewed through
Validation: 83 focused checks, 21 reuse/worker checks, and the new reaper check passed; one documented D122 expected failure. Two-account interleaving passed. The due-route probe used indexed route lookups with 100,000 pending rows. No Rule 4 reuse boundary changed. I made no repository edits. |
Dispositions for Codex round 1 (fixed in 3c2d4bd)
Also in this push, found while waiting for the review: only a real claim wakes another slot ( |
edf945f to
4efd3ff
Compare
Address Codex round 1 on #533: a slot probes for due routes before taking a claim token, so idle wake-ups never drain the bucket; the upgrade guide stops with `docker compose down --remove-orphans` so retired per-stage workers do not keep running. Rebased onto the merged library seams (D144): the class worker builds on the profile's `_worker`, now over several stages; this decision is D146 and the claim-lease decision is D145. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
fdde26c to
0936e16
Compare
Codex review round 2 (gpt-6.1-sol, max)VERDICT: APPROVE No blocker or major findings. Both round-1 fixes and the rebase resolutions check out. Minor — e3_entity_obs_flush_fanout_design.md:283 still recommends scaling the retired Validation: 125 targeted tests passed, one documented expected failure; the worker-class suite passed three additional runs. Shutdown/join, exception propagation, empty-bucket behavior, and index use checked successfully. Ruff and Pyright passed. Rule 4 reuse regressions passed. No files modified; disposable Postgres removed. DispositionMinor fixed in 0936e16: the obs-flush fan-out design now points at the |
4efd3ff to
68d50ef
Compare
Address Codex round 1 on #533: a slot probes for due routes before taking a claim token, so idle wake-ups never drain the bucket; the upgrade guide stops with `docker compose down --remove-orphans` so retired per-stage workers do not keep running. Rebased onto the merged library seams (D144): the class worker builds on the profile's `_worker`, now over several stages; this decision is D146 and the claim-lease decision is D145. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
0936e16 to
80b1f30
Compare
Address Codex round 1 on #533: a slot probes for due routes before taking a claim token, so idle wake-ups never drain the bucket; the upgrade guide stops with `docker compose down --remove-orphans` so retired per-stage workers do not keep running. Rebased onto the merged library seams (D144): the class worker builds on the profile's `_worker`, now over several stages; this decision is D146 and the claim-lease decision is D145. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
80b1f30 to
f3f1a32
Compare
05d46a2 to
72b49f7
Compare
`worker --class convert|llm [--concurrency N]` serves every stage of its class from one process with N tasks in flight (convert 1, llm 20 by default). Slots claim the first route with due work: steady lanes before backfill, downstream stages first, found by one probe query. LISTEN/NOTIFY and SKIP LOCKED stay; a wake-up rouses one idle slot and a slot that finds work rouses one more. The main thread runs the lease reaper. The worker's database pool is sized from its concurrency. Compose runs worker-convert and worker-llm instead of fourteen stage workers; docs, the LoCoMo shard runner, CI service lists and the design corpus follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
A route the probe lists but no slot can claim (a held window-review route) made slots wake each other in a loop. Worker.run_one now takes an on_claimed callback, called between the claim and the handler, and the claimed-attempt execution is its own small method, run_claimed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
WorkLedger.reap_expired_leases takes stages=None to sweep all stages, so a sweeper serving many deployment databases can run one pass per database. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Address Codex round 1 on #533: a slot probes for due routes before taking a claim token, so idle wake-ups never drain the bucket; the upgrade guide stops with `docker compose down --remove-orphans` so retired per-stage workers do not keep running. Rebased onto the merged library seams (D144): the class worker builds on the profile's `_worker`, now over several stages; this decision is D146 and the claim-lease decision is D145. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
…ptions=) Use the engine_options seam agreed with the library-seams track instead of a worker-specific keyword. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
…gn at the llm class Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
f3f1a32 to
7ff63bb
Compare
Relaunch plan phase 2 item (b): stage-class worker (UMC
design/plan/relaunch-shared-runtime.mdphase 2b; reasoning and the class table in the UMC relaunch analysis §3 items 1, 2, 4, 5). Builds on #529 (claim leases, merged).What changes
worker --class convert|llm [--concurrency N]replacesworker --stage STAGE.convert= theconvertstage, default concurrency 1;llm= every other stage, default 20 (WORKER_CLASSES,DEFAULT_WORKER_CONCURRENCYinprofiles/selfhost.py).SelfHostWorkerLoopnow serves a class: N slot threads each run one task at a time through the unchangedWorker.run_one. The main thread holds theLISTENconnection, runs the D145 reaper, and on each notification or fallback poll wakes one idle slot; a slot that finds due work wakes one more before running it, so idle slots look for work one at a time and a burst ramps up quickly.TokenBucketis now thread-safe.WorkLedger.due_routes()finds the routes with claimable work in one probe query that reuses the claim's own due predicate (_CLAIMABLE), so an idle class worker does not open one claim transaction per empty route.WorkLedger.reap_expired_leases(deployment_id, stages=None)sweeps every stage in one pass, so a sweeper serving many deployment databases without their handlers can call it per database (it then announces requeued rows and runs dead-lettered rows' finalizers itself).Worker.run_onedelegates to a publicWorker.run_claimed(claimed, started_ns);run_one(on_claimed=...)lets the loop wake another slot only after a real claim. The profile's_worker(stages=...)(from the D147 library seams) now builds a worker for several stages and is shared byworker_loopandrun_task.SelfHostProfile.from_settings(settings, engine_options=...)(the shared seam agreed with the library-seams track) lets the worker command size the worker's general pool toN + 2plusNoverflow (one code path nests a read inside a transaction, so a task can briefly hold two connections; renewals and the reaper need a few more). API/setup keep the old pool.compose.yamlrunsworker-convertandworker-llm(concurrency viaREMEMBERSTACK_SELFHOST_CONVERT_CONCURRENCY/REMEMBERSTACK_SELFHOST_LLM_CONCURRENCYinterpolated into the command) instead of fourteen stage workers. CI's quickstart and upgrade-gate service lists follow. There is no other Compose file in this repo that runs workers (.github/compose/upgrade-gate.yamlonly overridessetup).LOCOMO_*_WORKERSreplica knobs (28 replicas) becomeLOCOMO_LLM_CONCURRENCY(default 40), passed to Compose asREMEMBERSTACK_SELFHOST_LLM_CONCURRENCY.docker compose down --remove-orphans, so retired per-stage workers stop), install (services table), CLI reference, scaling (concurrency, containers, connection ceilings), requirements (ceilings, container count), troubleshooting, observability, versions-in-force, choose page,.env.example.Concurrency safety
An audit of the handler object graph found no shared mutable state mutated during
handle()(handlers, catalogs, P1 index, refreshers, adjudicators; one unlocked idempotentCascadeResolver._registeredflag whose race only re-runs anON CONFLICT DO NOTHINGseed). The sharedhttpx.Clientandboto3client are thread-safe. Known non-defects left as they are:boto3's defaultmax_pool_connections=10logs "pool is full" above 10 concurrent object-store calls (performance only); the structure stage's own 8-thread summary pool multiplies with concurrency.Tests
src/tests/adapters/test_selfhost_worker_classes.py(real Postgres):due_routeslists only routes with claimable work, in the caller's order;test_selfhost_profile.py: class split and order, CLI refuses--stage, unknown classes and concurrency 0; Compose wires exactly the two classes; connection-ceiling arithmetic.Rule 4 (D56)
No ingestion keyed input, chunking, extraction or reuse identity changes; the same handlers run, only scheduling changes.
🤖 Generated with Claude Code
https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm