Skip to main content

Context Engine — Feature Flags

All feature flags are Redis keys under the ff:context: prefix. Precedence is most specific wins: agent > org > global. Flags are read on every request with sub-millisecond overhead (Redis is already in the hot path).

Engine mode

Controls whether the full assembly pipeline runs, only retrieval runs, or the request is passed through to the caller unmodified.

KeyValuesEffect
ff:context:mode:globalfull, retrieval_only, passthroughGlobal engine mode (default: full).
ff:context:mode:{org_id}full, retrieval_only, passthroughPer-org override.
ff:context:mode:{org_id}:{agent_id}full, retrieval_only, passthroughPer-agent override.

Modes:

  • full — Steps 1–9 of the LLD #7 §2.3 pipeline run as designed.
  • retrieval_only — Steps 1, 3, 6, 7, 8 only. Skips pinned loading, compaction checks, and metrics emission. Used as a circuit-breaker when the pipeline is misbehaving in prod.
  • passthrough — The Context Engine returns the caller's prompt unchanged plus the L1–L4 immutable layers. Emergency fallback only.

Sampling tier override

Overrides the adaptive sampler tier for a given org. Useful when an org needs higher-fidelity data for debugging or when a low-value org should be down-sampled aggressively to protect the $1K/mo metrics ceiling (founder decision #3).

KeyValuesEffect
ff:context:sampling:pin:{org_id}T0, T1, T2, T3, T4Pin this org's sampling tier. Unset the key to return control to the adaptive sampler.

Tier rates: T0=100%, T1=50%, T2=20%, T3=5%, T4=2%.

Compaction toggle

KeyValuesEffect
ff:context:compaction:enabledtrue, falseGlobal compaction toggle (default: true). Disabling stops the sliding-window summarizer and skips the compaction step in assembly. Use only if compaction quality has regressed.

Runbook: flipping a flag safely

  1. Check current state

    redis-cli -u "$REDIS_URL" get "ff:context:mode:global"
  2. Set the flag (example: put an org in retrieval_only mode)

    redis-cli -u "$REDIS_URL" set "ff:context:mode:org_abc123" "retrieval_only"
  3. Verify the change landed

    • Grafana → Context Engine Overview → filter org_id=org_abc123
    • Expect context_engine_assembly_duration_seconds to drop (fewer steps)
    • Expect context_engine_savings_ratio to change (different pipeline shape)
  4. Audit trail Every flag flip must be accompanied by a GitHub issue with label feature-flag documenting the reason, the operator, and the rollback plan. Flag state is source-of-truth in Redis but the decision log is on GitHub.

  5. Rollback

    redis-cli -u "$REDIS_URL" del "ff:context:mode:org_abc123"

    The precedence chain falls back to the org's nearest ancestor, ultimately hitting ff:context:mode:global.

Defaults at process startup

If none of the Redis keys are set:

FlagDefault
modefull
sampling tieradaptive (no pin)
compactiontrue

These defaults are baked into the Context Engine binary (not read from the ConfigMap) so that a Redis outage does not disable the engine.