← Back to Pull requests

refactor: apply response history at turn acceptance #676

Merged
jackboyla merged 26 files (1256 lines) on Oct 09, 2026 21:40 UTC
View on GitHub
jackboyla jackboyla commented on Oct 08, 2026 07:12 UTC
Author

Model workers and the Realtime service currently make separate decisions about response relevance. A worker can write shared conversation history before the service drops its output. This change gives output and history the same acceptance decision.

  • Workers read deep snapshots and emit cumulative ResponseHistory proposals. The service-owned HistoryHandler writes accepted proposals and rolls back unfinished responses.

  • Tool history lands before client-visible calls, and duplicate side-channel/ordered delivery writes only the new suffix. Prefetched history stays private until the client claims it.

  • Before reading the next request, the model worker waits for the service to write or reject the previous terminal proposal. Logical completion supplies that decision without waiting for TTS; cancellation and shutdown release the wait.

  • Direct-audio input becomes permanent only after history cleanup succeeds, so a cleanup failure rolls back the whole proposed turn.
  • The change removes model-side rollback closures and Chat's cancellation tombstones. Existing tests use a small helper to apply proposals through the real history handler. Three added regression cases cover audio cleanup failure, successful audio-input retention after cancellation, and queued-worker history ordering. Both bugs reproduce on the original PR head.

    Validation: 2,406 Python tests passed, four skipped; all 33 Agents SDK checks passed; Ruff lint/format and mypy passed (129 source files).

    Closes #308.

    Diff: 1256 lines (+815 / -441) across 26 files Reviewer: andimarafioti Review duration: 2308m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.72) × (1 − Review Confidence (0.68)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.72 · 1256 lines diff across 26 files
    0.72
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.35 · 1 substantive comment(s)
    0.35
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    67%
    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.400
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    2 items
    andimarafioti andimarafioti approved these changes on Oct 09, 2026 21:38 UTC
    Approved Reviewer

    Great work! can't believe this closes #308 ! That's one chunky issue you took care of, huge kudos!

    <img src="https://static.klipy.com/ii/c3a19a0b747a76e98651f2b9a3cca5ff/be/4e/SyKoD7kT.gif"/>

    Reviewers
    Assignees
    jackboyla jackboyla
    Labels
    risk: low confidence: 67.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: 71.5% (HIGH) · Higher = larger blast radius
    71.5%
    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: 67.5% · Lower = rushed or shallow review
    67.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: 23.2% · Safe to merge
    23.2%