Skip to content

feat(licensing): unified feature_gate facade for the open-core boundary (ADR 0044) - #246

Closed
cursor[bot] wants to merge 3 commits into
mainfrom
cursor/sre-agent-protocol-f6db
Closed

cursor[bot] wants to merge 3 commits into
mainfrom
cursor/sre-agent-protocol-f6db

Conversation

@cursor

@cursor cursor Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Description

Architectural-segregation slice for the open-core boundary. The repo already
had three independent pieces of the feature-gate stack —
tier_features.py (registry), runtime_feature_tier.py (effective tier
resolver), and LicenseGuard (license state machine). New code that needed
to gate a Pro / Enterprise capability had to wire all three by hand, which
made the boundary easy to forget and pushed each call site to invent its
own "what reason do I log when access is denied?" answer.

This PR adds one runtime facade so require_feature("connector_mainframe", config)
is the only line a future Enterprise connector has to call, and registers
the premium feature names called out by the architectural mission
(mainframe / SAP HR connectors, high-frequency sampling, advanced audit log,
SIEM export, PDF report export).

What changed

  • core/licensing/feature_gate.py (new): FeatureGateDecision dataclass +
    evaluate_feature / is_feature_enabled / require_feature /
    snapshot_gate_state. Re-exported from core.licensing.__init__.
  • core/licensing/tier_features.py: registers connector_mainframe,
    connector_sap_hr_totvs_rm, high_frequency_sampling, audit_log_advanced,
    siem_export, report_pdf_export.
  • tests/test_feature_gate.py (new, 11 cases): OPEN-tier allow-all,
    Pro tier sees Pro / blocks Enterprise, require_feature raises with the
    structured decision attached, snapshot shape, audit-friendly serialization.
  • docs/adr/0044-runtime-feature-gate-facade-for-open-core-boundary.md +
    index rows in docs/adr/README*.md.
  • AGENTS.md last-ADR pointer (0043 → 0044).
  • docs/plans/PLAN_PRODUCT_TIERS_AND_OPEN_CORE.md: enforcement roadmap
    Phase 2 marked done; header Status: line refreshed.
  • docs/plans/PLANS_HUB.md regenerated by scripts/plans_hub_sync.py.

Why this preserves the community contract

Tier.OPEN (the lab / unlicensed default) still allows every registered
feature. Enforcement only kicks in when the operator opts into
licensing.mode: enforced or sets licensing.effective_tier in YAML —
exactly what docs/LICENSING_OPEN_CORE_AND_COMMERCIAL.md already promises
("forks and academic use keep working"). A 30-line smoke confirms this:
under the open default, every premium feature returns allowed=True with
reason="open_mode_enforcement_disabled".

Doctrinal alignment

  • DEFENSIVE_SCANNING_MANIFESTO.md — the gate never changes sampling
    caps, statement timeouts, or WITH (NOLOCK) posture in
    connectors/sql_sampling.py. It only decides whether the more expensive
    ingredient (e.g. high-frequency sampling profile) is offered to the
    operator. Hard ceilings still clamp every read. Zero impact on database
    locks. Zero new SQL.
  • THE_ART_OF_THE_FALLBACK.md §3 — every denial returns a structured
    FeatureGateDecision with a factual reason (tier_below_required,
    license_state_not_allowed, feature_not_registered_default_community).
    Callers are expected to surface that reason via core/scan_audit_log.py
    rather than swallowing it. to_audit_dict() is JSON-friendly so log,
    API, and dashboard consumers share the same shape.

Type of change

  • New feature (additive, non-destructive — open-core default unchanged)
  • Documentation (ADR 0044, plan status, AGENTS pointer)
  • Refactor / maintenance (registry expansion)
  • Bug fix

Checklist

  • Tests pass locally — 49 cases green across test_feature_gate.py,
    test_tier_features_open_core_subscription.py,
    test_enterprise_surface_posture.py, test_api_key.py,
    test_about_version_matches_pyproject.py.
  • Pre-commit (Ruff, Ruff format, plans-stats, plans-hub, markdown,
    pt-BR locale, commercial guard, external plan links, PII guards) all
    pass on every commit.
  • Docs updated: ADR + plan + AGENTS pointer + PLANS_HUB regen.
  • Security: no new dependencies, no JWT signing changes, no DB SQL
    changes; gate is read-only at process level.

Companion follow-up

A separate issue is recommended for Phase 3 of the enforcement
roadmap: migrating existing call sites (connectors/, pro/,
report/, dashboard route handlers) to call require_feature() instead
of running unconditionally. That work is intentionally out of scope here
to keep this PR reviewable and zero-regression — the facade is the
foundation; the migration is the next slice.

Related

  • ADR 0027 — Commercial tier boundaries (the docs-only predecessor).
  • docs/plans/PLAN_PRODUCT_TIERS_AND_OPEN_CORE.md Phase 2 row.
  • docs/ops/inspirations/DEFENSIVE_SCANNING_MANIFESTO.md,
    docs/ops/inspirations/THE_ART_OF_THE_FALLBACK.md.
Open in Web View Automation 

cursoragent and others added 3 commits April 27, 2026 17:17
Wires LicenseGuard, runtime tier resolution, and the tier_features registry
behind one call (evaluate_feature / is_feature_enabled / require_feature)
so new code does not have to re-derive the open-core boundary by hand.

- core/licensing/feature_gate.py: FeatureGateDecision dataclass + facade.
- core/licensing/__init__.py: re-export the public surface.
- core/licensing/tier_features.py: register premium feature names called
  out by the architectural-segregation mission (connector_mainframe,
  high_frequency_sampling, audit_log_advanced, siem_export, etc.).

OPEN tier (default) still allows everything: enforcement only kicks in
when licensing.mode=enforced or licensing.effective_tier is set, matching
the LICENSING_OPEN_CORE_AND_COMMERCIAL.md contract.

Doctrinal alignment:
- DEFENSIVE_SCANNING_MANIFESTO.md: this gate does not change sampling caps,
  statement timeouts, or NOLOCK posture; hard ceilings in
  connectors/sql_sampling.py still clamp every read.
- THE_ART_OF_THE_FALLBACK.md: every denial returns a structured
  FeatureGateDecision with a factual reason; callers are expected to
  surface it via core/scan_audit_log.py instead of swallowing it.

Co-authored-by: Fabio Tavares Leitão <[email protected]>
Cover the four wiring contracts the facade exists to enforce:

- OPEN tier (community / lab default) allows everything; enforcement only
  kicks in when the operator opts into it (matches LICENSING_OPEN_CORE
  contract — 'forks and academic use keep working').
- Tier ladder: Community < Pro < Enterprise; high_frequency_sampling and
  connector_mainframe stay Enterprise-only when the running tier is Pro.
- require_feature() raises FeatureNotAvailableError carrying the structured
  FeatureGateDecision so callers can surface it without re-evaluating.
- snapshot_gate_state() returns a JSON-friendly shape with per-feature
  decisions — input ready for /status and dashboard banners.

Co-authored-by: Fabio Tavares Leitão <[email protected]>
…ndary

Records the architectural decision that landed in
core/licensing/feature_gate.py: a single runtime entry point
(evaluate_feature / require_feature / snapshot_gate_state) wires the
LicenseGuard state machine, the runtime tier resolver, and the
tier_features registry behind one call.

Also updates:
- docs/adr/README.md + README.pt_BR.md index rows.
- AGENTS.md last-ADR pointer (0043 -> 0044).
- docs/plans/PLAN_PRODUCT_TIERS_AND_OPEN_CORE.md: enforcement roadmap
  Phase 2 marked done; header Status line + Related cross-links the new
  ADR.
- docs/plans/PLANS_HUB.md regenerated by scripts/plans_hub_sync.py.

Co-authored-by: Fabio Tavares Leitão <[email protected]>
current_tier = get_runtime_tier_for_features(cfg)
required_tier = get_required_tier(feature)

license_state = "UNKNOWN"
cfg = _coerce_config(config)
feature_names = list(features) if features else sorted(FEATURE_TIER_MAP.keys())
current_tier = get_runtime_tier_for_features(cfg)
license_state = "UNKNOWN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants