hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

resource_envelope.mojo (1737B)


      1 """Frozen semantic resource envelope (ADR-0010 D21; policy table
      2 ``docs/spec/hyf_http_v1/policy/hyf_http_v1_policy.v1.toml``).
      3 
      4 These are Codex-selected local regression bounds, not production SLOs. The
      5 values are frozen here as named constants and applied by
      6 :func:`default_resource_envelope`; dependent slices (H093 and the operation
      7 pipelines) consume them and may not enlarge or weaken them.
      8 """
      9 
     10 comptime RESOURCE_ENVELOPE_MAX_CANDIDATES: Int = 64
     11 comptime RESOURCE_ENVELOPE_MAX_PLANS: Int = 8
     12 comptime RESOURCE_ENVELOPE_MAX_STATE_BYTES: Int = 4096
     13 comptime RESOURCE_ENVELOPE_MAX_QUESTIONS: Int = 32
     14 comptime RESOURCE_ENVELOPE_MAX_PROVIDER_CALLS: Int = 4
     15 
     16 
     17 @fieldwise_init
     18 struct ResourceEnvelope(Copyable, Movable):
     19     var max_candidates: Int
     20     var max_plans: Int
     21     var max_state_bytes: Int
     22     var max_questions: Int
     23     var max_provider_calls: Int
     24 
     25 
     26 def default_resource_envelope() -> ResourceEnvelope:
     27     return ResourceEnvelope(
     28         max_candidates=RESOURCE_ENVELOPE_MAX_CANDIDATES,
     29         max_plans=RESOURCE_ENVELOPE_MAX_PLANS,
     30         max_state_bytes=RESOURCE_ENVELOPE_MAX_STATE_BYTES,
     31         max_questions=RESOURCE_ENVELOPE_MAX_QUESTIONS,
     32         max_provider_calls=RESOURCE_ENVELOPE_MAX_PROVIDER_CALLS,
     33     )
     34 
     35 
     36 def within_envelope(
     37     envelope: ResourceEnvelope,
     38     candidates: Int,
     39     plans: Int,
     40     state_bytes: Int,
     41     questions: Int,
     42     provider_calls: Int,
     43 ) -> Bool:
     44     """True when every dimension is at or below its inclusive cap."""
     45     return (
     46         candidates <= envelope.max_candidates
     47         and plans <= envelope.max_plans
     48         and state_bytes <= envelope.max_state_bytes
     49         and questions <= envelope.max_questions
     50         and provider_calls <= envelope.max_provider_calls
     51     )