arc-kernel 0.1.3__tar.gz → 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/Install.md +4 -1
  2. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/PKG-INFO +1 -1
  3. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/__init__.py +1 -1
  4. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/cli.py +67 -32
  5. arc_kernel-0.1.4/arc/deploy_settings.py +46 -0
  6. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/doctor.py +51 -0
  7. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/errors.py +7 -5
  8. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/log.py +26 -8
  9. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/runtime.py +8 -0
  10. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/settings.py +141 -18
  11. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/store.py +196 -21
  12. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/tracing.py +11 -14
  13. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/tz.py +3 -3
  14. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/pyproject.toml +1 -1
  15. arc_kernel-0.1.4/tests/test_cli_settings_set.py +144 -0
  16. arc_kernel-0.1.4/tests/test_deploy_settings.py +76 -0
  17. arc_kernel-0.1.4/tests/test_doctor_cpu.py +144 -0
  18. arc_kernel-0.1.4/tests/test_setting_descriptions.py +576 -0
  19. arc_kernel-0.1.4/tests/test_setting_types.py +212 -0
  20. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/.gitignore +0 -0
  21. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/LICENSE +0 -0
  22. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/README.md +0 -0
  23. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/_state.py +0 -0
  24. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/backup.py +0 -0
  25. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/backupcmd.py +0 -0
  26. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/codec.py +0 -0
  27. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/crypto.py +0 -0
  28. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/deploy.py +0 -0
  29. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/errorscmd.py +0 -0
  30. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/events.py +0 -0
  31. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/health.py +0 -0
  32. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/healthcmd.py +0 -0
  33. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/kernel.py +0 -0
  34. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/log_collector.py +0 -0
  35. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/metrics.py +0 -0
  36. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/permissions.py +0 -0
  37. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/plugin_cli.py +0 -0
  38. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/py.typed +0 -0
  39. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/registry.py +0 -0
  40. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/resolver.py +0 -0
  41. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/secrets.py +0 -0
  42. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/sizing.py +0 -0
  43. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/status.py +0 -0
  44. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/stubs.py +0 -0
  45. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/supervision.py +0 -0
  46. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/update.py +0 -0
  47. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/arc/uuid7.py +0 -0
  48. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/docs/arc-kernel.MD +0 -0
  49. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/setup.sh +0 -0
  50. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/__init__.py +0 -0
  51. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/conftest.py +0 -0
  52. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_backup.py +0 -0
  53. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_backup_cli.py +0 -0
  54. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_boot.py +0 -0
  55. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_cli_perform.py +0 -0
  56. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_cli_restart.py +0 -0
  57. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_cli_run_console.py +0 -0
  58. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_connection_budget.py +0 -0
  59. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_connection_plan_cli.py +0 -0
  60. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_crypto.py +0 -0
  61. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_deploy_sizing.py +0 -0
  62. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_deploy_split.py +0 -0
  63. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_errors.py +0 -0
  64. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_errors_cmd.py +0 -0
  65. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_events.py +0 -0
  66. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_kernel.py +0 -0
  67. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_log.py +0 -0
  68. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_log_collector.py +0 -0
  69. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_logs_serve.py +0 -0
  70. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_metrics.py +0 -0
  71. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_new_plugin_scaffold.py +0 -0
  72. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_nginx_metrics.py +0 -0
  73. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_nginx_routes.py +0 -0
  74. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_permissions.py +0 -0
  75. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_process_registry.py +0 -0
  76. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_resolver_versions.py +0 -0
  77. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_run_async.py +0 -0
  78. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_run_lock.py +0 -0
  79. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_secrets_provider.py +0 -0
  80. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_settings.py +0 -0
  81. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_status.py +0 -0
  82. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_supervision.py +0 -0
  83. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_tracing.py +0 -0
  84. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_tz.py +0 -0
  85. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_update.py +0 -0
  86. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_uuid7.py +0 -0
  87. {arc_kernel-0.1.3 → arc_kernel-0.1.4}/tests/test_worker_count.py +0 -0
@@ -453,6 +453,7 @@ For an office at `203.0.113.0/24`: `arc settings set gateway_rate_limit_exempt 2
453
453
  | `gateway_metrics_token` | Left empty, the app serves `/metrics` to anyone who can reach its port. The nginx site `arc deploy prod` writes already restricts `/metrics` (and anything under it) to this machine, so the internet gets a 403; this token is a second gate, and the only one if you front the app some other way. |
454
454
  | `nginx_login_rate`, `nginx_login_burst`, `nginx_login_allow` | The per-address limit on `/login` in the nginx site `arc deploy prod` writes. Rate: `10` or `10r/s` (per second) or `300r/m` (default `10r/s`); burst: how many logins beyond the rate one address may make at once, 0 to 1000 (default 50); allow: comma-separated IP addresses or CIDR ranges that are **not limited at all**, e.g. `203.0.113.0/24,10.1.2.3`. Read when `arc deploy prod` runs, so re-run it after changing them; a bad value stops the command before anything is installed. |
455
455
  | `gateway_max_json_body_bytes` | The largest **JSON** request body the gateway will decode, in bytes (default 2 MiB = 2097152); a bigger one gets `413` `{"error": "JSON body too large", "limit_bytes": …}` before any decoding starts. Decoding runs on the event loop and holds the GIL, so a big body pauses every other request on that web worker: about 7 ms per MB of ordinary JSON (10 MB: ~70 ms to decode, ~90 ms pause through the real gateway). It cannot be moved off the loop - a thread still holds the GIL (60 ms pause), a process pool is no better (66 ms, and slower overall) - so it is bounded. It applies to every route: an upload route's own `max_body_bytes` (e.g. `/files/upload`, 60 MB) lets big files in, and files are not decoded as JSON; the general `gateway_max_body_bytes` (10 MB) still applies to everything else. **If a client of yours posts JSON bodies over 2 MiB** (a bulk import in one call), raise this, or better send the file to an upload route and process it as a background job; `0` removes this ceiling. Restart to apply. |
456
+ | `gateway_max_inflight_body_bytes` | The most bytes of request bodies one web worker holds in memory at once (bodies over 64 KB; default 256 MiB = 268435456, `0` = no bound). A body is read whole before its handler runs, so a crowd of big uploads is a crowd of big allocations: about 0.7 MB of memory per MB of body (four anonymous 59 MB uploads took a worker from 425 to 594 MB). A request that does not fit waits up to 5 s for room, then gets `503` with `Retry-After: 2`; a body bigger than the whole bound is let in on its own. Two things work with it: a caller relay would refuse (no sign-in, wrong role) is refused **before** a large body is read, so an anonymous crowd cannot fill the bound, and an early reply no longer makes nginx answer `502`. Size it from RAM: web workers × this should stay well under what the machine can spare. `/metrics`: `arc_gateway_inflight_body_bytes` (in memory now), `arc_gateway_inflight_body_waiting`, `arc_gateway_inflight_body_rejected_total`. Restart to apply. |
456
457
  | `error_tracking_dsn`, `error_tracking_environment`, `error_tracking_max_per_minute` | Where errors are sent besides the log and `/metrics`: a Sentry or GlitchTip DSN (**secret**; needs `uv add sentry-sdk`), the environment name they are filed under (default `production`), and the most events per bug per minute sent there (default 10, `0` = no limit). Unset DSN = errors are only counted and written to `logs/errors.jsonl`. Restart to apply. See *Know when it breaks*. |
457
458
  | `tracing_export_timeout_seconds`, `tracing_shutdown_timeout_seconds` | Only matter when `tracing_otlp_endpoint` is set. The first (1 to 60, default 3) is how long one batch of spans, retries included, may spend reaching the collector before it is dropped; the second (0 to 30, default 5, `0` = do not wait) is how long a **stopping** process waits for the spans still queued before giving up on them. Keep the second well under the 30 s a systemd unit gets to stop: with the collector unreachable and traffic flowing, OpenTelemetry's own shutdown waits for every queued batch to fail, and `arc restart` ends in a kill after 30 s (measured: 30 s with 32 clients connected, against about 2 s idle). Failed exports are logged once a minute per kind of failure, saying how many more were held back. Restart to apply. |
458
459
  | `redix_max_connections`, `redix_pool_wait_ms` | The most connections each process (web worker, queue worker, scheduler) opens to Redis/Valkey, at least 1 (default 512; opened only when needed), and how long a call waits for a free one when they are all in use before failing (default 1000 ms, `0` = fail at once). A busy web worker needs about one per request in flight; redis-py's own limit is 100, and past it every rate-limit check and session-cache lookup failed and fell back (to an in-process counter, to the database). Keep processes × `redix_max_connections` under the server's `maxclients` (10000 by default). `arc_redix_pool_wait_timeouts_total` above zero on `/metrics` means calls ran out of patience: raise it. (`/metrics` adds the processes up, so `arc_redix_pool_max_connections` reads processes × this setting: 3584 for 7 processes at 512.) Restart to apply. |
@@ -460,7 +461,7 @@ For an office at `203.0.113.0/24`: `arc settings set gateway_rate_limit_exempt 2
460
461
  | `nginx_read_timeout` | Seconds nginx waits for the app on an ordinary request before answering `504`, 1 to 3600 (default 60). WebSocket routes keep their own one-hour idle timeout whatever this is. Raise it only for a route that really needs longer, and better still make that work a background job. Read when `arc deploy prod` runs, so re-run it after changing it; a bad value stops the command before anything is installed. |
461
462
  | `deploy_metrics_allow` | Comma-separated IP addresses or CIDR ranges, e.g. `203.0.113.7,10.0.0.0/24`, that may read `/metrics` through that nginx site besides this machine (your Prometheus server). Read when `arc deploy prod` runs, so re-run it after changing this; a bad value stops the command before anything is installed. A scraper on the same machine can use `127.0.0.1:8001/metrics` directly. |
462
463
  | `authn_login_throttle` | What a source address pays for **failed** logins, **one JSON object**; a key you leave out keeps its default: `{"max_failures": 60, "window_seconds": 60, "failure_delay_ms": 250}`. After `max_failures` failed logins from one address in a window, further attempts from it get `429` (`too_many_failures`) until the window passes, before any password hashing is spent on them (0 turns the budget off). **Successful logins do not count**, so an office behind one address is not affected, while someone trying passwords or spraying usernames fails nearly every time and runs out. `failure_delay_ms` is a pause before any failure is reported (0 turns it off). A failure is treated identically whether or not the account exists (same count, same pause, same message): an unknown username that cost more or less than a known one would show an attacker which accounts exist. Addresses in `gateway_rate_limit_exempt` are not held to the budget. Read at startup. |
463
- | `authn_argon2` | Password hashing, **one JSON object**; a key you leave out keeps its default: `{"memory_mb": 64, "time_cost": 3, "parallelism": 4, "max_concurrent": 2}`. `memory_mb` is the memory one hash uses (19 to 4096), `time_cost` the passes over it, `parallelism` the threads one hash uses, `max_concurrent` how many hashes one web worker runs at once. Peak memory per worker is `memory_mb` × `max_concurrent`; a few more hashes wait and the rest get `503` with `Retry-After`, so a login flood cannot run the server out of memory. **On a machine short of memory**, use OWASP's smallest profile: `arc settings set authn_argon2 '{"memory_mb": 19, "time_cost": 2, "parallelism": 1}'`, then restart. Existing hashes keep verifying with their own parameters and are replaced by one made under the new settings at the owner's next login. Measured with 2 web workers and 48 concurrent wrong-password logins: before, the workers grew by 1,098 MB (the run was stopped there to protect the machine) and a bystander's p99 was 266 ms; now +263 MB at the default and +47 MB with the 19 MiB profile, p99 96 ms and 37 ms. A bad value stops startup with a message naming the key. |
464
+ | `authn_argon2` | Password hashing, **one JSON object**; a key you leave out keeps its default: `{"memory_mb": 64, "time_cost": 3, "parallelism": 1, "max_concurrent": 2}`. `memory_mb` is the memory one hash uses (19 to 4096), `time_cost` the passes over it, `parallelism` the threads one hash uses, `max_concurrent` how many hashes one web worker runs at once. **What makes a password costly to crack is the memory and the passes; `parallelism` only spreads the same work over more threads** (OWASP's Argon2id profiles all use 1), so it is the setting that decides how much of the machine a flood of logins can take: web workers × `max_concurrent` × `parallelism` threads at once. Measured on a 12-core machine, one hash at 64 MiB and 3 passes takes **66 ms on 4 threads and 163 ms on 1**; four at once cost 326 CPU-ms each on 4 threads and 214 on 1. The default was 4 threads: 2 web workers × 2 hashes × 4 = 16 threads, and a flood of logins for accounts that do not exist took 9 to 10 of the 12 cores. At 1 it is 4 threads, a third of that machine, with the same strength; a login takes about 100 ms longer, and the most logins a second the server can do is web workers × `max_concurrent` ÷ the time one takes (2 × 2 ÷ 0.23 s ≈ 17 a second here; an office signing in at nine is a few a second). `arc doctor --deep` warns when a deployment could use more than half of the cores for it. **Passwords stored before the default changed** (made at `parallelism` 4) keep working: they verify as before, and that user's next login stores a new one. Peak memory per worker is `memory_mb` × `max_concurrent`; a few more hashes wait and the rest get `503` with `Retry-After`, so a login flood cannot run the server out of memory. **On a machine short of memory**, use OWASP's smallest profile: `arc settings set authn_argon2 '{"memory_mb": 19, "time_cost": 2, "parallelism": 1}'`, then restart. Existing hashes keep verifying with their own parameters and are replaced by one made under the new settings at the owner's next login. Measured with 2 web workers and 48 concurrent wrong-password logins: before, the workers grew by 1,098 MB (the run was stopped there to protect the machine) and a bystander's p99 was 266 ms; now +263 MB at the default and +47 MB with the 19 MiB profile, p99 96 ms and 37 ms. A bad value stops startup with a message naming the key. |
464
465
  | `provider` under `[secrets]` in `.arc/arc.toml` | `local_file` (the default) keeps secrets encrypted in `.arc/arc.store.db`. **`env`** reads each one from an environment variable and stores nothing: `ARC_SECRET_PGDB_DSN`, `ARC_SECRET_REDIX_URL`, `ARC_SECRET_AUTHN_CSRF_SECRET`, `ARC_SECRET_FILER_SIGNING_SECRET`, … (the setting's name in capitals). `arc settings set … --secret` then refuses and names the variable to set, and a secret that is not set stays unset: ARC will not invent a CSRF or signing secret per worker. **Every ARC process needs the variables**, for example through an `EnvironmentFile=` line in each systemd unit (`arc deploy` does not write one). `.arc/arc.mkey` is still a file: it protects `arc.encrypt()` data, not these secrets. Any other value is an error at startup and in `arc doctor`; it used to be ignored, silently leaving the secrets in the local file. Tested: the gateway ran with all four secrets supplied only through the environment. |
465
466
  | *permissions of `.arc/`* | New projects are private from the start (`.arc/` mode 700; the settings store and master key 600). A project created before that has `.arc/` readable by every local user: `arc doctor` says so, and **`arc doctor --fix`** repairs it. It is never changed silently, because a setup that shares `.arc/` with another account through a group must be able to keep doing that. |
466
467
  | `gateway_access_log` | Where each request's access line goes. `file` (the default) writes it to `logs/gateway.jsonl` only; `console` also prints it through `arc run` (handy on a dev machine, but at thousands of requests per second that relay becomes the bottleneck); `off` disables the line. Request metrics are kept in every mode. Restart to apply. |
@@ -563,6 +564,8 @@ The output looks like this (illustrative values):
563
564
 
564
565
  Two more counters say when Redis is not keeping up, rather than when the app is failing: `arc_gateway_rate_limit_fallbacks_total` (request-limit checks Redis could not answer, decided from each web worker's own counter instead, so the limit is per worker until it recovers) and `arc_redix_pool_wait_timeouts_total` (calls that gave up waiting for a free Redis connection; see `redix_max_connections`). Either rising means look at Redis, or the pool size, before anything else.
565
566
 
567
+ And for request bodies: `arc_gateway_inflight_body_bytes` is what the web workers hold in memory for uploads and large posts right now, `arc_gateway_inflight_body_waiting` how many requests are waiting for room, and `arc_gateway_inflight_body_rejected_total` how many were told to come back (`503`). Rejections that keep rising mean either a flood of big uploads or a bound (`gateway_max_inflight_body_bytes`) too small for the RAM you have.
568
+
566
569
  **Sentry or GlitchTip (optional).** The SDK is not a dependency of ARC; install it, give it the project's DSN, restart:
567
570
 
568
571
  ```bash
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: arc-kernel
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: ARC kernel — capability-based Python platform
5
5
  Project-URL: Homepage, https://github.com/vignesh-ramsh/arc
6
6
  Project-URL: Repository, https://github.com/vignesh-ramsh/arc
@@ -28,7 +28,7 @@ from .kernel import ( # noqa: F401
28
28
  from .resolver import BootPlan, PluginSpec, ResolutionError # noqa: F401
29
29
  from .runtime import BootError, boot, find_project_root, shutdown # noqa: F401
30
30
 
31
- __version__ = "0.1.3"
31
+ __version__ = "0.1.4"
32
32
 
33
33
 
34
34
  def __getattr__(name: str) -> Any:
@@ -21,6 +21,7 @@ The `arc` command. Subcommands implemented here:
21
21
  from __future__ import annotations
22
22
 
23
23
  import asyncio
24
+ import enum
24
25
  import importlib
25
26
  import inspect
26
27
  import json
@@ -35,7 +36,7 @@ import threading
35
36
  import time
36
37
  import warnings
37
38
  from pathlib import Path
38
- from typing import Any
39
+ from typing import Annotated, Any
39
40
  from urllib.parse import urlparse
40
41
 
41
42
  import tomlkit
@@ -43,8 +44,9 @@ import typer
43
44
  from rich.console import Console
44
45
  from rich.table import Table
45
46
 
46
- from . import deploy, permissions, registry, sizing, update as update_module
47
+ from . import deploy, permissions, registry, sizing, store, update as update_module
47
48
  from .backupcmd import app as _backup_app
49
+ from .deploy_settings import GATEWAY_WORKERS_KEY, LINEUP_QUEUES_KEY, LINEUP_WORKERS_KEY, RESTART_COMMAND_KEY
48
50
  from .doctor import doctor as _doctor_command
49
51
  from .errorscmd import errors_command as _errors_command
50
52
  from .healthcmd import health as _health_command
@@ -1073,10 +1075,6 @@ def clear_cache() -> None:
1073
1075
  # guidance when unset. Supervisor knowledge lives in the
1074
1076
  # setting's VALUE, never in kernel code.
1075
1077
  # --------------------------------------------------------------------------- #
1076
- RESTART_COMMAND_KEY = "restart_command"
1077
- GATEWAY_WORKERS_KEY = "gateway_workers"
1078
- LINEUP_WORKERS_KEY = "lineup_workers"
1079
- LINEUP_QUEUES_KEY = "lineup_queues"
1080
1078
  POOL_MAX_SIZE_KEY = "pgdb_pool_max_size"
1081
1079
  #: Who may read /metrics through the nginx site `arc deploy prod` writes, besides this machine.
1082
1080
  DEPLOY_METRICS_ALLOW_KEY = "deploy_metrics_allow"
@@ -1372,13 +1370,8 @@ def run_(
1372
1370
  err_console.print(f"[bold red]{exc}[/bold red]")
1373
1371
  raise typer.Exit(code=1)
1374
1372
 
1375
- # Plain (non-secret) keys — declare() is a documentation-only no-op for
1376
- # these (arc.settings.declare's own docstring), kept for the same
1377
- # reason every other plugin declares its plain settings: so they show
1378
- # up via arc.settings.list_all() / admin's Settings page.
1379
- kernel.settings.declare(GATEWAY_WORKERS_KEY)
1380
- kernel.settings.declare(LINEUP_WORKERS_KEY)
1381
- kernel.settings.declare(LINEUP_QUEUES_KEY)
1373
+ # gateway_workers / lineup_workers / lineup_queues / restart_command are declared, with their
1374
+ # descriptions, at boot (arc.deploy_settings): the admin Settings page lists them whoever reads them.
1382
1375
 
1383
1376
  gateway_workers = _resolve_worker_count(kernel, GATEWAY_WORKERS_KEY)
1384
1377
  console.print(
@@ -2739,6 +2732,23 @@ def settings_get(
2739
2732
  console.print(value)
2740
2733
 
2741
2734
 
2735
+ def _settings_manager_that_knows_declared_keys(root: Path) -> tuple[SettingsManager, str | None]:
2736
+ """The project's settings manager after booting it, so it knows what every plugin declared (types, defaults,
2737
+ descriptions) - which `SettingsManager(...)` alone cannot, since declare() only runs inside each plugin's
2738
+ register(). A project that cannot boot yet (e.g. no DSN set) falls back to the plain manager, and the second
2739
+ value is why the boot failed (None when it booted): settings management has to work before the project is
2740
+ otherwise runnable, and the caller says what it could not check rather than hiding it - a bad *typed*
2741
+ setting value is exactly the kind of boot failure these commands exist to reveal (§1 P0)."""
2742
+ import arc as _arc
2743
+
2744
+ with warnings.catch_warnings():
2745
+ warnings.simplefilter("ignore", _arc.ArcAdvisory)
2746
+ try:
2747
+ return _arc.boot(project_root=root).settings, None
2748
+ except _arc.BootError as exc:
2749
+ return SettingsManager(root / ".arc"), str(exc)
2750
+
2751
+
2742
2752
  @settings_app.command("list")
2743
2753
  def settings_list() -> None:
2744
2754
  """List every known setting — value (redacted for secrets) plus, when
@@ -2753,22 +2763,8 @@ def settings_list() -> None:
2753
2763
  err_console.print("Not inside an ARC project — no .arc/arc.toml found.")
2754
2764
  raise typer.Exit(code=1)
2755
2765
 
2756
- import arc as _arc
2757
-
2758
- booted = False
2759
- boot_error: str | None = None
2760
- with warnings.catch_warnings():
2761
- warnings.simplefilter("ignore", _arc.ArcAdvisory)
2762
- try:
2763
- mgr = _arc.boot(project_root=root).settings
2764
- booted = True
2765
- except _arc.BootError as exc:
2766
- # Surfaced, not swallowed — a bad *typed* setting value is
2767
- # exactly the kind of boot failure this command exists to
2768
- # reveal (§1 P0), so silently falling back here would defeat
2769
- # its own purpose.
2770
- boot_error = str(exc)
2771
- mgr = SettingsManager(root / ".arc")
2766
+ mgr, boot_error = _settings_manager_that_knows_declared_keys(root)
2767
+ booted = boot_error is None
2772
2768
 
2773
2769
  data = mgr.list_all()
2774
2770
  if not data:
@@ -2798,6 +2794,10 @@ def settings_list() -> None:
2798
2794
  )
2799
2795
 
2800
2796
 
2797
+ #: The types `arc settings set --type` offers: the ones a key added by hand can have (store.STORED_TYPES).
2798
+ SettingType = enum.Enum("SettingType", {name: name for name in store.STORED_TYPES}, type=str)
2799
+
2800
+
2801
2801
  @settings_app.command("set")
2802
2802
  def settings_set(
2803
2803
  key: str,
@@ -2805,19 +2805,54 @@ def settings_set(
2805
2805
  secret: bool = typer.Option(
2806
2806
  False, "--secret", help="Store this value encrypted and mark the key as secret."
2807
2807
  ),
2808
+ value_type: Annotated[
2809
+ SettingType | None,
2810
+ typer.Option(
2811
+ "--type",
2812
+ help="The type of a NEW key: only values of that type are accepted, now and later. Fixed once the key exists.",
2813
+ ),
2814
+ ] = None,
2815
+ description: str = typer.Option(
2816
+ None,
2817
+ "--description",
2818
+ help="What a NEW key is for, in plain words (shown on the admin Settings page, where it can be edited).",
2819
+ ),
2808
2820
  ) -> None:
2809
2821
  """Set a setting. Both plain and --secret values live in .arc/arc.store.db —
2810
- --secret ones encrypted, keyed by .arc/arc.mkey."""
2822
+ --secret ones encrypted, keyed by .arc/arc.mkey.
2823
+
2824
+ --type and --description are what a key is created with, so they are
2825
+ accepted only for a key that does not exist yet. To change an existing
2826
+ key's description use the admin Settings page; its type cannot change."""
2811
2827
  root = find_project_root()
2812
2828
  mgr = SettingsManager(root / ".arc")
2829
+ type_name = value_type.value if value_type is not None else None
2830
+ creating = type_name is not None or description is not None
2831
+ if creating:
2832
+ # The plain manager cannot tell a key some plugin declared but nobody has set yet from a new one, so it
2833
+ # would let this command re-describe or re-type it. Booting tells it.
2834
+ mgr, boot_error = _settings_manager_that_knows_declared_keys(root)
2835
+ if boot_error is not None:
2836
+ err_console.print(
2837
+ f"[yellow]note:[/yellow] the project did not boot, so '{key}' could not be checked against the keys "
2838
+ f"plugins declare ({boot_error})"
2839
+ )
2813
2840
  try:
2814
- mgr.set(key, value, secret=secret, updated_by=f"cli:{os.environ.get('USER', 'unknown')}")
2841
+ mgr.set(
2842
+ key,
2843
+ value,
2844
+ secret=secret,
2845
+ updated_by=f"cli:{os.environ.get('USER', 'unknown')}",
2846
+ type=type_name,
2847
+ description=description,
2848
+ )
2815
2849
  except SettingsError as exc:
2816
2850
  err_console.print(str(exc))
2817
2851
  raise typer.Exit(code=1)
2818
2852
 
2819
2853
  shown = REDACTED if secret else value
2820
- console.print(f"[green]Set {key} = {shown}[/green]" + (" (secret)" if secret else ""))
2854
+ saved = [part for part, given in (("secret", secret), (type_name, type_name), ("with a description", description)) if given]
2855
+ console.print(f"[green]Set {key} = {shown}[/green]" + (f" ({', '.join(saved)})" if saved else ""))
2821
2856
 
2822
2857
 
2823
2858
  @settings_app.command("delete")
@@ -0,0 +1,46 @@
1
+ """
2
+ arc.deploy_settings
3
+ -------------------
4
+ The settings that say how this project is run (restarted, which job queues get a worker). `arc restart`,
5
+ `arc build`, `arc run` and `arc deploy` read them, but until now nothing declared them: they were invisible on
6
+ the admin Settings page until someone had set one, and had no description. Declared once, at boot, so they show
7
+ up there with a description wherever they are read.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import Any
13
+
14
+ RESTART_COMMAND_KEY = "restart_command"
15
+ LINEUP_QUEUES_KEY = "lineup_queues"
16
+ GATEWAY_WORKERS_KEY = "gateway_workers"
17
+ LINEUP_WORKERS_KEY = "lineup_workers"
18
+
19
+
20
+ def declare(kernel: Any) -> None:
21
+ kernel.settings.declare(
22
+ RESTART_COMMAND_KEY,
23
+ doc="The command that restarts ARC. `arc restart` (and `arc build`) run it exactly as written, for example "
24
+ "`systemctl --user restart arc-desk.target`. `arc deploy` sets it for you. If empty, `arc restart` says "
25
+ "there is nothing to run.",
26
+ )
27
+ kernel.settings.declare(
28
+ LINEUP_QUEUES_KEY,
29
+ doc="Which job queues the worker processes handle, as a comma-separated list such as `default,mail`. If "
30
+ "empty, ARC uses every queue its installed plugins declare. `arc deploy` reads it to make one worker unit "
31
+ "per queue.",
32
+ )
33
+ kernel.settings.declare(
34
+ GATEWAY_WORKERS_KEY,
35
+ doc="How many web workers (server processes that answer requests) ARC starts. If empty, ARC chooses: 2 for a "
36
+ "development setup, or a number worked out from this machine's CPU and memory (at most 8 on its own) for "
37
+ "production. A number you set is used as given, at least 1. Every worker keeps its own database "
38
+ "connections, so more workers need a bigger database connection limit. Apply a change with `arc deploy`.",
39
+ )
40
+ kernel.settings.declare(
41
+ LINEUP_WORKERS_KEY,
42
+ doc="How many background-job workers ARC starts for each job queue (with `arc run` it is the total). If "
43
+ "empty, ARC chooses: 1 for each queue in a development setup, or a number worked out from this machine for "
44
+ "production, shared over the queues. A number you set is used as given, at least 1. Apply a change with "
45
+ "`arc deploy`.",
46
+ )
@@ -45,6 +45,7 @@ from typing import Any
45
45
 
46
46
  import typer
47
47
  from rich.console import Console
48
+ from rich.markup import escape
48
49
  from rich.table import Table
49
50
 
50
51
  from . import permissions, resolver, settings as arc_settings
@@ -257,6 +258,7 @@ def _run_deep() -> dict[str, Any]:
257
258
  result = asyncio.run(_open_and_collect())
258
259
  # After the loop above has finished: asking PostgreSQL uses a loop of its own.
259
260
  result["connections"] = _connections(kernel)
261
+ result["cpu_warnings"] = _cpu_warnings(kernel)
260
262
  return result
261
263
  finally:
262
264
  _shutdown()
@@ -285,6 +287,52 @@ def _connections(kernel: Any) -> dict[str, Any] | None:
285
287
  }
286
288
 
287
289
 
290
+ def cpu_demand_warnings(demands: list[dict[str, Any]], web_workers: int, cores: int) -> list[str]:
291
+ """One warning for each plugin whose CPU demand, over every web worker, could take more than half of
292
+ the machine's cores. A demand is `{"what", "threads" (per web worker), "advice"}` as a plugin's
293
+ `web_worker_cpu_demand()` gives it. Half, because the database, nginx and the job workers share the
294
+ machine: a flood that reaches it should still leave them room."""
295
+ if web_workers <= 0:
296
+ return []
297
+ warnings_out: list[str] = []
298
+ for demand in demands:
299
+ total = web_workers * int(demand["threads"])
300
+ if total > cores / 2:
301
+ warnings_out.append(
302
+ f"{demand['what']} can use up to {total} threads at once ({web_workers} web workers x "
303
+ f"{demand['threads']}) on a machine with {cores} cores. {demand['advice']}"
304
+ )
305
+ return warnings_out
306
+
307
+
308
+ def _cpu_demands(kernel: Any) -> list[dict[str, Any]]:
309
+ """What each capability that states one (`web_worker_cpu_demand()`) says it may spend per web worker."""
310
+ demands: list[dict[str, Any]] = []
311
+ for _name, cap in kernel.capabilities().items():
312
+ ask = getattr(cap.instance, "web_worker_cpu_demand", None)
313
+ if not callable(ask):
314
+ continue
315
+ try:
316
+ demand = ask()
317
+ except Exception: # noqa: BLE001 - a plugin that cannot answer must not stop the rest of the check
318
+ continue
319
+ if demand:
320
+ demands.append(demand)
321
+ return demands
322
+
323
+
324
+ def _cpu_warnings(kernel: Any) -> list[str]:
325
+ """For a project deployed with `arc deploy`: the demands against the web workers and cores it has.
326
+ Nothing when it was not deployed that way, since the number of web workers is then unknown."""
327
+ from . import deploy, sizing, status
328
+
329
+ deployments = deploy.read_deployments(kernel.project_root)
330
+ if not deployments:
331
+ return []
332
+ web_workers = status.expected_processes(deployments[0]).get(sizing.ROLE_GATEWAY, 0)
333
+ return cpu_demand_warnings(_cpu_demands(kernel), web_workers, sizing.detect_cpu_count())
334
+
335
+
288
336
  def _queue_coverage(kernel: Any) -> dict[str, list[str]] | None:
289
337
  """For a project deployed with `arc deploy`: which of the queues its plugins declare
290
338
  have a worker unit. A queue without one is never consumed — jobs for it just wait,
@@ -362,6 +410,9 @@ def _print_deep(deep: dict[str, Any]) -> None:
362
410
  for problem in connections["problems"]:
363
411
  err_console.print(f"[bold yellow]warning:[/bold yellow] {problem}")
364
412
 
413
+ for warning in deep.get("cpu_warnings") or []:
414
+ err_console.print(f"[bold yellow]warning:[/bold yellow] {escape(warning)}")
415
+
365
416
  coverage = deep.get("queue_coverage")
366
417
  if coverage and coverage["missing"]:
367
418
  err_console.print(
@@ -115,20 +115,22 @@ def declare(kernel: Any) -> None:
115
115
  kernel.settings.declare(
116
116
  DSN_KEY,
117
117
  secret=True,
118
- doc="Sentry/GlitchTip DSN to send errors to (needs `uv add sentry-sdk`). Unset = errors are "
119
- "only counted and written to logs/errors.jsonl. Restart to apply.",
118
+ doc="The address (DSN) of the Sentry or GlitchTip project that errors should be sent to. It needs the "
119
+ "`sentry-sdk` package (`uv add sentry-sdk`). If empty, errors are only counted and written to "
120
+ "`logs/errors.jsonl`. Restart to apply.",
120
121
  )
121
122
  kernel.settings.declare(
122
123
  ENVIRONMENT_KEY,
123
124
  default=DEFAULT_ENVIRONMENT,
124
- doc="The environment name errors are filed under at the tracker (production, staging, ...).",
125
+ doc="The environment name errors are filed under in the error tracker, such as `production` or `staging`. "
126
+ "The default is `production`.",
125
127
  )
126
128
  kernel.settings.declare(
127
129
  MAX_PER_MINUTE_KEY,
128
130
  type=int,
129
131
  default=DEFAULT_MAX_PER_MINUTE,
130
- doc="Most events per fingerprint per minute sent to the tracker; the rest are only counted "
131
- "and logged. 0 = no limit.",
132
+ doc="The most times one kind of error is sent to the tracker each minute. Beyond that it is still counted "
133
+ "and logged, only not sent. 0 means no limit.",
132
134
  )
133
135
 
134
136
 
@@ -216,23 +216,41 @@ def read_sink_settings(settings: Any) -> SinkSettings:
216
216
  level_name, max_bytes, backup_count = DEFAULT_LEVEL, DEFAULT_MAX_BYTES, DEFAULT_BACKUP_COUNT
217
217
  collector, flush_ms = True, DEFAULT_FLUSH_MS
218
218
  if settings is not None:
219
- settings.declare(LOG_LEVEL_KEY)
220
- settings.declare(LOG_MAX_BYTES_KEY)
221
- settings.declare(LOG_BACKUP_COUNT_KEY)
219
+ settings.declare(
220
+ LOG_LEVEL_KEY,
221
+ type=str,
222
+ default=DEFAULT_LEVEL,
223
+ doc="How much detail goes into the logs: `DEBUG` (most), `INFO` (the default), `WARNING`, `ERROR` or "
224
+ "`CRITICAL` (least).",
225
+ )
226
+ settings.declare(
227
+ LOG_MAX_BYTES_KEY,
228
+ type=int,
229
+ default=DEFAULT_MAX_BYTES,
230
+ doc="How big each log file may grow, in bytes, before it is rotated (default 10 MB).",
231
+ )
232
+ settings.declare(
233
+ LOG_BACKUP_COUNT_KEY,
234
+ type=int,
235
+ default=DEFAULT_BACKUP_COUNT,
236
+ doc="How many old copies of each log file are kept after it is rotated. The default is 5. Older ones "
237
+ "are deleted.",
238
+ )
222
239
  settings.declare(
223
240
  LOG_COLLECTOR_KEY,
224
241
  type=bool,
225
242
  default=True,
226
- doc="`arc run` starts one log-collector that is the only writer of logs/*.jsonl "
227
- "(no rotation races between workers, one write() per batch). Off: every process "
228
- "writes the files itself.",
243
+ doc="When on (the default), `arc run` starts one log collector that is the only program writing the "
244
+ "`logs/*.jsonl` files, which avoids clashes between workers. When off, every process writes the "
245
+ "log files itself.",
229
246
  )
230
247
  settings.declare(
231
248
  LOG_FLUSH_MS_KEY,
232
249
  type=int,
233
250
  default=DEFAULT_FLUSH_MS,
234
- doc="How long (ms) each process accumulates log lines before sending them to the "
235
- "collector, and how long the collector accumulates before one write().",
251
+ doc="How many milliseconds each process gathers log lines before sending them to the collector, and "
252
+ "how long the collector gathers them before writing them out in one go. A bigger number means "
253
+ "fewer writes but logs appear slightly later.",
236
254
  )
237
255
  level_name = settings.get(LOG_LEVEL_KEY) or DEFAULT_LEVEL
238
256
  max_bytes = int(settings.get(LOG_MAX_BYTES_KEY) or DEFAULT_MAX_BYTES)
@@ -125,6 +125,7 @@ def boot(
125
125
  # is untouched by this.) See arc.log's own docstring for why root-
126
126
  # logger configuration lives here rather than in each plugin/CLI
127
127
  # entrypoint separately.
128
+ from . import deploy_settings as _deploy_settings
128
129
  from . import errors as _errors
129
130
  from . import log as _log
130
131
  from . import tracing as _tracing
@@ -143,6 +144,8 @@ def boot(
143
144
  # Error tracking's settings (the tracker's DSN and so on) for the same reason: any plugin may
144
145
  # call arc.errors.capture() from its own register() or from the first request.
145
146
  _errors.declare(kernel)
147
+ # How the project is run (restart command, job queues): declared so the admin Settings page lists them.
148
+ _deploy_settings.declare(kernel)
146
149
 
147
150
  for warning in plan.warnings:
148
151
  kernel.advise(warning)
@@ -196,6 +199,11 @@ def boot(
196
199
  _state.set_kernel(None)
197
200
  raise BootError(str(exc)) from exc
198
201
 
202
+ # Every key is declared by now: copy the descriptions the code gives them into the settings store, where
203
+ # the admin Settings page reads (and lets an administrator rewrite) them. Writes nothing when nothing
204
+ # changed, so the processes that start together do not queue up on the file.
205
+ settings_manager.sync_descriptions()
206
+
199
207
  missing_sdk = _errors.sentry_missing_notice(kernel)
200
208
  if missing_sdk:
201
209
  kernel.advise(missing_sdk)