Repository navigation
feat(licensing): unified feature_gate facade for the open-core boundary (ADR 0044) - #246
Closed
cursor[bot] wants to merge 3 commits into
Closed
cursor[bot] wants to merge 3 commits into
cursor[bot] wants to merge 3 commits into
Conversation
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" |
Merged
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 tierresolver), and
LicenseGuard(license state machine). New code that neededto 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):FeatureGateDecisiondataclass +evaluate_feature/is_feature_enabled/require_feature/snapshot_gate_state. Re-exported fromcore.licensing.__init__.core/licensing/tier_features.py: registersconnector_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_featureraises with thestructured 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.mdlast-ADR pointer (0043 → 0044).docs/plans/PLAN_PRODUCT_TIERS_AND_OPEN_CORE.md: enforcement roadmapPhase 2 marked done; header
Status:line refreshed.docs/plans/PLANS_HUB.mdregenerated byscripts/plans_hub_sync.py.Why this preserves the community contract
Tier.OPEN(the lab / unlicensed default) still allows every registeredfeature. Enforcement only kicks in when the operator opts into
licensing.mode: enforcedor setslicensing.effective_tierin YAML —exactly what
docs/LICENSING_OPEN_CORE_AND_COMMERCIAL.mdalready promises("forks and academic use keep working"). A 30-line smoke confirms this:
under the open default, every premium feature returns
allowed=Truewithreason="open_mode_enforcement_disabled".Doctrinal alignment
caps, statement timeouts, or
WITH (NOLOCK)posture inconnectors/sql_sampling.py. It only decides whether the more expensiveingredient (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.
FeatureGateDecisionwith a factualreason(tier_below_required,license_state_not_allowed,feature_not_registered_default_community).Callers are expected to surface that reason via
core/scan_audit_log.pyrather than swallowing it.
to_audit_dict()is JSON-friendly so log,API, and dashboard consumers share the same shape.
Type of change
Checklist
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.pt-BR locale, commercial guard, external plan links, PII guards) all
pass on every commit.
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 callrequire_feature()insteadof 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
docs/plans/PLAN_PRODUCT_TIERS_AND_OPEN_CORE.mdPhase 2 row.docs/ops/inspirations/DEFENSIVE_SCANNING_MANIFESTO.md,docs/ops/inspirations/THE_ART_OF_THE_FALLBACK.md.