← Back to Pull requests

fix(core): withhold the next hint on confirm gate previews #296

Closed
unknown closed this pull request without merging on Oct 02, 2026 18:38 UTC
View on GitHub
unknown unknown commented on Sep 30, 2026 10:39 UTC
Author

Description

Confirm gate previews no longer carry the _meta.next hint. That hint describes the step after an action has run, and a preview has not run anything.

What was wrong

With confirmed=False, every mutating tool correctly returns a preview and sends nothing to the cluster. _inject_meta then attached the hint from TOOL_NEXT_HINTS anyway:

| tool | _meta.next on the preview (before) |
|---|---|
| fine_tune, run_custom_training, run_container_training | Monitor with get_training_job(name) and get_training_logs(name) |
| delete_training_job | Resubmit with fine_tune() or run_custom_training() if needed |
| update_training_job | Check get_training_job(name) to verify new status |
| create_runtime | Verify with list_runtimes() or get_runtime(name) |
| patch_runtime | Verify changes with get_runtime(name) |
| delete_runtime | Confirm removal with list_runtimes() |

For clients that rely on _meta instead of the server instructions, this is the main guidance after a preview. It points them at a job that does not exist, or at a delete that has not happened. Full details and a repro are in #295.

Why withhold rather than replace

I considered swapping the hint for "call again with confirmed=True" and left it out on purpose. The confirm gate is there so a person approves the action, and a hint that points straight at the confirm call makes that step easier to skip. The preview message already says Set confirmed=True to proceed. This also matches how #237 handled blocked pre_flight results: withhold next, keep phase.

What changes

1. _is_preview() in kubeflow_mcp/core/server.py recognises both preview shapes:
- PreviewResponse: status="preview" at the top level
- the legacy runtime shape that docs/CONVENTIONS.md lists as an exception: ToolResponse with data.action="preview"
2. _inject_meta withholds next when _is_blocked(result) or _is_preview(result). phase is unchanged.

Only the envelope status counts, so a job whose own status sits in data is not mistaken for a preview. Executed update_training_job responses carry data.action="suspend" or "resume", never "preview", so they keep their hint.

No tool schema, parameter or response shape changes. The only visible difference is that _meta on a preview is {"phase": ...} without next.

Related Issue

Fixes #295

Checklist

  • I have read the [CONTRIBUTING](../CONTRIBUTING.md) guide

  • Tests pass locally (make test-python)

  • Linting passes (make verify)

  • Documentation updated (if applicable)

  • My commits are signed off (git commit -s)
  • Testing

  • Unit tests

  • Integration tests

  • E2E tests

  • Manually tested (describe below)
  • New tests (TestInjectMetaPreviewResponses in server_test.py)

    | test | checks |
    |---|---|
    | test_every_mutating_tool_has_a_post_action_hint | all 8 tools really have a hint that could leak (guards the premise) |
    | test_next_withheld_for_preview_response | no next on a PreviewResponse, for all 8 tools |
    | test_next_withheld_for_legacy_runtime_preview | no next on the runtime tools' data.action="preview" shape |
    | test_phase_preserved_for_preview | phase is still there |
    | test_next_present_after_confirmed_submission | a real submission keeps its hint |
    | test_next_present_after_confirmed_update | executed update_training_job (data.action="suspend") keeps its hint |
    | test_job_status_in_data_is_not_a_preview | data.status="preview" from a job does not trigger the guard |
    | test_preview_over_mcp_has_no_next_hint | end to end through an MCP client: patch_runtime preview returns _meta == {"phase": "platform"} |

    The responses are built from the real PreviewResponse and ToolResponse models rather than hand written dicts, so a change to either model shows up here.

    The tests fail without the fix

    With server.py reverted to main, the three tests that check the fix fail and the four guard tests still pass:

    FAILED ...::test_next_withheld_for_preview_response
    FAILED ...::test_next_withheld_for_legacy_runtime_preview
    FAILED ...::test_preview_over_mcp_has_no_next_hint
    3 failed, 20 passed
    

    The tests catch a wrong fix

    I broke the new guard three ways and checked that a test fails each time:

    | break | caught by |
    |---|---|
    | status="preview" branch removed | test_next_withheld_for_preview_response |
    | legacy data.action branch removed | test_next_withheld_for_legacy_runtime_preview, test_preview_over_mcp_has_no_next_hint |
    | any data.action treated as a preview | test_next_present_after_confirmed_update |

    All 8 tools over MCP

    I also ran every mutating tool through an in-memory MCP client with the Kubernetes API faked at ApiClient.call_api, calling each with confirmed=False:

                            before (main)                                   after
    fine_tune               next: Monitor with get_training_job(name) ...   next: None
    run_custom_training     next: Monitor with get_training_job(name) ...   next: None
    run_container_training  next: Monitor with get_training_job(name) ...   next: None
    delete_training_job     next: Resubmit with fine_tune() ...             next: None
    update_training_job     next: Check get_training_job(name) ...          next: None
    create_runtime          next: Verify with list_runtimes() ...           next: None
    patch_runtime           next: Verify changes with get_runtime(name)     next: None
    delete_runtime          next: Confirm removal with list_runtimes()      next: None
    write requests sent: []
    

    Full suite

  • 719 passed, 8 skipped on three consecutive runs

  • uv lock --check, ruff check and ruff format --check clean, 84 files formatted

  • Tool schema snapshot unchanged
  • The two resilience tests fixed in #290 were deselected for these runs, since on Windows they fail intermittently on main for an unrelated reason. They do not touch this code.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: abhijeet-dhumal Review duration: 3359m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #296"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%