From e6921b4591ad98f3fc3efa45afec916967a6d8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 15 Sep 2026 21:08:10 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=94=8C=20echo=20the=20request=20sc?= =?UTF-8?q?hool=20so=20hab/2=20frames=20validate=20-=20hab/2=20Request=20c?= =?UTF-8?q?arries=20a=20required=20school=20field=20and=20Response=20must?= =?UTF-8?q?=20echo=20it;=20=20=20without=20it=20the=20backend=20fails=20ev?= =?UTF-8?q?ery=20message=20with=20error=5Fcode=3Dprotocol=20even=20=20=20t?= =?UTF-8?q?hough=20the=20registration=20handshake=20succeeded=20-=20the=20?= =?UTF-8?q?school=20rides=20through=20to=20every=20Response=20branch=20(ok?= =?UTF-8?q?,=20capability=20error,=20=20=20timeout,=20internal)=20so=20a?= =?UTF-8?q?=20refusal=20is=20attributed=20to=20the=20right=20school=20too?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bridge.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/bridge.py b/src/bridge.py index f5a8d68..36931e5 100644 --- a/src/bridge.py +++ b/src/bridge.py @@ -16,7 +16,9 @@ Akış (bkz. backend ``src/ai/mod.rs`` ve ``server.rs``): yaz, bir ``Greeting`` oku, akışı hayat boyu açık tut (kapanması = kayıttan düşme sinyali). 4. Her istek backend'in açtığı *server-initiated* çift yönlü bir akıştır: tek - ``Request`` gelir, motoru çalıştırıp tek ``Response`` yazarız. + ``Request`` gelir, motoru çalıştırıp tek ``Response`` yazarız. hab/2'de + ``Request.school`` zorunludur ve ``Response`` onu yankılar; ikisi de eksikse + backend çerçeveyi reddeder. Çerçeveleme: 4 bayt big-endian uzunluk + o kadar bayt JSON. @@ -201,21 +203,28 @@ class BridgeProtocol(QuicConnectionProtocol): return req_id = request.get("id", "") + # hab/2: her istek kendi OKULUNU adıyla taşır ve cevap onu yankılar. + # Bu alan eksikse backend çerçeveyi reddeder (mesaj error_code=protocol + # ile düşer) — sürüm dizesi tek başına yetmez. + school = request.get("school", "") capability = request.get("capability", "") payload = request.get("payload") or {} deadline_ms = request.get("deadline_ms") try: timeout = (deadline_ms / 1000.0) if isinstance(deadline_ms, (int, float)) else None text = await asyncio.wait_for(self._reply(capability, payload), timeout=timeout) - response: dict[str, Any] = {"status": "ok", "id": req_id, "payload": {"text": text}} + response: dict[str, Any] = { + "status": "ok", "id": req_id, "school": school, "payload": {"text": text}, + } except CapabilityError as exc: - response = {"status": "err", "id": req_id, "code": exc.code, "message": str(exc)} + response = {"status": "err", "id": req_id, "school": school, + "code": exc.code, "message": str(exc)} except asyncio.TimeoutError: - response = {"status": "err", "id": req_id, "code": "timed_out", + response = {"status": "err", "id": req_id, "school": school, "code": "timed_out", "message": "motor süre içinde cevap veremedi"} except Exception as exc: # pragma: no cover - beklenmeyen print(f"[bridge] istek {req_id} işlenemedi: {exc}", flush=True) - response = {"status": "err", "id": req_id, "code": "internal", + response = {"status": "err", "id": req_id, "school": school, "code": "internal", "message": "beklenmeyen hata"} try: