feat(orchestrator): intent-fidelity gate — "A or better", with percentile - #18
Conversation
…tile Post-execution gate that judges whether a run achieved the user's ORIGINAL INTENT, not merely whether its tasks ran. Scores intent fidelity as a 0-100 percentile with a letter grade and a met/exceeded/missed verdict against a configurable "A" bar (JUSTAI_INTENT_BAR, default 90). Honest downgrade: a task-complete run judged to have MISSED the intent is downgraded complete->partial by the synthesizer, so "all tasks done" can no longer masquerade as "achieved your goal". The gate only downgrades — it never upgrades a partial run, so a real task failure is never hidden. - justai/intent_fidelity.py: score_fidelity() (LiteLLM judge + deterministic completion-based heuristic fallback); FidelityResult / verdict / grade. - synthesizer: RunSummary carries fidelity fields; applies the downgrade. - orchestrator: stage "[6/6] Intent-fidelity gate"; OrchestrationResult carries fidelity fields; flag JUSTAI_FIDELITY_GATE (default on). - tests: 12 new (grade mapping, heuristic, mocked LLM judge, downgrade). Best-effort: any scoring error degrades to the heuristic and never fails a run. When the model proxy is down, fidelity == completion (no status change vs prior behavior). Behavior-semantics note: this changes when a run reports "complete"; flag-disable to restore prior task-count-only semantics. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VPortjb8U5oteKxppGuVDQ
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
Introduces an intent-fidelity gate that scores post-execution outcome fidelity (0–100 percentile + grade) and honestly downgrades task-complete runs from complete → partial when the outcome misses the original intent, while remaining best-effort (non-fatal) with a heuristic fallback.
Changes:
- Add
justai/intent_fidelity.pywith LiteLLM judge + deterministic completion-based heuristic fallback and verdict/grade mapping. - Thread fidelity results through
orchestrator.run()→synthesizer.synthesize()→RunSummary/OrchestrationResult, including downgrade logic. - Add comprehensive unit + integration tests for scoring, fallback behavior, and the downgrade semantics.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_orchestrator_pipeline.py | Mocks fidelity scoring in the orchestrator pipeline tests and asserts fidelity fields are surfaced on results. |
| tests/test_intent_fidelity.py | Adds unit + integration tests for grading, LLM judge path (mocked), heuristic fallback, and synthesizer downgrade behavior. |
| justai/synthesizer.py | Extends RunSummary with fidelity fields and applies downgrade-on-missed-intent when tasks were otherwise complete. |
| justai/orchestrator.py | Adds a gated Stage 6 that computes intent fidelity (best-effort) and passes it into synthesis; surfaces fidelity fields in return object/trace metadata. |
| justai/intent_fidelity.py | New module implementing fidelity scoring, verdicts, grades, LiteLLM call, and heuristic fallback. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| Main pipeline: intake → intent → plan → review → checkpoint → delegate → | ||
| synthesize → intent-fidelity gate |
| def _fidelity(verdict: str = "met", fidelity: float = 100.0): | ||
| from justai.intent_fidelity import FidelityResult, FidelityVerdict | ||
|
|
||
| v = FidelityVerdict(verdict) | ||
| return FidelityResult( | ||
| fidelity=fidelity, | ||
| verdict=v, | ||
| a_or_better=v in (FidelityVerdict.MET, FidelityVerdict.EXCEEDED), | ||
| grade="A" if fidelity >= 90 else "F", | ||
| rationale="test fidelity", | ||
| source="test", | ||
| ) |
| # "A or better" — the intent bar. Default: A == 90th-percentile fidelity. | ||
| # a_or_better tracks THIS bar; the letter grade is a fixed scale, so at the | ||
| # default bar (90) a_or_better is exactly (grade in {A, A+}). | ||
| INTENT_BAR = float(os.environ.get("JUSTAI_INTENT_BAR", "90")) | ||
| FIDELITY_MODEL = os.environ.get("JUSTAI_FIDELITY_MODEL", "openai/claude-opus-4-6") |
| intent_line = ( | ||
| f"Intent: {s.intent_fidelity:.0f}/100 ({s.fidelity_grade}) " | ||
| f"{s.fidelity_verdict} | a-or-better: {s.a_or_better}" | ||
| ) | ||
| lines.append(f"| {intent_line:<48} |") |
|
Desktop Codex exact-head review at
Networkless differential testing at this exact head produced 407 passes with the same 7 known failures/14 subtests as the base, but GitHub currently has only Vercel checks—no Python CI. Tests/source merge, activation, and live acceptance remain separate gates. |
Resolves the large-bad findings on the gate at dev-grade (honest-mistake
threat model, high-trust box):
- _env_float: module-level INTENT_BAR no longer crashes import on a
malformed/inline-commented JUSTAI_INTENT_BAR (was a hard import failure).
- _coerce_fidelity: non-numeric/NaN judge score -> 0.0/MISSED, never crash,
never a spurious pass.
- _as_bool: strict truthy parse; judge string 'false' no longer scores
EXCEEDED (bool('false')==True trap = silent false-success).
+3 regression tests (18 pass). Adversarial-class findings (forgery, replay
mutation, masked verifiers, untrusted-evidence) recorded to hardening backlog
as non-blocking per the dev-grade review bar.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VPortjb8U5oteKxppGuVDQ
What — "the intent is A or better", with percentile
Adds a post-execution intent-fidelity gate. Today
summary.statusis decidedpurely by task counts: every task
done→complete. But a plan can decompose agoal into tasks that all pass while drifting from the real intent, so "all tasks
done" masquerades as "achieved your goal". This gate closes that gap.
For each run it judges whether the OUTCOME achieved the user's original intent and
scores it as a 0-100 percentile with a letter grade and a verdict against a
configurable "A" bar (
JUSTAI_INTENT_BAR, default 90):met— fidelity ≥ bar (the intended outcome "A" was achieved)exceeded— genuinely better than the intent ("or better")missed— fell shortHonest downgrade (the point)
A task-complete run judged to have missed the intent is downgraded
complete → partial. The gate only downgrades — it never upgrades a partialrun, so a real task failure is never hidden. Honesty over performance, both ways.
Design / safety
justai/intent_fidelity.py—score_fidelity(): primary LiteLLM judge, with adeterministic completion-based heuristic fallback that is honest about its
own limits (no LLM → it does NOT fabricate a confident "missed" from fuzzy
tokens; it scores from completion and marks
source="heuristic").run (
try/exceptin the orchestrator stage).JUSTAI_FIDELITY_GATE(default on) restores prior task-count-onlysemantics when off.
prior behavior. The only behavior change is when a live judge flags a
task-complete run as intent-missed — exactly the intended honesty win.
Tests
12 new (
tests/test_intent_fidelity.py): percentile→grade mapping, heuristicfallback, mocked LLM judge (missed/met/exceeded), fallback-on-error, and the
synthesizer downgrade integration. Full suite: 407 passed, +12 new, 0 new
failures (7 failures on this branch are pre-existing README-drift and a local
backend-unavailable E2E smoke — verified identical on clean HEAD with this work
stashed).
⚠ Behavior-semantics note for Justin
This changes when a run reports "complete". You approved building it ("A or
better, good idea. With percentile."). Flagging it here per the git-ops rubric so
the semantics change is explicit; squash-merge target is
demo-build.