-
Notifications
You must be signed in to change notification settings - Fork 701
feat(F192): evidence-source prerequisite gate for eval scheduler #1352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mindfn
wants to merge
1
commit into
main
Choose a base branch
from
feat/f192-evidence-prereq-gate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
104 changes: 104 additions & 0 deletions
104
packages/api/src/infrastructure/harness-eval/domain/eval-domain-evidence-gate.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /** | ||
| * Evidence-source prerequisite gate for scheduled eval domains. | ||
| * | ||
| * Verdict provenance: eval:a2a build verdict | ||
| * `2026-07-07-eval-a2a-reeval-telemetry-still-disabled-build` (PR #19). | ||
| * | ||
| * Direction B's `publishPrereqProbe` (eval-domain-daily.ts) answers "can this | ||
| * runtime ACCEPT a published verdict?". This gate answers the upstream | ||
| * question: "can the domain's evidence source PRODUCE evidence at all?" | ||
| * | ||
| * eval:a2a consumes `f167-runtime-eval` artifacts derived from live OTel | ||
| * telemetry. When `TELEMETRY_HMAC_SALT` is unset in a non-dev environment, | ||
| * `initTelemetry()` disables OTel at boot — no fresh snapshots can exist, and | ||
| * invoking the eval cat burns a full LLM session to re-conclude "telemetry | ||
| * still disabled" (the 2026-06-30 → 2026-07-07 series produced daily | ||
| * near-identical verdicts). Failing closed BEFORE invocation posts a | ||
| * zero-LLM-cost skip notice to the domain's own system thread instead, | ||
| * keeping the gap visible without the burn. | ||
| * | ||
| * OTel init state is fixed for the process lifetime (the salt is read at | ||
| * boot), so a boolean thunk wired from bootstrap is a complete input — no | ||
| * re-probing or caching needed. | ||
| */ | ||
|
|
||
| import type { EvalDomainRegistryEntry } from './eval-domain-registry.js'; | ||
|
|
||
| /** Minimal domain projection the gate needs — keeps probes trivial to test. */ | ||
| export type EvidenceGateDomain = Pick<EvalDomainRegistryEntry, 'domainId' | 'sourceAdapter'>; | ||
|
|
||
| export type EvidencePrereqResult = { ok: true } | { ok: false; reason: string }; | ||
|
|
||
| export type EvidencePrereqProbe = (domain: EvidenceGateDomain) => EvidencePrereqResult | Promise<EvidencePrereqResult>; | ||
|
|
||
| /** | ||
| * Source adapters whose evidence pipeline hard-requires live OTel telemetry. | ||
| * Registry `sourceAdapter` is a free slug (see eval-domain-registry.ts), so | ||
| * the adapter → prerequisite mapping lives here, next to the probe. | ||
| */ | ||
| const TELEMETRY_BACKED_ADAPTERS: ReadonlySet<string> = new Set(['f167-runtime-eval']); | ||
|
|
||
| export function isTelemetryBackedAdapter(sourceAdapter: string): boolean { | ||
| return TELEMETRY_BACKED_ADAPTERS.has(sourceAdapter); | ||
| } | ||
|
|
||
| /** | ||
| * Probe factory. Bootstrap wires `otelEnabled: () => !!telemetryHandle.getMetricsText` | ||
| * — the same init-state signal `GET /api/telemetry/health` reports as | ||
| * `otelEnabled` (routes/telemetry.ts Phase K note: actual init state, not an | ||
| * env-var proxy). Non-telemetry-backed adapters always pass through. | ||
| */ | ||
| export function createTelemetryEvidencePrereqProbe(opts: { | ||
| otelEnabled: () => boolean; | ||
| /** Override the reason text; defaults to the health route's disabledReason derivation. */ | ||
| disabledReason?: () => string; | ||
| }): EvidencePrereqProbe { | ||
| return (domain) => { | ||
| if (!isTelemetryBackedAdapter(domain.sourceAdapter)) return { ok: true }; | ||
| if (opts.otelEnabled()) return { ok: true }; | ||
| const reason = | ||
| opts.disabledReason?.() ?? | ||
| (process.env.OTEL_SDK_DISABLED === 'true' | ||
| ? 'OTel disabled by OTEL_SDK_DISABLED=true' | ||
| : 'OTel disabled at boot: HMAC salt validation failed (TELEMETRY_HMAC_SALT not configured)'); | ||
| return { ok: false, reason }; | ||
| }; | ||
| } | ||
|
|
||
| /** Fail-closed evaluation: a probe that throws is treated as "evidence unavailable". */ | ||
| export async function evaluateEvidencePrereq( | ||
| probe: EvidencePrereqProbe, | ||
| domain: EvidenceGateDomain, | ||
| ): Promise<EvidencePrereqResult> { | ||
| try { | ||
| return await Promise.resolve(probe(domain)); | ||
| } catch (err) { | ||
| const message = err instanceof Error ? err.message : String(err); | ||
| return { ok: false, reason: `evidence prereq probe threw: ${message}` }; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Stable-header skip notice posted to the domain's OWN system thread when the | ||
| * cron fails closed. Header format mirrors `buildPublishPrereqSkippedMessage` | ||
| * so eval-domain readers / log scrubbers can grep both skip classes uniformly. | ||
| */ | ||
| export function buildEvidencePrereqSkippedMessage(domain: EvidenceGateDomain, reason: string): string { | ||
| return [ | ||
| `## Eval Domain: ${domain.domainId} — SKIPPED (evidence source unavailable)`, | ||
| '', | ||
| "The scheduled eval was skipped because this domain's evidence source", | ||
| `(\`${domain.sourceAdapter}\`) cannot produce evidence on this runtime:`, | ||
| '', | ||
| `> ${reason}`, | ||
| '', | ||
| 'Why this matters: invoking the eval cat without a live evidence source', | ||
| 'burns a full LLM session to re-conclude the same telemetry gap every fire', | ||
| '(see the eval:a2a 2026-06-30 → 2026-07-07 verdict series). The fail-closed', | ||
| 'skip keeps the gap visible in this thread at zero LLM cost.', | ||
| '', | ||
| 'Next action: configure a non-empty `TELEMETRY_HMAC_SALT` for the API', | ||
| 'runtime and restart it (OTel initializes at boot), or set `enabled: false`', | ||
| "in this domain's registry YAML to pause the schedule intentionally.", | ||
| ].join('\n'); | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
OTEL_SDK_DISABLED=true(or the probe fails for another reason), every skip notice still instructs the operator to configureTELEMETRY_HMAC_SALT; adding the salt and restarting will not re-enable telemetry while the disable flag remains set. Build the next-action text from the detected reason, including clearingOTEL_SDK_DISABLEDfor the intentional-disable case, so the notice does not prescribe an ineffective recovery.Useful? React with 👍 / 👎.