Skip to content

feat: derive corrective turns from session judge - #401

Merged
yyiilluu merged 3 commits into
mainfrom
codex/judge-derived-corrections
Jul 30, 2026
Merged

feat: derive corrective turns from session judge#401
yyiilluu merged 3 commits into
mainfrom
codex/judge-derived-corrections

Conversation

@yyiilluu

@yyiilluu yyiilluu commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Make corrective user turns an independent output of the session-level agent-success judge instead of deriving them from user-playbook rows.
  • Keep corrective-turn counting independent from final task success and distinguish revisions from new questions or deliverables.
  • Preserve the existing public result field and historical storage schema while making regeneration safe for both SQLite inserts and enterprise in-place upserts.

Changes

Evaluation contract

  • Require a strict, non-negative number_of_correction_per_session in the structured judge response.
  • Add and activate agent-success prompt v1.1.0 with the corrective-turn rubric; deactivate v1.0.0.
  • Copy the judge value directly into AgentSuccessEvaluationResult and remove playbook-count lookup/fallback behavior.

Persistence and regeneration

  • Reconcile prior result IDs after a successful save: delete prior SQLite rows only when a fresh ID was inserted, while preserving enterprise rows updated in place.
  • Keep failed or empty regeneration attempts from deleting prior results.

Schemas and tests

  • Document the existing result field as a judge-derived corrective-user-turn count.
  • Update deterministic LLM fixtures, snapshots, and prompt-version guards.
  • Add structured-output, prompt-rubric, evaluator, and regeneration coverage for required/non-negative counts and insert/upsert storage semantics.

Test Plan

  • uv run ruff check on all changed Python files
  • uv run pyright on all changed Python files
  • uv run pytest -q --no-cov tests/server/services/agent_success_evaluation/test_agent_success_evaluator.py tests/server/services/agent_success_evaluation/test_agent_success_evaluation_utils.py tests/server/services/agent_success_evaluation/test_group_evaluation_runner_regen.py tests/server/services/test_prompt_model_mapping.py
  • Result after CodeRabbit follow-up: 89 passed, 2 skipped

Follow-ups

  • Addressed every actionable CodeRabbit review item in cd549b5a: valid JSON output examples, nested agent-success config lookup during regeneration, and corrected runner step numbering.
  • Added regression coverage that parses both rendered JSON examples and verifies regeneration uses the evaluator's singleton identity.
  • Merge order: merge this OSS PR before the companion enterprise gitlink update.

Summary by CodeRabbit

  • New Features

    • Introduced an updated agent success evaluation that measures corrective user turns across the full session.
    • Added clearer failure classification and escalation assessment.
    • Added validation to ensure correction counts are non-negative integers.
  • Bug Fixes

    • Regenerated evaluations now preserve results correctly across different storage behaviors.
    • Correction counts now reflect evaluation results rather than stored playbook counts.

Count corrective user turns in the agent-success structured output, persist the judge value across evaluation flows, and preserve regenerated results for both insert- and upsert-style storage backends.
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 29 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0a6838de-7a15-4d14-817d-42e1bc90a390

📥 Commits

Reviewing files that changed from the base of the PR and between cd549b5 and ffdf1d9.

📒 Files selected for processing (1)
  • reflexio/server/prompt/prompt_bank/agent_success_evaluation/v1.1.0.prompt.md
📝 Walkthrough

Walkthrough

Agent-success evaluation now uses prompt v1.1.0 to produce validated corrective-turn counts, propagates those counts from LLM output, and reconciles regenerated evaluation rows for both insert and in-place upsert storage.

Changes

Agent success evaluation

Layer / File(s) Summary
Evaluation contract and prompt
reflexio/models/api_schema/..., reflexio/server/prompt/..., reflexio/server/services/agent_success_evaluation/agent_success_evaluation_constants.py, reflexio/test_support/..., tests/fixtures/..., tests/server/services/__snapshots__/..., tests/server/services/test_prompt_model_mapping.py
Correction-count fields now enforce non-negative values, prompt v1.1.0 defines correction-count evaluation, and mock and fixture expectations use the new output shape.
Judge-derived correction propagation
reflexio/server/services/agent_success_evaluation/components/evaluator.py, tests/server/services/agent_success_evaluation/test_agent_success_evaluator.py, tests/server/services/agent_success_evaluation/test_agent_success_evaluation_utils.py
The evaluator copies the validated LLM correction count directly and no longer queries playbook storage; tests cover validation, propagation, and prompt rendering.
Regeneration result reconciliation
reflexio/server/services/agent_success_evaluation/runner.py, tests/server/services/agent_success_evaluation/test_group_evaluation_runner_regen.py
Regeneration deletes prior IDs only when new rows are inserted and preserves rows updated in place, with tests for both storage behaviors.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PromptV110
  participant AgentSuccessEvaluator
  participant EvaluationStorage
  PromptV110->>AgentSuccessEvaluator: returns corrective-turn count
  AgentSuccessEvaluator->>EvaluationStorage: saves evaluation result
  AgentSuccessEvaluator->>EvaluationStorage: reconciles prior and post-save result IDs
Loading

Possibly related PRs

  • ReflexioAI/reflexio#101: Both changes derive the agent-success evaluation name from the singular agent-success configuration.
  • ReflexioAI/reflexio#212: Both changes modify agent-success result identity scoping during regeneration cleanup.
  • ReflexioAI/reflexio#329: Both changes modify agent-success regeneration behavior in run_group_evaluation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: correction counts now come from the session judge instead of storage-derived counts.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/judge-derived-corrections

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
reflexio/server/services/agent_success_evaluation/runner.py (1)

314-318: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Inline step numbering drifted from the docstring.

The docstring (Lines 115-119) labels the delete/reconcile logic as step 7 (step 6 = "Run evaluation service"), but this comment still says # 6..

✏️ Fix
-    # 6. New rows saved successfully. Delete captured prior rows only when the
+    # 7. New rows saved successfully. Delete captured prior rows only when the
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@reflexio/server/services/agent_success_evaluation/runner.py` around lines 314
- 318, Correct the inline step number above the old-result deletion logic
guarded by old_result_ids from step 6 to step 7, matching the surrounding
function docstring. Leave the deletion and reconciliation behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@reflexio/server/prompt/prompt_bank/agent_success_evaluation/v1.1.0.prompt.md`:
- Around line 90-93: Update the failure example in the agent success evaluation
prompt so the failure_type field contains one concrete valid enum value, such as
"missing_tool", instead of an inline “or” expression; describe the other allowed
values in prose while preserving the remaining JSON structure.

In `@reflexio/server/services/agent_success_evaluation/runner.py`:
- Around line 254-268: Update the force_regenerate setup in the evaluation
runner to derive evaluation_name from root_config.agent_success_config, using
the nested AgentSuccessConfig singleton expected by the evaluator. Keep the
existing prior-result ID lookup unchanged so regeneration cleanup targets the
same rows written by the agent-success evaluator.

---

Nitpick comments:
In `@reflexio/server/services/agent_success_evaluation/runner.py`:
- Around line 314-318: Correct the inline step number above the old-result
deletion logic guarded by old_result_ids from step 6 to step 7, matching the
surrounding function docstring. Leave the deletion and reconciliation behavior
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e83cc40f-8937-480f-b393-ee710b6ebb8a

📥 Commits

Reviewing files that changed from the base of the PR and between f81117c and 75958ee.

📒 Files selected for processing (15)
  • reflexio/models/api_schema/domain/entities.py
  • reflexio/models/api_schema/eval_overview_schema.py
  • reflexio/models/api_schema/ui/entities.py
  • reflexio/server/prompt/prompt_bank/agent_success_evaluation/v1.0.0.prompt.md
  • reflexio/server/prompt/prompt_bank/agent_success_evaluation/v1.1.0.prompt.md
  • reflexio/server/services/agent_success_evaluation/agent_success_evaluation_constants.py
  • reflexio/server/services/agent_success_evaluation/components/evaluator.py
  • reflexio/server/services/agent_success_evaluation/runner.py
  • reflexio/test_support/llm_model_registry.py
  • tests/fixtures/llm/agent_success_evaluation.json
  • tests/server/services/__snapshots__/test_llm_mock_schema_compliance/TestMockResponseSnapshots.test_recorded_fixture_content[agent_success_evaluation].json
  • tests/server/services/agent_success_evaluation/test_agent_success_evaluation_utils.py
  • tests/server/services/agent_success_evaluation/test_agent_success_evaluator.py
  • tests/server/services/agent_success_evaluation/test_group_evaluation_runner_regen.py
  • tests/server/services/test_prompt_model_mapping.py

Comment thread reflexio/server/services/agent_success_evaluation/runner.py
Use the agent-success singleton config during regeneration cleanup and keep prompt output examples valid JSON. Add focused regressions for both contracts.
@yyiilluu

Copy link
Copy Markdown
Contributor Author

CodeRabbit follow-up: fixed both inline findings and the review-body step-numbering nitpick in cd549b5. The focused suite passes (89 passed, 2 skipped), with clean Ruff, formatting, and Pyright checks.

@yyiilluu
yyiilluu merged commit 6ba9e6d into main Jul 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant