Runtime Settings
Tunable values are **runtime settings**: stored in the service's own database and edited by super admins in the Tawa Console. A redeploy or a code change is…
Commandconfigure
About
Tunable values are **runtime settings**: stored in the service's own database and edited by super admins in the Tawa Console. A redeploy or a code change is never needed to flip a value.
Skill Content
This is the raw markdown that gets installed as a Claude Code command.
---
name: tawa-runtime-settings
description: "Tunables as runtime settings in the DB edited in the Console (registry, API, auth), not env vars. Use when adding a feature flag, rate, limit or URL."
---
# Runtime Settings
Tunable values are **runtime settings**: stored in the service's own database and edited by
super admins in the Tawa Console. A redeploy or a code change is never needed to flip a value.
## The Short Version
- A tunable is a **setting**, not an env var or config var.
- Each service declares its settings in a typed registry; the Console renders them with no UI work.
- Changes apply within about 15 seconds, without a restart.
- Only an owner (or super admin) can write, with their own Bio-ID JWT or an agent token (`act`) whose
subject is that person. There is no app allowlist. Every write records the person and, for an
agent token, the actor (`via`).
## What Is a Setting
- Feature flags
- URLs shown to users (for example a "buy gas" link)
- Rates
- Limits
- Intervals
- Allow-lists
- Rollout modes (for example `off` / `shadow` / `enforce`)
## What Stays Env / Config
Use `tawa config` (see `config`) for values that wiring needs before the database is reachable
or that must never be visible in a UI:
- Secrets and credentials
- Connection strings
- Service URLs used for infrastructure wiring
- The settings-owners list itself (the `sub` values allowed to write settings)
If changing the value is a product or operations decision, it is a setting. If changing it
reconnects the service to something, it is config.
## The Pattern
Reference implementation: iec-janus, `src/services/settings.ts` and `src/routes/adminSettings.ts`.
- **Typed registry.** One entry per dotted lowercase key (`authz`, `gas.buyUrl`,
`promo.launchGrantsEnabled`), each with a zod `schema`, a `defaultValue`, a one-sentence
`description`, and an `editor` hint: `'boolean' | 'number' | 'string' | 'url' | 'json'`.
- **Storage.** Values live in a Mongo collection. An audit collection holds one row per write
with `before`, `after`, `by` and `at`.
- **Cache.** An in-memory cache refreshes about every 15 seconds, so a change applies without a
restart. If Mongo is unreachable during a refresh, the previous cached values are kept.
- **`getSetting(key)`** is synchronous, never throws, and returns the registry default when no value
is stored or the stored value fails its schema.
- **Optimistic concurrency.** Each setting has a `version`. A write may send `expectedVersion`;
a mismatch is rejected so two admins cannot overwrite each other.
- **Jobs read flags at run time.** A cron handler or queue worker calls `getSetting` on every run,
never once at boot, so a flag flipped in the Console takes effect on the next run.
```typescript
const SETTINGS = {
'promo.launchGrantsEnabled': {
schema: z.boolean(),
defaultValue: () => false,
description: 'Run the launch promo-grant cycle for eligible agency orgs.',
editor: 'boolean',
},
} as const
if (getSetting('promo.launchGrantsEnabled')) await runLaunchGrantCycle()
```
## API
Mounted under the service's own prefix (`<prefix>`).
| Route | Purpose |
|---|---|
| `GET <prefix>/admin/settings` | List every declared setting |
| `PUT <prefix>/admin/settings/:key` | Set one value. Body: `{ "value": ..., "expectedVersion": 3 }` (`expectedVersion` optional) |
| `GET <prefix>/admin/settings/:key/history?limit=` | Audit rows for one key, newest first |
The list response:
```json
{
"settings": [
{
"key": "gas.buyUrl",
"value": "https://example.com/buy",
"default": "",
"version": 4,
"source": "stored",
"updatedBy": "<bio-id sub>",
"updatedAt": "2026-10-04T12:00:00.000Z",
"description": "Where the 402 INSUFFICIENT_GAS response sends a caller to buy gas. Empty = no link.",
"editor": "url"
}
],
"canWrite": true,
"actor": "<bio-id sub>"
}
```
`source` is `stored` (a value is in the database) or `default` (the registry default; `version` 0).
`updatedBy` and `updatedAt` are absent for a key that has never been written.
## Auth
- **Reads** accept the internal key or a user JWT.
- **Writes** require the person's own Bio-ID JWT: a settings owner (`sub` in the service's owners
list) or, where the service says so, a platform `super_admin`.
- **There is no app allowlist for settings or admin writes. The person check is the gate.**
A write is accepted from the person's own Bio-ID user token whichever Bio-ID app they signed in
through: the Tawa Console, the tawa CLI (`tawa login`, `tawa switches`) or any other app.
Signature, issuer and expiry are still verified. Do not add a `client_id`/`aud` list of
"console apps" to a settings or admin route, in code, env or a runtime setting (Derek,
2026-11-18; the old `SETTINGS_CLIENTS` / `CONSOLE_CLIENTS` / `BUILDER_SETTINGS_CLIENTS` /
`GATEWAY_OWNER_CLIENTS` / `promo.manualGrantClients` lists were removed).
- The internal key and service (client-credentials) tokens are **refused on writes** with `403`.
A service, script or agent holding the internal key cannot change a setting.
- **Agent tokens are accepted.** A token carrying `act` (or `azp`, or an agent session such as
`amr` chaac_cloud) is accepted on settings and admin writes when its subject (`sub`) is a settings
owner or super admin, whoever the actor is (Jefferson, `tawa session`, tawa-cli). The audit records
the actor as `via` next to the person (`by`), so a change made through an agent shows as such.
- Personas are refused, and the person check itself is never widened.
`canWrite` and `actor` in the list response tell the UI whether to render fields as editable.
## From the CLI
```bash
tawa switches list -s policy-spot # every setting, value, version
tawa switches get -s policy-spot binders.defaultTemplateId
tawa switches set -s policy-spot binders.defaultTemplateId '"tpl_123"' # JSON value
tawa switches history -s policy-spot binders.defaultTemplateId
```
`set` sends `expectedVersion` from a fresh read, so it never overwrites a change it did not see.
The CLI sends your own login token; for a service that accepts only its own audience
(iec-bio-api) it exchanges the login first, as `tawa session` does.
## UI
The Tawa Console (tawa-web) renders every declared setting generically from `description` and
`editor`. Adding a key to the registry is all it takes; no Console change or deploy is needed.
| Service | Console page |
|---|---|
| iec-janus | Console → Janus Switches |
| iec-wallet | Console → Wallet Switches |
Every service on the Console's switches pages is also reachable with `tawa switches -s <service>`:
janus, iec-wallet, iec-builder, chain-gateway, iec-locker, policy-spot, iec-test, iec-actuary,
bio-api, bio-vault, marketsninja, iec-policyos, iec-split-pay.
## Review Rule
A PR that adds a tunable env var or config var is changed to a setting before merge. Reviewers
ask one question: could someone want to change this without a deploy? If yes, it goes in the registry.
Install
Copy the skill content and save it to:
~/.claude/commands/tawa-runtime-settings.mdComing soon via CLI:
tawa chaac install tawa-runtime-settingsDetails
- Format
- Command
- Category
- configure
- Version
- 1.0.68490
- Tokens
- ~1,763
- Updated
- 2026-11-25
platformsettingsfeature-flagsconfigconsolesuper-admintawa-web