Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
dd80249
feat(runtime): durable Work Ledger rebased onto current master
jasondeng1997 Oct 29, 2026
3243572
fix(migration): register the Work Ledger boolean column as TINYINT(1)
jasondeng1997 Oct 29, 2026
3026ca2
test(native): expect the new head revision after the personal-service…
jasondeng1997 Oct 29, 2026
9683d25
refactor(migration): name the Work Ledger revision v1_4_1_006
jasondeng1997 Oct 29, 2026
b311e14
feat(server): compose the durable Work Ledger into the runtime
jasondeng1997 Oct 29, 2026
02ca795
fix(runtime): keep the Work Ledger and the APScheduler supervisors ex…
jasondeng1997 Oct 29, 2026
8f74ab2
docs: describe which scheduler owns a Family in each deployment mode
jasondeng1997 Oct 29, 2026
8005d53
fix(dsh): rebuild the plugin bundle from the committed operation catalog
jasondeng1997 Oct 29, 2026
1fa2a0c
fix(config): validate a distributed deployment against its real role
jasondeng1997 Oct 29, 2026
feb9e7f
test(zcode): re-issue the bounded boundary flush instead of racing it…
jasondeng1997 Oct 30, 2026
11f4319
feat(server): serve the durable operation endpoints the docs promise
jasondeng1997 Oct 30, 2026
cf81c1a
chore(desktop): regenerate the contract types for the new operation p…
jasondeng1997 Oct 30, 2026
886a0cf
chore(desktop): qualify the bundled contract for the new operation paths
jasondeng1997 Oct 30, 2026
843aac3
Merge up/master (745ebf2e) into the Work Ledger branch
jasondeng1997 Nov 2, 2026
d9f33be
fix(persistence): finish the v1_4_1_007 renumbering after the master …
jasondeng1997 Nov 2, 2026
5fa749d
chore(desktop): qualify the merged contract for the renumbered chain
jasondeng1997 Nov 2, 2026
20bd462
fix(migrations): append the Work Ledger after the published v1_5_0_00…
jasondeng1997 Nov 4, 2026
c9934b7
fix(docker): run the migrator through the supported db-migrate plan/a…
jasondeng1997 Nov 4, 2026
719c826
fix(runtime): fence the Memory publication with the Work completion
jasondeng1997 Nov 4, 2026
33eb25e
fix(server): gate the data plane by deployment role in the factory ou…
jasondeng1997 Nov 4, 2026
ccef697
fix(runtime): keep the cron next run in the future across DST transit…
jasondeng1997 Nov 4, 2026
7512efb
fix(runtime): bound the rate limit window table in single-node installs
jasondeng1997 Nov 4, 2026
448e152
fix(runtime): wire the WorkObserver into the composed ledger
jasondeng1997 Nov 4, 2026
88baf5a
Merge up/master (1c52626d) into the Work Ledger branch
jasondeng1997 Nov 4, 2026
4e8b30a
chore(desktop): regenerate the contract artifacts for the merged OpenAPI
jasondeng1997 Nov 4, 2026
a8cb90e
chore(desktop): qualify the merged bundled contract (4e8b30aa)
jasondeng1997 Nov 4, 2026
5cfc8e1
Merge remote-tracking branch 'origin/master' into rebase/onto-master
jasondeng1997 Nov 4, 2026
b175d3a
test(migration): expect the appended v1_5_0_004 head
jasondeng1997 Nov 4, 2026
da48a23
fix(runtime): return the earliest future cron occurrence on transitio…
jasondeng1997 Nov 4, 2026
5a0a1f4
fix(docker): escape the migrator's shell variables from Compose
jasondeng1997 Nov 4, 2026
3c03a47
fix(runtime): pin Memory preparation to the persisted window
jasondeng1997 Nov 4, 2026
fad4d46
docs(operate): use the Server-prefixed generation model variable
jasondeng1997 Nov 4, 2026
6e7bac2
docs(desktop): keep this branch's protocol qualification records
jasondeng1997 Nov 4, 2026
3c37a15
style: apply ruff formatting to the review fixes
jasondeng1997 Nov 4, 2026
deda9e1
fix(migrations): back up the Work Ledger tables with the rest of the …
jasondeng1997 Nov 4, 2026
3df12c9
test(persistence): follow the v1_5_0_004 head in the evidence upgrade…
jasondeng1997 Nov 4, 2026
e03e4ee
docs(desktop): qualify the merged Desktop contract b4d241e6
jasondeng1997 Nov 4, 2026
b1eef2f
refactor(server): keep create_app inside the complexity budget
jasondeng1997 Nov 4, 2026
2dcc253
style: restore the formatter and end-of-file output CI enforces
jasondeng1997 Nov 4, 2026
51c3e61
fix(runtime): report rate limit maintenance failures instead of dropp…
jasondeng1997 Nov 4, 2026
294a3d9
test: satisfy the repository type gate for the new Work Ledger fixtures
jasondeng1997 Nov 4, 2026
44d6b76
test(cli): expect the Work Ledger head from the packaged migration chain
jasondeng1997 Nov 4, 2026
6c2aa7a
Merge remote-tracking branch 'origin/master' into rebase/onto-master
jasondeng1997 Nov 5, 2026
8ea1ae2
docs(desktop): qualify the merged contract after restoring statistics
jasondeng1997 Nov 5, 2026
3535c29
perf(migrations): declare the Work Ledger indexes inline on MySQL
jasondeng1997 Nov 5, 2026
906beae
Merge remote-tracking branch 'origin/master' into rebase/onto-master
jasondeng1997 Nov 5, 2026
44cc6b0
fix(review): rebuild the OpenCode bundle and close the remaining revi…
jasondeng1997 Nov 5, 2026
cd7e4be
Merge remote-tracking branch 'origin/master' into rebase/onto-master
jasondeng1997 Nov 5, 2026
9efb56f
fix(desktop): qualify the bundled contract after the Operations paths
jasondeng1997 Nov 5, 2026
89e8170
docs(desktop): record the clean-tree qualification run
jasondeng1997 Nov 5, 2026
2101fe8
test(work): keep the distributed authorizer check type-checkable
jasondeng1997 Nov 5, 2026
15a75c3
ci: raise the two deadlines the v1_5_0_004 chain outgrew
jasondeng1997 Nov 6, 2026
73fb088
Merge remote-tracking branch 'origin/master' into rebase/onto-master
jasondeng1997 Nov 6, 2026
9da3a20
fix(gateway): carry the license header until #2504 lands
jasondeng1997 Nov 6, 2026
95e1626
fix(tests): treat ESRCH as a vanished process in release gate probe
jasondeng1997 Nov 6, 2026
8464c73
Merge remote-tracking branch 'origin/master' into rebase/onto-master
jasondeng1997 Nov 6, 2026
0658894
refactor(migrations): renumber the Work Ledger revision to v1_5_0_005
jasondeng1997 Nov 9, 2026
6836557
Merge remote-tracking branch 'origin/master' into rebase/onto-master
jasondeng1997 Nov 9, 2026
2cb8da3
fix(migrations): chain the Work Ledger after v1_5_0_004
jasondeng1997 Nov 9, 2026
182106b
fix(desktop,runtime): requalify the merged contract and renew schedul…
jasondeng1997 Nov 9, 2026
b9589ab
fix(runtime): publish ledger Memory under the worker's background pri…
jasondeng1997 Nov 9, 2026
7d716b6
Merge remote-tracking branch 'up/master' into rebase/onto-master
jasondeng1997 Nov 9, 2026
253ee2a
chore(desktop): qualify the merged 1.5.1 Work Ledger contract
jasondeng1997 Nov 9, 2026
c8b62cf
test(runtime): narrow the memory publication context for ty
jasondeng1997 Nov 9, 2026
fb2a984
fix(runtime): wait for the first cron boundary before Profile discovery
jasondeng1997 Nov 9, 2026
0bb9eda
fix(runtime): keep existing Profile cron configurations loadable
jasondeng1997 Nov 9, 2026
c9dd22b
fix(persistence): keep a repeated cancellation idempotent
jasondeng1997 Nov 9, 2026
bfbd2e9
fix(website): pin the generator to the griffe major fumapy imports
jasondeng1997 Nov 9, 2026
ed3accd
chore(release): declare the persistence digest for the cancellation fix
jasondeng1997 Nov 9, 2026
e767946
test(runtime): pin the idempotent cancel replay at the transport
jasondeng1997 Nov 9, 2026
0a478b2
fix(runtime): accept the legacy cron marker without relaxing validation
jasondeng1997 Nov 9, 2026
5a8dd23
chore(ci): pin the standalone Connector type checker to the locked ty
jasondeng1997 Nov 9, 2026
a25b6ad
fix(e2e): pin the ACP SDK Harbor's runner venv installs unpinned
jasondeng1997 Nov 9, 2026
7db9ebe
test(e2e): require the resolved pip index on every step that installs…
jasondeng1997 Nov 9, 2026
3eaccdd
test(inference): wait for the spawned worker's exit instead of racing it
jasondeng1997 Nov 9, 2026
9c43653
fix(e2e): pin the runner venv to the last ACP SDK release the runner …
jasondeng1997 Nov 10, 2026
8bc8aff
fix(runtime): retire ledger snapshots superseded by any racing cursor…
jasondeng1997 Nov 11, 2026
50a3b61
fix(runtime): recheck publication authorization in the Experience and…
jasondeng1997 Nov 11, 2026
6a889ff
fix(runtime): stop claiming ledger work while the membership is incom…
jasondeng1997 Nov 11, 2026
8099c4c
Merge up/master (d64381bf) into the Work Ledger branch
jasondeng1997 Nov 11, 2026
638ec46
refactor(runtime): separate the ledger background identity from its p…
jasondeng1997 Nov 11, 2026
95e0a35
test(dsh): declare the Memory contract on the synthetic setup fixture…
jasondeng1997 Nov 11, 2026
8faa834
test(dsh): declare the Memory contract in the explicit-Web doctor fix…
jasondeng1997 Nov 12, 2026
88c86f6
Merge up/master (fd9f1682b) into the Work Ledger branch
jasondeng1997 Nov 12, 2026
96d6db3
test(inference): make the spawned Codex worker exit deterministically
jasondeng1997 Nov 12, 2026
eb6a9dc
test(gateway): stop reusing half-closed keep-alive connections in aut…
jasondeng1997 Nov 12, 2026
d29754c
test(e2e): reserve the source manager port immediately before spawnin…
jasondeng1997 Nov 13, 2026
8d9d107
Merge up/master (1cb0e75db) into the Work Ledger branch
jasondeng1997 Nov 13, 2026
c441634
chore(desktop): qualify the merged Work Ledger / task stop reason con…
jasondeng1997 Nov 13, 2026
c08c8c6
fix(runtime): recheck Scope contribution inside the Profile publicati…
jasondeng1997 Nov 13, 2026
db2c2cf
docs(desktop): pin the merged-contract qualification anchor
jasondeng1997 Nov 13, 2026
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
36 changes: 36 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,42 @@ POWERCONTEXT_SERVER_DATABASE_KIND=sqlite
# POWERCONTEXT_SERVER_DATABASE_KIND=seekdb
# POWERCONTEXT_SERVER_DATABASE_PATH=/absolute/path/to/seekdb

# Deployment and durable work -------------------------------------------------
# Local installs run every role in one process. Distributed mode requires OceanBase and one role per process.
POWERCONTEXT_SERVER_DEPLOYMENT_MODE=single_node
POWERCONTEXT_SERVER_DEPLOYMENT_ROLE=all
POWERCONTEXT_SERVER_DEPLOYMENT_ID=local
POWERCONTEXT_SERVER_DEPLOYMENT_BEHAVIOR_REVISION=default

# Scheduler and member leases use database time. Renewal must stay within the validated lease ratios.
POWERCONTEXT_SERVER_COORDINATION_SCHEDULER_LEASE_SECONDS=30
POWERCONTEXT_SERVER_COORDINATION_SCHEDULER_RENEW_SECONDS=10
POWERCONTEXT_SERVER_COORDINATION_SCAN_PAGE_SIZE=100
POWERCONTEXT_SERVER_COORDINATION_MEMBER_TTL_SECONDS=30
POWERCONTEXT_SERVER_COORDINATION_MEMBER_HEARTBEAT_SECONDS=10
POWERCONTEXT_SERVER_COORDINATION_EMIT_PAYLOAD_VERSION=1

POWERCONTEXT_SERVER_WORKER_CONCURRENCY=4
POWERCONTEXT_SERVER_WORKER_LEASE_SECONDS=120
POWERCONTEXT_SERVER_WORKER_HEARTBEAT_SECONDS=30
POWERCONTEXT_SERVER_WORKER_SHUTDOWN_GRACE_SECONDS=90
POWERCONTEXT_SERVER_WORKER_MAX_ATTEMPTS=5
POWERCONTEXT_SERVER_WORKER_RETRY_BASE_SECONDS=2
POWERCONTEXT_SERVER_WORKER_RETRY_MAX_SECONDS=300
POWERCONTEXT_SERVER_WORKER_POLL_SECONDS=1

POWERCONTEXT_SERVER_OPERATIONS_DEFAULT_WAIT_SECONDS=10
POWERCONTEXT_SERVER_OPERATIONS_MAXIMUM_WAIT_SECONDS=30
POWERCONTEXT_SERVER_OPERATIONS_POLL_SECONDS=0.2
POWERCONTEXT_SERVER_OPERATIONS_RETENTION_DAYS=30
POWERCONTEXT_SERVER_OPERATIONS_CLEANUP_BATCH_SIZE=500
POWERCONTEXT_SERVER_OPERATIONS_CLEANUP_INTERVAL_SECONDS=3600

# Shared OceanBase fixed-window limiting is optional and disabled by default.
POWERCONTEXT_SERVER_RATE_LIMIT_ENABLED=false
POWERCONTEXT_SERVER_RATE_LIMIT_REQUESTS=120
POWERCONTEXT_SERVER_RATE_LIMIT_WINDOW_SECONDS=60

# Runtime ---------------------------------------------------------------------
POWERCONTEXT_SERVER_RUNTIME_SOURCE_WINDOW_LIMIT=100
# Maximum sum of explicit assembly section limits; per-family limits still apply.
Expand Down
2 changes: 2 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ header:
- 'src/powercontext/server/dashboard/static/vendor/**'
- '.gitattributes'
- '**/*.service.in'
# license-eye cannot determine the comment style of Alembic's Mako template.
- 'src/powercontext/builtin/persistence/migrations/script.py.mako'
- '**/*.jsonl'
# license-eye cannot determine the comment style of patch files.
- '**/*.patch'
Expand Down
7 changes: 6 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ docker build \
.
```

Run the Server with persistent SQLite and scheduler data:
Run the Server with persistent SQLite application and Work Ledger data:

```bash
docker run --rm \
Expand All @@ -34,6 +34,11 @@ requests share one refresh. Checks use the Runtime's credentials and never expos
another database or inference provider with the same `POWERCONTEXT_SERVER_*` environment variables used by a regular
Server installation.

For a role-separated OceanBase topology, use `docker/compose.distributed.yaml` as a deployment template. It runs a
one-shot migrator, two API replicas, two fenced Scheduler replicas, and two lease-based Worker replicas. Replace the
example database credentials, authentication token, and provider configuration before starting it; only Workers need
model credentials.

## Network exposure

PowerContext refuses to start an unauthenticated Server on a non-loopback address unless
Expand Down
112 changes: 112 additions & 0 deletions docker/compose.distributed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: powercontext-distributed

x-runtime: &runtime
image: ${POWERCONTEXT_IMAGE:-powercontext-server:local}
restart: unless-stopped
environment: &shared-environment
POWERCONTEXT_SERVER_DATABASE_KIND: oceanbase
POWERCONTEXT_SERVER_DATABASE_URL: ${POWERCONTEXT_SERVER_DATABASE_URL:?set an OceanBase URL}
POWERCONTEXT_SERVER_DEPLOYMENT_MODE: distributed
POWERCONTEXT_SERVER_DEPLOYMENT_BEHAVIOR_REVISION: ${POWERCONTEXT_BEHAVIOR_REVISION:-distributed-v1}
POWERCONTEXT_SERVER_RUNTIME_SCHEDULE_SECONDS: ${POWERCONTEXT_MEMORY_SCHEDULE_SECONDS:-60}
POWERCONTEXT_SERVER_RUNTIME_EXPERIENCE_SCHEDULE_SECONDS: ${POWERCONTEXT_EXPERIENCE_SCHEDULE_SECONDS:-60}

services:
migrate:
<<: *runtime
restart: "no"
command: ["server", "migrate"]
Comment thread
Copilot marked this conversation as resolved.
Resolved
environment:
<<: *shared-environment
# The migration command does not start a Runtime or register this role;
# a valid distributed role is still required while parsing ServerSettings.
POWERCONTEXT_SERVER_DEPLOYMENT_ROLE: api
POWERCONTEXT_SERVER_DEPLOYMENT_ID: migrator

api-a:
<<: *runtime
command: ["server", "run"]
environment:
<<: *shared-environment
POWERCONTEXT_SERVER_DEPLOYMENT_ROLE: api
POWERCONTEXT_SERVER_DEPLOYMENT_ID: api-a
POWERCONTEXT_SERVER_AUTH_ENABLED: "true"
POWERCONTEXT_SERVER_AUTH_TOKEN: ${POWERCONTEXT_SERVER_AUTH_TOKEN:?set an API bearer token}
POWERCONTEXT_SERVER_RATE_LIMIT_ENABLED: "true"
ports: ["127.0.0.1:8001:8000"]
depends_on:
migrate:
condition: service_completed_successfully

api-b:
<<: *runtime
command: ["server", "run"]
environment:
<<: *shared-environment
POWERCONTEXT_SERVER_DEPLOYMENT_ROLE: api
POWERCONTEXT_SERVER_DEPLOYMENT_ID: api-b
POWERCONTEXT_SERVER_AUTH_ENABLED: "true"
POWERCONTEXT_SERVER_AUTH_TOKEN: ${POWERCONTEXT_SERVER_AUTH_TOKEN:?set an API bearer token}
POWERCONTEXT_SERVER_RATE_LIMIT_ENABLED: "true"
ports: ["127.0.0.1:8002:8000"]
depends_on:
migrate:
condition: service_completed_successfully

scheduler-a:
<<: *runtime
command: ["server", "run"]
environment:
<<: *shared-environment
POWERCONTEXT_SERVER_DEPLOYMENT_ROLE: scheduler
POWERCONTEXT_SERVER_DEPLOYMENT_ID: scheduler-a
POWERCONTEXT_SERVER_DASHBOARD_ENABLED: "false"
POWERCONTEXT_SERVER_MCP_ENABLED: "false"
depends_on:
migrate:
condition: service_completed_successfully

scheduler-b:
<<: *runtime
command: ["server", "run"]
environment:
<<: *shared-environment
POWERCONTEXT_SERVER_DEPLOYMENT_ROLE: scheduler
POWERCONTEXT_SERVER_DEPLOYMENT_ID: scheduler-b
POWERCONTEXT_SERVER_DASHBOARD_ENABLED: "false"
POWERCONTEXT_SERVER_MCP_ENABLED: "false"
depends_on:
migrate:
condition: service_completed_successfully

worker-a:
<<: *runtime
command: ["server", "run"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 33eb25e9. create_app gained route_profile="full" | "health"; create_server_app computes it from the deployment: distributed scheduler/worker get the health profile, which registers only /health/live, /health/ready and /metrics — no /v1/ data-plane routes and no openapi/docs. Distributed api and single_node keep the full profile, and a health profile with Dashboard or MCP enabled is rejected at composition time.

tests/test_server_role_routes.py (5 tests) pins the exact route sets: scheduler/worker expose exactly the three health/metrics routes; api/single_node retain /v1/memory/flush and /v1/scopes/{scope_id}/operations. The existing contract/health/rate-limit/metrics suites still pass (83 passed, 1 skipped).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wired to a restricted listener. src/powercontext/server/factory.py:219 selects route_profile="health" when deployment.mode == "distributed" and deployment.role in {"scheduler", "worker"}; in that profile src/powercontext/server/app.py:1496 disables /openapi.json and mounts only the health/metrics boundary, and the factory rejects Dashboard or MCP enabled for those roles.

docker/compose.distributed.yaml runs all four background services with POWERCONTEXT_SERVER_DASHBOARD_ENABLED=false, POWERCONTEXT_SERVER_MCP_ENABLED=false and no published ports, asserted by tests/test_docker_contract.py::test_distributed_compose_separates_roles_and_model_credentials. In-network reachability now only exposes the health/metrics boundary, not the business API.

environment:
<<: *shared-environment
POWERCONTEXT_SERVER_DEPLOYMENT_ROLE: worker
POWERCONTEXT_SERVER_DEPLOYMENT_ID: worker-a
POWERCONTEXT_SERVER_DASHBOARD_ENABLED: "false"
POWERCONTEXT_SERVER_MCP_ENABLED: "false"
POWERCONTEXT_SERVER_INFERENCE_GENERATION_MODEL: ${POWERCONTEXT_GENERATION_MODEL:?set a generation model}
OPENAI_API_KEY: ${OPENAI_API_KEY:-}
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
depends_on:
migrate:
condition: service_completed_successfully

worker-b:
<<: *runtime
command: ["server", "run"]
environment:
<<: *shared-environment
POWERCONTEXT_SERVER_DEPLOYMENT_ROLE: worker
POWERCONTEXT_SERVER_DEPLOYMENT_ID: worker-b
POWERCONTEXT_SERVER_DASHBOARD_ENABLED: "false"
POWERCONTEXT_SERVER_MCP_ENABLED: "false"
POWERCONTEXT_SERVER_INFERENCE_GENERATION_MODEL: ${POWERCONTEXT_GENERATION_MODEL:?set a generation model}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both Worker definitions now interpolate the documented variable: docker/compose.distributed.yaml:119 and :135 read ${POWERCONTEXT_SERVER_INFERENCE_GENERATION_MODEL:?set a generation model}, which matches the exports in both deployment guides. POWERCONTEXT_GENERATION_MODEL no longer appears anywhere in the template (44cc6b02e), and tests/test_docker_contract.py renders the template with the documented variable names, so a mismatch between the guides and the template now fails that test.

Head a25b6adf3.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed on 8ea1ae22 with Docker Compose v2.27, not a compatible-interpolator test. With database URL, API token, durable migration directory and the documented POWERCONTEXT_SERVER_INFERENCE_GENERATION_MODEL supplied, and legacy POWERCONTEXT_GENERATION_MODEL unset, docker compose --env-file /dev/null -f docker/compose.distributed.yaml config --format json exits 15: required variable POWERCONTEXT_GENERATION_MODEL is missing a value: set a generation model. The previous shell-variable escaping fix is separate; following either current deployment guide still cannot render this topology. Please align both Worker references with the documented variable and check the full Compose document using those exports.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 44cc6b0: both Worker services now interpolate the documented POWERCONTEXT_SERVER_INFERENCE_GENERATION_MODEL instead of the legacy name. Verified with Docker Compose v2 on this head — docker compose --env-file /dev/null -f docker/compose.distributed.yaml config --quiet exits 0 with exactly the variables the deployment guide exports (POWERCONTEXT_SERVER_DATABASE_URL, POWERCONTEXT_SERVER_AUTH_TOKEN, POWERCONTEXT_SERVER_INFERENCE_GENERATION_MODEL, POWERCONTEXT_MIGRATION_STATE_DIR) and POWERCONTEXT_GENERATION_MODEL unset.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 44cc6b0, same change as the thread above: lines 119 and 135 now read ${POWERCONTEXT_SERVER_INFERENCE_GENERATION_MODEL:?set a generation model}. Reproduced your command (docker compose --env-file /dev/null ... config) on the fixed head: exit 0 with the Server-prefixed variable supplied and the legacy one unset.

OPENAI_API_KEY: ${OPENAI_API_KEY:-}
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
depends_on:
migrate:
condition: service_completed_successfully
7 changes: 4 additions & 3 deletions docs/en/development/core-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ conflicts and persistence; the family service is responsible for its domain beha
A `Trigger` is a policy over a signal and prior state. It returns a `PolicyTransition` containing the next state and
zero or more actions. A Trigger should not open storage, schedule itself, or perform the action it selects.

APScheduler belongs to the Builtin runtime lifecycle. It decides when to evaluate a policy. The Trigger decides what
the observed signal means.
The durable Scheduler belongs to the Builtin runtime lifecycle. It decides when to evaluate a policy and records work
in the database ledger. The Trigger decides what the observed signal means; a fenced Worker performs the selected
action.

## Ownership boundaries

Expand All @@ -109,7 +110,7 @@ the observed signal means.
| Environment-backed process configuration | `powercontext.client.settings`, `powercontext.server.settings` |
| HTTP lifecycle and optional MCP transport | `powercontext.server` |
| Provider-specific generation and embedding | Inference integration |
| Database and scheduler resource lifetime | Application entry point or Builtin runtime instance |
| Database, Scheduler, and Worker resource lifetime | Application entry point or Builtin runtime instance |

Core models use Pydantic `BaseModel`. Add a validator when the value has a real domain constraint. Do not add wrapper
properties for stored fields, custom JSON value hierarchies, or a second definition object when the model or protocol
Expand Down
6 changes: 4 additions & 2 deletions docs/en/development/remote-access-implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ and OceanBase uses HNSW for `vector` and `hybrid` searches.
Inference configuration is documented in [Configure Pydantic AI inference](pydantic-ai-inference.md).

Set `POWERCONTEXT_SERVER_RUNTIME_SCHEDULE_SECONDS` to process pending Source windows on a persisted interval. Scheduled
jobs use the SQLite sidecar at `POWERCONTEXT_HOME/scheduler.db`. Scheduling works with either application database and
requires a configured generation pipeline.
discovery and execution use the primary database Work Ledger. In `single_node/all` mode the embedded Scheduler and
Worker share that ledger; distributed OceanBase deployments run them as separate roles. A generation pipeline is
required by the Worker.

## HTTP surface

Expand All @@ -91,6 +92,7 @@ The source contract is `openapi/powercontext.yaml`. Generated Pydantic models an
| Capabilities | source types, Artifact families, extraction, search modes |
| Sources | capture durable content evidence |
| Memory | flush pending Sources, remember explicit entries, search |
| Operations | inspect, list, cancel, and retry durable background work |
| Memory entries | list, get, revise, retire |
| History | list Memory changes |

Expand Down
23 changes: 23 additions & 0 deletions docs/en/docs/develop/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ curl --fail \
"$POWERCONTEXT_URL/v1/memory/search"
```

## Flush through a durable operation

A Memory flush can finish during the request or continue on any Worker. Ask for an immediate handle when the caller
does not want to wait:

```bash
curl --fail-with-body --include \
--request POST \
--header 'Content-Type: application/json' \
--header 'Prefer: respond-async' \
--header "$POWERCONTEXT_AUTH_HEADER" \
--data '{"scope_id":"project:example"}' \
"$POWERCONTEXT_URL/v1/memory/flush"
```

HTTP `200` contains the completed `FlushMemoryResponse`. HTTP `202` contains an operation ID and includes relative
`Location` and `Retry-After` headers. `Prefer: wait=N` waits up to 30 seconds. Poll
`GET /v1/operations/{operation_id}`; use the returned `state_version` as `expected_version` when cancelling a queued or
running operation, or retrying a blocked failed operation. A failed logical window returns `409 operation_blocked` on
another flush until an operator retries or cancels it.

## Scope-owned operational Prompts

Operational Prompts use `family=prompt` and the same Scope access boundary as other Artifacts. Under enforced Access,
Expand Down Expand Up @@ -211,6 +232,7 @@ use the same policy enforcement point; MCP tool visibility is not permission.
| External Skills | `/v1/external-skills/*` | Scan configured targets and resolve or import packages |
| Handoff Reports | `/v1/handoff-reports/*` | Generate a read-only report for a Scope selection |
| Statistics | `/v1/stats` | Read scoped usage statistics |
| Durable operations | `/v1/operations/*` | Inspect, list, cancel, or recover Memory and Experience background work |

Create an Artifact with `POST /v1/scopes/{scope_id}/artifacts`, specifying `family` in the request body.
Profile candidate review uses `/v1/candidates/*`.
Expand Down Expand Up @@ -244,6 +266,7 @@ Common statuses are:
| --- | --- |
| `401` | The Server requires a valid bearer token |
| `403` | The authenticated Principal is not authorized for the requested action and resource |
| `429` | The shared request window is exhausted; wait for `Retry-After` |
| `404` | The requested immutable value does not exist |
| `409` | The request conflicts with current immutable state or an expected version |
| `413` | A selected Handoff Report exceeds its output limit |
Expand Down
10 changes: 5 additions & 5 deletions docs/en/docs/develop/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ selector retains that selector, and Experience incubation uses its independent c
## Scheduled Experience incubation

An integration can capture a completed task as a Content Source with metadata `"kind": "task-outcome"`. When the
Experience schedule is configured, APScheduler scans bounded Source windows and asks the configured schema-bound
pipeline for reusable situation, action, outcome, and lesson proposals. Each proposal cites exact Sources and enters
the Review Inbox as a pending Experience Candidate.
Experience schedule is configured, the durable Scheduler scans bounded Source windows and enqueues versioned work.
A fenced Worker asks the configured schema-bound pipeline for reusable situation, action, outcome, and lesson
proposals. Each proposal cites exact Sources and enters the Review Inbox as a pending Experience Candidate.

Experience incubation has its own persisted Source cursor, independent from Memory extraction. Candidate writes and
cursor advancement commit together; a generation or write failure leaves the window available for retry. Ordinary
Experience incubation has its own persisted Source cursor, independent from Memory extraction. Candidate writes,
cursor advancement, and Work success commit together; a generation or write failure leaves the window available for retry. Ordinary
prompt Sources are not Task Outcomes and are ignored by this job.

Scheduling stops at the review boundary. It never approves an Experience, includes pending content in
Expand Down
13 changes: 11 additions & 2 deletions docs/en/docs/operate/database-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ The design follows [RFC #1771](https://github.com/oceanbase/powercontext/pull/17

The full Server framework registers two installed-release sources for the PowerContext 1.4.1 target (stored compatibility IDs shown below):

- **1.3.0:** `s1300 → s1400 → s1401 → s1402 → v1_4_1_004`.
- **1.4.0:** `r1400 → s1400 → s1401 → s1402 → v1_4_1_004` through a separate frozen source bridge.
- **1.3.0:** `s1300 → s1400 → s1401 → s1402 → v1_4_1_004 → v1_4_1_005`.
- **1.4.0:** `r1400 → s1400 → s1401 → s1402 → v1_4_1_004 → v1_4_1_005` through a separate frozen source bridge.

Application release numbers and schema revisions are distinct. The 1.4.0 release is not the `s1400` checkpoint:
its existing Candidate schema is current, but its Topic attempt storage still needs the registered bridge.
Expand Down Expand Up @@ -51,6 +51,15 @@ maintenance for existing managed storage. Runtime startup does not add the recei

Revision `v1_4_1_004` registers `pc_access_owner_recovery` for durable Artifact and Candidate ownership intents. Both installed-release source paths and vector profiles include this table. Existing managed databases require explicit maintenance; fresh databases create the registered empty table. Pending intents retain their original deployment, principal and idempotency identity across Server restarts. Earlier revision resources and checksums remain unchanged. Unregistered database layouts are rejected rather than adopted from a table name alone. This registration does not establish installed-release or external-Provider upgrade acceptance.

Revision `v1_4_1_005` registers the durable Work Ledger and its scheduler coordination tables: `pc_work_lanes`,
`pc_work_items`, `pc_work_keys`, `pc_work_attempts`, `pc_scheduler_leases`, `pc_scheduler_scans`,
`pc_runtime_members`, and the shared `pc_rate_limit_windows`. Ledger execution is at-least-once behind a monotonic
fence token while its commit is at-most-once, so a retried, superseded or cancelled attempt cannot publish a duplicate
result or release another worker's logical key. Both installed-release source paths and vector profiles include these
tables; existing managed databases require explicit maintenance and fresh databases create them through the registered
bootstrap. Earlier revision resources, registered layouts and historical checksums remain unchanged. This registration
does not establish installed-release or external-Provider upgrade acceptance.

An interrupted [portable restore](portable-archive.md) keeps normal startup and workers blocked until its projections
are complete. Retry `powercontext archive restore <bundle> --yes` with the same validated bundle. Only this explicit
recovery path can open an incomplete projection set, after validating the registered layout and the configured vector
Expand Down
44 changes: 41 additions & 3 deletions docs/en/docs/operate/deploy-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ export POWERCONTEXT_HOME=/srv/powercontext
powercontext server run
```

The process must be able to create and update this directory. The default SQLite database and scheduler state are
stored below it. Supply the same environment variables whenever your service manager restarts the process.
The process must be able to create and update this directory. The default SQLite database also stores durable
Scheduler, Worker lease, and Operation state. Supply the same environment variables whenever your service manager
restarts the process.

`server run` loads `.env` from its current directory when present. Managed deployments should export the variables,
configure them in the service manager or container platform, or pass one explicit file so startup does not depend on
Expand Down Expand Up @@ -140,7 +141,44 @@ docker run --rm \
```

The image listens on `0.0.0.0:8000` inside the container, so the host-side address in `--publish` is important. The
named volume persists the SQLite database and scheduler state after the container stops.
named volume persists the SQLite database and durable work state after the container stops.

## Run distributed roles

Distributed mode requires OceanBase and a schema migration before any role starts. The repository includes
`docker/compose.distributed.yaml` as a topology example with two APIs, two Schedulers, and two Workers. One Scheduler is
leader and the other remains ready to take over; both APIs and both Workers are active.

The distributed Work Ledger schedules Memory, Experience, and Profile work. Topic Memory processing is not supported
in distributed v1; leave its schedule unset. The single-node Artifact Processing Supervisor role must remain `all`
because `POWERCONTEXT_SERVER_DEPLOYMENT_ROLE` owns process separation in this topology.

Export secrets and deployment choices without writing them into Compose:

```bash
export POWERCONTEXT_SERVER_DATABASE_URL="$OCEANBASE_URL"
export POWERCONTEXT_SERVER_AUTH_TOKEN="$POWERCONTEXT_DEPLOYMENT_TOKEN"
export POWERCONTEXT_GENERATION_MODEL="openai:gpt-4.1-mini"
export OPENAI_API_KEY
Comment thread
Copilot marked this conversation as resolved.
Resolved
docker compose --file docker/compose.distributed.yaml up migrate
docker compose --file docker/compose.distributed.yaml up -d api-a api-b scheduler-a scheduler-b worker-a worker-b
```

The two API examples listen on host ports 8001 and 8002. Put a TLS-terminating load balancer in front of them and use
round-robin routing without session affinity. Distributed MCP is stateless. The example intentionally supplies model
credentials only to Workers and no public port to Scheduler or Worker roles. A production deployment should also use
separate least-privilege database users instead of the shared demonstration URL.

Every replica in one rollout must use the same behavior revision. Upgrade in this order:

1. run `powercontext server migrate` with a dedicated DDL account;
2. replace Workers and wait for readiness;
3. replace Schedulers and confirm a leader can scan;
4. replace APIs.

Keep `POWERCONTEXT_SERVER_COORDINATION_EMIT_PAYLOAD_VERSION` on the older supported value until old Workers have drained.
Rollback in the reverse order and never start a distributed role against a schema that has not reached the packaged
revision.

## Enable authentication

Expand Down
Loading
Loading