GET /v1/feedback — status. POST /v1/feedback — submit signal or rollback.
(request: Request)
| 3668 | return JSONResponse(artifact) |
| 3669 | |
| 3670 | async def handle_feedback(request: Request) -> JSONResponse: |
| 3671 | """GET /v1/feedback — status. POST /v1/feedback — submit signal or rollback.""" |
| 3672 | if request.method == "GET": |
| 3673 | return JSONResponse({ |
| 3674 | **_feedback.status(), |
| 3675 | "route_confidence_calibration": _route_confidence.status(), |
| 3676 | }) |
| 3677 | body = await request.json() |
| 3678 | action = body.get("action") |
| 3679 | if action == "rollback": |
| 3680 | denied = _admin_auth_failure(request) |
| 3681 | if denied is not None: |
| 3682 | return denied |
| 3683 | rolled = _feedback.rollback() |
| 3684 | return JSONResponse({ |
| 3685 | "ok": True, |
| 3686 | "rolled_back": rolled, |
| 3687 | "route_confidence_calibration": _route_confidence.status(), |
| 3688 | }) |
| 3689 | request_id = body.get("request_id", "") |
| 3690 | signal = body.get("signal", "") |
| 3691 | if not request_id or signal not in ("weak", "strong", "ok"): |
| 3692 | return JSONResponse( |
| 3693 | {"error": "Requires request_id and signal (weak|strong|ok)"}, |
| 3694 | status_code=400, |
| 3695 | ) |
| 3696 | result = _feedback.submit(request_id, signal) |
| 3697 | if result.action != "expired": |
| 3698 | _stats.record_feedback( |
| 3699 | request_id, |
| 3700 | signal=signal, |
| 3701 | ok=result.ok, |
| 3702 | action=result.action, |
| 3703 | from_tier=result.from_tier, |
| 3704 | to_tier=result.to_tier, |
| 3705 | reason=result.reason, |
| 3706 | ) |
| 3707 | get_bus().publish({ |
| 3708 | "type": "feedback_updated", |
| 3709 | "request_id": request_id, |
| 3710 | "feedback_signal": signal, |
| 3711 | "feedback_ok": result.ok, |
| 3712 | "feedback_action": result.action, |
| 3713 | "feedback_from_tier": result.from_tier, |
| 3714 | "feedback_to_tier": result.to_tier, |
| 3715 | "feedback_reason": result.reason, |
| 3716 | "feedback_submitted_at": time.time(), |
| 3717 | }) |
| 3718 | _traces.record_feedback( |
| 3719 | request_id, |
| 3720 | signal=signal, |
| 3721 | ok=result.ok, |
| 3722 | action=result.action, |
| 3723 | from_tier=result.from_tier, |
| 3724 | to_tier=result.to_tier, |
| 3725 | reason=result.reason, |
| 3726 | ) |
| 3727 | _route_confidence.fit_from_route_records(_stats.history()) |
nothing calls this directly
no test coverage detected