8Declare each timed stage's cost-of-quality tier and that tier's budget.
12- Keep local timing data bounded, private and advisory.
18 L1 -- instrumentation failures
20 L3 -- semantic details
25- Timing instrumentation never changes the wrapped operation's outcome.
26- A project may lower a shipped tier budget and never raise one.
30- oc_diagnostics (structured timing diagnostics)
32from __future__
import annotations
34from collections.abc
import Mapping
35from types
import MappingProxyType
36from oc_diagnostics
import _dbg
38INNER_LOOP =
"inner_loop"
39PER_COMMIT =
"per_commit"
40PER_LANDING =
"per_landing"
45TIER_BUDGETS_MS: Mapping[str, int |
None] = MappingProxyType({
55_STAGES_BY_TIER: Mapping[str, tuple[str, ...]] = {
56 INNER_LOOP: (
"format",
"health",
"lint",
"new",
"oct"),
57 PER_COMMIT: (
"git",
"git.add",
"git.branch",
"git.check",
"git.commit",
58 "git.commit-msg",
"git.ignore",
"git.restore",
"git.status"),
59 PER_LANDING: (
"agent",
"audit",
"clean",
"complexity",
"deps",
"docs",
60 "engine.dispatch",
"engine.prepare",
"engine.teardown",
61 "export-skeleton",
"export-source",
"git.changelog",
"test",
63 PERIODIC: (
"diag",
"diag.list-domains",
"diag.migrate-config",
64 "diag.restore",
"diag.set-level",
"diag.validate-config",
65 "git.hooks",
"git.hooks.install",
"git.hooks.remove",
66 "git.hooks.status",
"git.init",
"install",
"install-hooks",
67 "install-mcp",
"migrate",
"migrate.option-c",
"mutate",
71STAGE_TIERS: Mapping[str, str] = MappingProxyType(
72 {stage: tier
for tier, stages
in _STAGES_BY_TIER.items()
for stage
in stages})
75 """Return the declared tier, never inventing one for an unknown stage."""
76 return STAGE_TIERS.get(stage)
if isinstance(stage, str)
else None
78def budgets_ms(overrides: object =
None) -> dict[str, int |
None]:
79 """Apply project overrides, which may only lower a shipped budget."""
81 budgets = dict(TIER_BUDGETS_MS)
82 if not isinstance(overrides, Mapping):
84 for tier, value
in overrides.items():
85 shipped = TIER_BUDGETS_MS.get(tier)
if isinstance(tier, str)
else None
86 if shipped
is None or type(value)
is not int
or value <= 0
or value > shipped:
87 _dbg(
"GENERAL", func,
"VALIDATION_ERROR: invalid timing budget", 3)
92def budget_for(stage: object, budgets: Mapping[str, int |
None] |
None =
None) -> int |
None:
93 """Return the effective budget, or None when the stage declares no tier."""
95 return None if tier
is None else (TIER_BUDGETS_MS
if budgets
is None else budgets).get(tier)
dict[str, int|None] budgets_ms(object overrides=None)
int|None budget_for(object stage, Mapping[str, int|None]|None budgets=None)
str|None tier_for(object stage)