Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
REMEMBERSTACK_POSTGRES_USER=rememberstack
REMEMBERSTACK_POSTGRES_DB=rememberstack
# PostgreSQL max_connections. The default 300 covers the stock stack's ceiling
# of 215 connections (API 23 + 12 workers x 16) with headroom; raise it when you
# add API replicas or worker containers.
# of 71 connections (API 23 + worker-llm 43 + worker-convert 5) with headroom;
# a worker needs 2 x concurrency + 3. Raise it when you add API replicas, worker
# containers or concurrency.
# REMEMBERSTACK_POSTGRES_MAX_CONNECTIONS=300
# Tasks in flight per worker container (D146): worker-llm runs every stage
# except convert; worker-convert converts one file at a time by default.
# REMEMBERSTACK_SELFHOST_LLM_CONCURRENCY=20
# REMEMBERSTACK_SELFHOST_CONVERT_CONCURRENCY=1
# Every variable in this file reaches the engine containers (compose.yaml
# loads .env with env_file), so any engine setting can be set here.
#
Expand Down
1 change: 1 addition & 0 deletions .github/ci/integration-paths.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ src/tests/adapters/test_mount_provisioning.py
src/tests/adapters/test_p1_ranked_pg.py
src/tests/adapters/test_postgres_p1_document_filters.py
src/tests/adapters/test_selfhost_queue.py
src/tests/adapters/test_selfhost_worker_classes.py
src/tests/eval/test_harness_skeleton.py
src/tests/eval/test_s58_consumption.py
src/tests/profiles/test_selfhost_profile.py
Expand Down
20 changes: 4 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,7 @@ jobs:
running_services="$(
docker compose --env-file .env ps --status running --services
)"
for service in \
api worker-convert worker-structure worker-chunk worker-embed-chunk \
worker-extract-claims worker-normalize-relations \
worker-adjudicate-observations worker-adjudicate-supersession \
worker-embed-claim worker-reconcile worker-label-relation; do
for service in api worker-convert worker-llm; do
printf '%s\n' "$running_services" | grep -qx "$service"
done
ingested="$(
Expand Down Expand Up @@ -389,11 +385,7 @@ jobs:

- name: Stage an upgrade from the prior schema
run: |
docker compose --env-file .env stop \
api worker-convert worker-structure worker-chunk worker-embed-chunk \
worker-extract-claims worker-normalize-relations \
worker-adjudicate-observations worker-adjudicate-supersession \
worker-embed-claim worker-reconcile worker-label-relation
docker compose --env-file .env stop api worker-convert worker-llm
# Build an empty pre-D119 fixture. Temporal/span migrations refuse
# lossy conversion or downgrade of populated stores.
docker compose --env-file .env run --rm --no-deps -T \
Expand Down Expand Up @@ -466,7 +458,7 @@ jobs:
docker compose "${compose_args[@]}" ps --status running --services
)"
test -z "$(printf '%s\n' "$running_services" \
| grep -E '^(api|worker-(convert|structure|chunk|embed-chunk|extract-claims|normalize-relations|adjudicate-observations|adjudicate-supersession|embed-claim|reconcile|label-relation))$' || true)"
| grep -E '^(api|worker-(convert|llm))$' || true)"
test "$(docker compose "${compose_args[@]}" exec -T postgres \
psql -U rememberstack -d rememberstack -Atc \
'SELECT version_num FROM alembic_version')" = 'p9_31_0052'
Expand All @@ -483,11 +475,7 @@ jobs:
running_services="$(
docker compose "${compose_args[@]}" ps --status running --services
)"
for service in \
api worker-convert worker-structure worker-chunk worker-embed-chunk \
worker-extract-claims worker-normalize-relations \
worker-adjudicate-observations worker-adjudicate-supersession \
worker-embed-claim worker-reconcile worker-label-relation; do
for service in api worker-convert worker-llm; do
printf '%s\n' "$running_services" | grep -qx "$service"
done
curl --fail http://localhost:8000/healthz
Expand Down
6 changes: 1 addition & 5 deletions benchmarks/locomo/sharding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,7 @@ as source-derived data.
| `LOCOMO_BACKUP_TOOL` | `benchmarks/locomo/sharding/store_backup.py` | backup tool path; use an absolute path only when operating a pinned clean campaign checkout with a newer compatible safety runner |
| `LOCOMO_COMPOSE_PROJECT` | `rememberstack` | Compose label used to resolve exactly four volumes |
| `LOCOMO_RUNNER_LOCK` | `/var/lock/rememberstack-locomo-shard.lock` | host-wide exclusive runner lock |
| `LOCOMO_EXTRACT_CLAIM_WORKERS` | `8` | chunk-level Selection worker replicas |
| `LOCOMO_GROUND_CLAIM_WORKERS` | `8` | chunk-level Claimify worker replicas |
| `LOCOMO_NORMALIZE_RELATION_WORKERS` | `6` | claim-level E3 normalize worker replicas |
| `LOCOMO_ADJUDICATE_OBSERVATION_WORKERS` | `4` | post-barrier observation-flush worker replicas |
| `LOCOMO_EMBED_CLAIM_WORKERS` | `2` | P1 claim/fact embedding worker replicas |
| `LOCOMO_LLM_CONCURRENCY` | `40` | tasks in flight in the `worker-llm` process, which serves every stage except `convert` |
| `LOCOMO_GCP_CREDENTIALS_FILE` | `/etc/rememberstack/locomo-gcs/credentials.json` | public external-account configuration |
| `LOCOMO_GCP_CERTIFICATE_CONFIG_FILE` | `/etc/rememberstack/locomo-gcs/certificate-config.json` | public client-certificate path configuration |
| `LOCOMO_VERTEX_GCP_CREDENTIALS_FILE` | unset | optional process-wide generation credential configuration; backups continue to use `LOCOMO_GCP_CREDENTIALS_FILE` |
Expand Down
28 changes: 6 additions & 22 deletions benchmarks/locomo/sharding/run_shard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ backup_project=${LOCOMO_GCP_PROJECT:-}
backup_staging_root=${LOCOMO_BACKUP_STAGING_ROOT:-/var/lib/rememberstack-locomo-backups}
compose_project=${LOCOMO_COMPOSE_PROJECT:-rememberstack}
runner_lock=${LOCOMO_RUNNER_LOCK:-/var/lock/rememberstack-locomo-shard.lock}
extract_claim_workers=${LOCOMO_EXTRACT_CLAIM_WORKERS:-8}
ground_claim_workers=${LOCOMO_GROUND_CLAIM_WORKERS:-8}
normalize_relation_workers=${LOCOMO_NORMALIZE_RELATION_WORKERS:-6}
adjudicate_observation_workers=${LOCOMO_ADJUDICATE_OBSERVATION_WORKERS:-4}
embed_claim_workers=${LOCOMO_EMBED_CLAIM_WORKERS:-2}
llm_concurrency=${LOCOMO_LLM_CONCURRENCY:-40}
backup_tool=${LOCOMO_BACKUP_TOOL:-benchmarks/locomo/sharding/store_backup.py}
compose=(docker compose --project-name "$compose_project")

Expand Down Expand Up @@ -104,11 +100,7 @@ for value in \
"$max_judge_calls" \
"$drain_timeout_seconds" \
"$drain_poll_seconds" \
"$extract_claim_workers" \
"$ground_claim_workers" \
"$normalize_relation_workers" \
"$adjudicate_observation_workers" \
"$embed_claim_workers"; do
"$llm_concurrency"; do
[[ "$value" =~ ^[1-9][0-9]*$ ]] || die "integer caps must be positive"
done

Expand Down Expand Up @@ -330,12 +322,8 @@ require_verified_final_backup() {
}

start_existing_store() {
"${compose[@]}" up --detach --wait --no-recreate \
--scale "worker-extract-claims=$extract_claim_workers" \
--scale "worker-ground-claims=$ground_claim_workers" \
--scale "worker-normalize-relations=$normalize_relation_workers" \
--scale "worker-adjudicate-observations=$adjudicate_observation_workers" \
--scale "worker-embed-claim=$embed_claim_workers"
REMEMBERSTACK_SELFHOST_LLM_CONCURRENCY="$llm_concurrency" \
"${compose[@]}" up --detach --wait --no-recreate
bind_benchmark_api
attest_worker_environment
}
Expand Down Expand Up @@ -464,12 +452,8 @@ for sample_id in "${pending_samples[@]}"; do
"${compose[@]}" down --volumes --remove-orphans
backup_python "$backup_tool" clear-live --run-dir "$run_dir" --lock-fd 9
log "sample=$sample_id stage=stack status=starting"
"${compose[@]}" up --detach --wait \
--scale "worker-extract-claims=$extract_claim_workers" \
--scale "worker-ground-claims=$ground_claim_workers" \
--scale "worker-normalize-relations=$normalize_relation_workers" \
--scale "worker-adjudicate-observations=$adjudicate_observation_workers" \
--scale "worker-embed-claim=$embed_claim_workers"
REMEMBERSTACK_SELFHOST_LLM_CONCURRENCY="$llm_concurrency" \
"${compose[@]}" up --detach --wait
bind_benchmark_api
attest_worker_environment
backup_python "$backup_tool" record-live \
Expand Down
94 changes: 7 additions & 87 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,100 +237,20 @@ services:
# otherwise; set a token before publishing on another address.
- "${REMEMBERSTACK_SELFHOST_API_PUBLISH_ADDRESS:-127.0.0.1}:${REMEMBERSTACK_SELFHOST_API_PORT}:8000"

# Two worker classes (D146): `convert` runs one conversion at a time, so its
# memory is bounded by the largest allowed input; `llm` serves every other
# stage with many tasks in flight. Scale either with `--scale` or with its
# concurrency.
worker-convert:
<<: *app
command: ["worker", "--stage", "convert"]
command: ["worker", "--class", "convert", "--concurrency", "${REMEMBERSTACK_SELFHOST_CONVERT_CONCURRENCY:-1}"]
depends_on:
setup:
condition: service_completed_successfully

worker-structure:
worker-llm:
<<: *app
command: ["worker", "--stage", "structure"]
depends_on:
setup:
condition: service_completed_successfully

worker-crossref:
<<: *app
command: ["worker", "--stage", "crossref"]
depends_on:
setup:
condition: service_completed_successfully

worker-chunk:
<<: *app
command: ["worker", "--stage", "chunk"]
depends_on:
setup:
condition: service_completed_successfully

worker-embed-chunk:
<<: *app
command: ["worker", "--stage", "embed_chunk"]
depends_on:
setup:
condition: service_completed_successfully

worker-extract-claims:
<<: *app
command: ["worker", "--stage", "extract_claims"]
depends_on:
setup:
condition: service_completed_successfully

worker-ground-claims:
<<: *app
command: ["worker", "--stage", "ground_claims"]
depends_on:
setup:
condition: service_completed_successfully

worker-normalize-relations:
<<: *app
command: ["worker", "--stage", "normalize_relations"]
depends_on:
setup:
condition: service_completed_successfully

worker-adjudicate-observations:
<<: *app
command: ["worker", "--stage", "adjudicate_observations"]
depends_on:
setup:
condition: service_completed_successfully

worker-adjudicate-supersession:
<<: *app
command: ["worker", "--stage", "adjudicate_supersession"]
depends_on:
setup:
condition: service_completed_successfully

worker-embed-claim:
<<: *app
command: ["worker", "--stage", "embed_claim"]
depends_on:
setup:
condition: service_completed_successfully

worker-reconcile:
<<: *app
command: ["worker", "--stage", "reconcile"]
depends_on:
setup:
condition: service_completed_successfully

worker-label-relation:
<<: *app
command: ["worker", "--stage", "label_relation"]
depends_on:
setup:
condition: service_completed_successfully

worker-review-fact-windows:
<<: *app
command: ["worker", "--stage", "review_fact_windows"]
command: ["worker", "--class", "llm", "--concurrency", "${REMEMBERSTACK_SELFHOST_LLM_CONCURRENCY:-20}"]
depends_on:
setup:
condition: service_completed_successfully
Expand Down
37 changes: 37 additions & 0 deletions decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7455,3 +7455,40 @@ first sweep recovers them. [Orchestration §6](plan/designs/orchestration_design
holds the contract; [schema §2](plan/designs/postgres_schema_design.md) the column, index and
queries.

## D146. One worker process serves a class of stages, with a fixed number of tasks in flight

**Status:** accepted. **Date:** 2026-11-06.

**Context.** Each pipeline stage ran in its own worker process (fourteen in the stock Compose),
each importing the full dependency set, holding its own database pool and `LISTEN` connection,
being woken by every notification, and running one task at a time. Almost every stage spends
its time waiting on a model, embedding or database call, so this was the most memory for the
least concurrency: about two thirds of an idle deployment's memory, and one task per stage in
flight even during a large upload. A combined worker must still never run out of memory, and
conversion's memory grows with the input.

**Decision.**

- Two **worker classes**: `convert` (the `convert` stage) and `llm` (every other stage).
`worker --class convert|llm [--concurrency N]` serves every stage of its class from one
process with N tasks in flight, each in its own thread. Starting points to be measured:
`convert` 1, `llm` 20. No dynamic memory accounting: a class's process is sized as peak memory
per task × concurrency + headroom.
- **Fair order:** a free slot claims from the first route with due work in the order steady
lanes, then backfill lanes, each with stages downstream first, so work already in the pipeline
drains before new uploads take the slots. One probe query finds the routes with due work.
- **Delivery is unchanged:** `LISTEN/NOTIFY` wake-ups and `SELECT … FOR UPDATE SKIP LOCKED`
claims (D67). A wake-up rouses one idle slot; a slot that finds work rouses one more. Claim
leases (D145) make it safe for a class process to die with many tasks in flight.
- A process's database pool is sized from its concurrency.

**Alternatives.** One process per stage with in-process concurrency keeps fourteen idle
interpreters. A single class for everything lets one large conversion share a process, and its
memory, with twenty LLM tasks. Asynchronous handlers would need every handler and adapter
rewritten; threads reuse the synchronous handlers, which share no mutable state.

**Consequences.** The stock Compose runs `worker-convert` and `worker-llm`
(`REMEMBERSTACK_SELFHOST_CONVERT_CONCURRENCY`, `REMEMBERSTACK_SELFHOST_LLM_CONCURRENCY`) instead
of fourteen stage workers; `worker --stage` is gone. Contract in
[packaging §3, worker classes](plan/designs/packaging_distribution_design.md#3-task-execution--one-model-two-delivery-shells).

4 changes: 2 additions & 2 deletions design/benchmarks/runbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ Manual equivalents, when you need them:
| --- | --- | --- |
| `answer` refuses: deployment lacks required pipeline/P1/live-graph/P3 capability readiness | Drain not actually complete, live graph catalog/helper health failed, or P3 published before the last ingest event | Finish the true drain, repair live graph catalog if reported, rebuild P3, then answer. P3 must follow ingest. |
| Rows stuck in `dead_letter` | A chunk's extraction (or a relation stage) exhausted 3 attempts — usually glm non-JSON (#174) | `docker compose exec -T api remember ops replay <processing_id> --deployment <id> --attempts 3`, then wait for the drain again. In practice one replay round clears it; bound retries (the wrappers use 3 rounds) so a truly poisoned chunk stops the run loudly instead of looping. |
| A worker reports a model different from `state.json` | A separate post-launch `docker compose up --scale` read stale ambient `.env` values and created a mixed-model fleet | Stop the invalid run. Relaunch through `run_shard.sh` only; set its `LOCOMO_*_WORKERS` variables if different replica counts are needed. The runner attests every app container before ingest and during every drain poll. |
| Extract or normalize remains slow | Replica counts are too low for the current chunk/claim fan-out | Set `LOCOMO_EXTRACT_CLAIM_WORKERS`, `LOCOMO_NORMALIZE_RELATION_WORKERS`, `LOCOMO_ADJUDICATE_OBSERVATION_WORKERS`, or `LOCOMO_EMBED_CLAIM_WORKERS` on the original `run_shard.sh` invocation. Never scale the benchmark with a second Compose command. |
| A worker reports a model different from `state.json` | A separate post-launch `docker compose up --scale` read stale ambient `.env` values and created a mixed-model fleet | Stop the invalid run. Relaunch through `run_shard.sh` only; set its `LOCOMO_LLM_CONCURRENCY` if a different concurrency is needed. The runner attests every app container before ingest and during every drain poll. |
| Extract or normalize remains slow | The `worker-llm` concurrency is too low for the current chunk/claim fan-out | Set `LOCOMO_LLM_CONCURRENCY` on the original `run_shard.sh` invocation. Never scale the benchmark with a second Compose command. |
| run_shard refuses: "partial checkpoint; resume stages manually" | A previous attempt died mid-sample, leaving partial ingest/answer records in the run dir | If the stack matches the checkpoint, run the incomplete stage directly; `ingest` first proves the exact public live-lineage/visible-version join. If it does not match and the sample has no answer/judge records, rerun that sample in a new run directory and merge it with the old run. If any answer/judge record exists, restart every sample assigned to that run directory; merging a replacement sample would correctly fail as overlap. Never edit or force a checkpoint forward. |
| Item failures recorded in run state | Per-item failures are terminal in that run | Missing items (never attempted, e.g. after a stage-level refusal) can be answered in the same run dir. A terminal failed item requires a fresh deployment and restarting every sample assigned to that run directory; a replacement sample cannot be merged over existing records. |
| Preflight/answer/judge cost cap hit | Caps are run-cumulative, not per-invocation | Pass a positive finite run-absolute cap (`--max-evaluator-cost-usd`), sized from §7. |
Expand Down
8 changes: 4 additions & 4 deletions plan/designs/chunk_level_extract_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ workers and tests without reopening product debate.
## 1. Problem

`extract_claims` is leased **once per document version** and then walks every E1
chunk serially inside one handler. Scaling `worker-extract-claims` does not
chunk serially inside one handler. Scaling the `extract_claims` workers does not
parallelize Claimify on a single large document (BEAM 1M/10M). E1 already
partitions text into section-bounded chunks; the ledger must claim work at that
grain.
Expand Down Expand Up @@ -174,7 +174,7 @@ Connector-cycle finalization SQL must likewise wait on pending/running/failed

`processing_state` aggregates by `stage` already power readiness. After this
change, `extract_claims` pending/running counts approximate **chunk** backlog.
Document for operators and UMC: scale `worker-extract-claims` on that depth.
Document for operators and UMC: scale the `llm` worker class (D146) on that depth.

No new public HTTP API is required for v1.

Expand Down Expand Up @@ -207,7 +207,7 @@ Chunk ids are internal UUIDs; no new mount surface.

### 9.1 Auto-deploy

- Same container image, same worker entrypoints (`worker --stage extract_claims`).
- Same container image, same worker entrypoint (`worker --class llm`, D146).
- No new Coolify service names, secrets, or migrations of the `processing_target`
enum (CHUNK already exists). Alembic may still be needed only if readiness SQL
lives purely in app code (preferred).
Expand All @@ -224,7 +224,7 @@ UMC must **not** manufacture extract work. It may:

1. Observe OSS `processing_state` (or a safe aggregate export) for
`stage=extract_claims`, statuses pending/running.
2. Set replica count for the data-plane `worker-extract-claims` process.
2. Set the concurrency or replica count of the data-plane `llm` worker class (D146).

Chunk-level grain makes that observation **useful**. Control plane remains non-
authoritative for work truth (D2/D6/D67 as used in UMC integration analysis).
Expand Down
5 changes: 3 additions & 2 deletions plan/designs/e3_claim_level_normalize_fanout_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,9 @@ retry then drop; systemic provider/DB re-raise; mint defense; cost keys

## 9. UMC / compose

Same image; `worker --stage normalize_relations`. Scale on claim-grain
pending/running. No control-plane work manufacture (D67). Single-revision
Same image; `normalize_relations` runs in the `llm` worker class
(`worker --class llm`, D146). Scale that class's concurrency or containers on
claim-grain pending/running. No control-plane work manufacture (D67). Single-revision
deploy for all normalize workers.

## 10. Implementation plan (ordered)
Expand Down
2 changes: 1 addition & 1 deletion plan/designs/e3_entity_obs_flush_fanout_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ E1/E2 zero-chunk paths): after the component-version bump they must either:

### 5.9 Workers and indexes

- Stage name unchanged; scale `worker-adjudicate-observations`.
- Stage name unchanged; it runs in the `llm` worker class (D146): scale that class's concurrency or containers.
- Handler dispatches: entity unit (`target_kind=entity` + fan-out version) vs
legacy document_version + pre-fanout version.
- Indexes: membership by version; processing partial index on entity target_kind
Expand Down
Loading
Loading