fix chatbot limits and test * add tests
7.6 KiB
Configuration Management
This document reflects the current configuration model implemented under internal/serviceconfig.
Loading Model
Configuration is loaded through:
.env(if present)- Environment variables
- Struct defaults (
envDefault)
Runtime initialization is handled by serviceconfig.InitializeConfig.
Core Configuration (internal/serviceconfig/common.go)
PORT(default8080)BASE_URL(defaulthttp://localhost)- Embedded config domains:
- auth
- thread pool
- logger
- observability
- database
- aws
- queue
Database Configuration (internal/serviceconfig/database/config.go)
Required:
PGUSERPGPASSWORDPGHOSTPGPORTPGDATABASE
Optional:
DB_NOSSL(defaultfalse)
AWS/Object Store Configuration
AWS (internal/serviceconfig/aws/config.go)
AWS_REGION(required)AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN(optional; SDK chain also supported)AWS_ENDPOINT_URL(optional global endpoint override)AWS_PROFILE(optional)
Object Store (internal/serviceconfig/objectstore/config.go)
BUCKET(required)AWS_ENDPOINT_URL_S3(optional S3-specific endpoint)AWS_S3_USE_PATH_STYLE(defaultfalse)
Queue Client (internal/serviceconfig/queue/config.go)
AWS_ENDPOINT_URL_SQS(optional SQS-specific endpoint)
Queue URL Variables (service-specific)
Active flow:
STORE_EVENT_URLDOCUMENT_INIT_URLDOCUMENT_SYNC_URLDOCUMENT_CLEAN_URLCLIENT_SYNC_URL
Compatibility/deprecated flow (still used by some deployment files):
DOCUMENT_TEXT_URLQUERY_SYNC_URLQUERY_URLQUERY_VERSION_SYNC_URL
Per-runner listener queue URL:
QUEUE_URL(required by runner base config)
Authentication / Authorization
From internal/serviceconfig/auth/config.go:
COGNITO_REGION(defaultus-east-2)COGNITO_USER_POOL_ID(required)COGNITO_CLIENT_SECRET(required)COGNITO_DOMAIN(required)COGNITO_CLIENT_ID(required)DISABLE_AUTH(defaultfalse)NO_JWT_VALIDATION(defaultfalse)PERMIT_IO_API_KEY(optional but required for full Permit.io operation)PERMIT_IO_PDP_URL(defaulthttp://localhost:7766)COGNITO_ENVIRONMENT_ID(optional, default empty) - Scopes this server instance to a specific environment within a shared Cognito user pool. When set, only users tagged with this environment ID (or untagged legacy users) are visible to admin operations and EULA compliance. Must be lowercase alphanumeric with underscores allowed in middle positions, max 50 characters. Empty string means no scoping (backward compatible).
Two-pool service accounts (optional; see 13-two-pool-service-accounts.md):
COGNITO_SVC_USER_POOL_ID(default empty) - Cognito user pool id for service accounts ("pool B"). Empty disables the feature; queryAPI then validates tokens only againstCOGNITO_USER_POOL_ID. Setting this turns on multi-issuer validation.COGNITO_SVC_JWKS_URL(default derived) - JWKS endpoint for pool B. When unset, queryAPI computeshttps://cognito-idp.<COGNITO_REGION>.amazonaws.com/<COGNITO_SVC_USER_POOL_ID>/.well-known/jwks.jsonat startup. Override only for testing against a fake JWKS server.COGNITO_SVC_APP_CLIENT_ID(default empty) - App client id for pool B. Consumed by thecmd/auth_related/service.account.toolCLI and by service-account callers issuingInitiateAuth; queryAPI itself does not read it at runtime.
Auth path customization:
COGNITO_LOGIN_PATH(default/login)COGNITO_CALLBACK_PATH(default/login-callback)COGNITO_HOME_PATH(default/home)COGNITO_LOGOUT_PATH(default/logout)HEALTH_PATH(default/health)
Local development bootstrap, active only when DISABLE_AUTH=true:
LOCAL_DEV_CLIENT_ID(optional) - Creates this client at queryAPI startup when it does not already exist.LOCAL_DEV_CLIENT_NAME(optional) - Display name forLOCAL_DEV_CLIENT_ID; defaults to the client ID.LOCAL_DEV_EULA_VERSION(optional) - Creates or updates this local EULA version and marks it current.LOCAL_DEV_EULA_TITLE(optional) - Title for the local EULA; defaults toAArete DoczyAI Terms of Use.LOCAL_DEV_EULA_AUTO_ACCEPT_SUBJECT(optional) - Cognito subject/user key to mark as accepted for the local EULA.LOCAL_DEV_EULA_AUTO_ACCEPT_EMAIL(optional) - Email for the auto-accepted user; defaults to the subject value.
Rate Limiting
From internal/serviceconfig/ratelimit/config.go:
RATE_LIMIT_GLOBAL_RATERATE_LIMIT_GLOBAL_BURSTRATE_LIMIT_DEFAULT_RATERATE_LIMIT_DEFAULT_BURSTRATE_LIMIT_EXPIRES_INRATE_LIMIT_ENDPOINT_OVERRIDES(JSON)
Defaults:
- Global:
500 rps, burst1000 - Per-IP:
5 rps, burst10
M6 behavior change (plan §10 M6 + §11): RATE_LIMIT_ENDPOINT_OVERRIDES
now changes ACTUAL throttling behavior, not only the RateLimit and
Retry-After response headers. Each (IP, route) tuple gets its own
budget when the route has an override entry. Operators upgrading from
pre-M6 deployments should review existing overrides for unintended
tightening. Override map keys use Echo's path template form
(:clientId, :sessionId), NOT the OpenAPI {clientId} form. See
Chatbot Guide → Rate-limit overrides
for the chatbot turn-endpoint example.
Chatbot (FastAPI agent service)
From internal/serviceconfig/chatbot/config.go. Plan §8.
| Variable | Default | Validation | Purpose |
|---|---|---|---|
CHATBOT_SERVICE_URL |
(required, notEmpty) | env-loader rejects empty | FastAPI base URL. |
CHATBOT_API_KEY |
(required, notEmpty) | env-loader rejects empty | Sent verbatim as the X-API-Key header. |
CHATBOT_REQUEST_TIMEOUT_SECONDS |
60 |
>= 1 |
Per-attempt FastAPI HTTP timeout. |
CHATBOT_MAX_TURN_CHARS |
2000 |
1 <= x <= 65536 |
Caps prompt and answer.text rune count. Upper bound (chatbot.MaxTurnCharsCeiling) tracks the OpenAPI prompt.maxLength so the configured cap is always reachable. |
CHATBOT_RECENT_TURNS |
5 |
1 <= x <= 5 |
Conversation-history length and session-list preview cap. |
Validated at startup via chatbot.ChatbotConfig.Validate(), called
between serviceconfig.InitializeConfig and cfg.InitializeAuthConfig
in cmd/queryAPI/main.go. The process exits with status 1 on
validation failure.
Derived constants (not env-driven):
chatbot.StateMaxBytes = 64 * 1024— session-state cap on persist.chatbot.MaxTurnCharsCeiling = 65536— upper bound onCHATBOT_MAX_TURN_CHARS, mirroring the OpenAPIBotTurnAddRequest.prompt.maxLengthinserviceAPIs/queryAPI.yaml. Changing one requires changing the other.chatbot.ChatbotConfig.InflightGraceSeconds() = 2 * RequestTimeoutSecondsper plan §8 literal.
See Chatbot Guide for the complete configuration reference, including the grace-window floor.
Logging and Observability
LOG_LEVEL(defaultINFO)ENABLE_OTEL(defaultfalse)
Notes
- Some deployment files still include legacy query/text environment variables because deprecated compatibility services remain in compose definitions.
- For API/runtime behavior, prefer
serviceAPIs/queryAPI.yamlplusinternal/serviceconfig/*as source of truth.