[fix] solution/backend: 카톡 5초 벽을 콜백으로 넘는다
실사용 첫날 "시설 편의에서 바비큐 이용 문구 빼줘" 가 타임아웃으로 끝났다.
★ 작은 표본으로 잰 수치를 상한 근거로 삼은 것이 틀렸다. 개발 중 잰 1.3~2.4초는
업종 필드 두 개짜리 장난감 프롬프트였고, 진짜 요청에는 필드 43개 + fact 수십 개가
실린다. "여유가 있다" 고 적어 둔 판단이 하루 만에 깨졌다.
- userRequest.callbackUrl 이 오면 {"useCallback": true} 로 즉답하고 백그라운드에서
답을 만든 뒤 그 주소로 POST. 콜백 주소는 1분·1회라 재시도하지 않는다 —
두 번째 POST 는 거절되고 사장님에게는 이미 "확인하고 있어요" 가 가 있다
- 콜백이 꺼져 있으면 예전처럼 동기, 상한만 4.0 → 4.5 (카카오가 5초에 끊는다)
★ 오픈빌더 스킬 설정에서 '콜백 사용' 을 켜야 열린다. 안 켜면 callbackUrl 이 안 와서
조용히 예전 경로로만 돈다.
test_kakao_webhook.py 24 passed(콜백 3건 추가)
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
1300652b09
commit
f500210cd8
4 files changed
+157
-26
No files matched your search
@@ -318,3 +318,55 @@ async def test_목록은_발행_여부를_같이_말한다(client, auth_headers,
|
||||
await link(db_engine, client, auth_headers, speaker, "미발행가게")
|
||||
res = await client.post(PATH, headers={"X-Agent-Secret": SECRET}, json=body("목록", speaker))
|
||||
assert "아직 발행 전" in said(res)
|
||||
|
||||
|
||||
# ── 콜백 (5초 벽 넘기) ───────────────────────────────────────────────────
|
||||
|
||||
async def test_콜백이_켜져_있으면_즉답하고_뒤에서_마저_만든다(client, auth_headers, db_engine, monkeypatch):
|
||||
"""★ 오픈빌더 스킬 타임아웃은 5초다. 콜백을 쓰면 '잠시만 기다려 주세요' 를 먼저 주고
|
||||
답이 완성되면 그 주소로 따로 보낸다 — 느린 답이 침묵이 되지 않는다."""
|
||||
import router.v1.agent.kakao_bot as bot
|
||||
|
||||
sent = {}
|
||||
|
||||
async def fake_push(callback_url, utterance, speaker):
|
||||
sent["url"] = callback_url
|
||||
sent["payload"] = await bot._answer(utterance, speaker, 5.0)
|
||||
|
||||
monkeypatch.setattr(bot, "_push", fake_push)
|
||||
|
||||
payload = body("안녕", "콜백-발화자")
|
||||
payload["userRequest"]["callbackUrl"] = "https://callback.example/one-shot"
|
||||
res = await client.post(PATH, headers={"X-Agent-Secret": SECRET}, json=payload)
|
||||
|
||||
# 즉답은 useCallback 이다 — template 을 싣지 않는다.
|
||||
assert res.json()["useCallback"] is True
|
||||
assert res.json()["data"]["text"]
|
||||
assert "template" not in res.json()
|
||||
|
||||
# 실제 답은 콜백으로 간다.
|
||||
assert sent["url"] == "https://callback.example/one-shot"
|
||||
assert "연결" in sent["payload"]["template"]["outputs"][0]["simpleText"]["text"]
|
||||
|
||||
|
||||
async def test_콜백이_없으면_예전처럼_동기로_답한다(client, db_engine):
|
||||
res = await client.post(PATH, headers={"X-Agent-Secret": SECRET}, json=body("안녕", "동기-발화자"))
|
||||
assert "useCallback" not in res.json()
|
||||
assert res.json()["template"]["outputs"]
|
||||
|
||||
|
||||
async def test_콜백_전송이_실패해도_터지지_않는다(monkeypatch):
|
||||
"""★ 주소는 1분 · 1회다. 재시도하지 않는다 — 두 번째 POST 는 어차피 거절된다."""
|
||||
import router.v1.agent.kakao_bot as bot
|
||||
|
||||
monkeypatch.setattr(bot, "_answer", AsyncMock(return_value=bot._reply("답")))
|
||||
|
||||
class Boom:
|
||||
async def __aenter__(self):
|
||||
raise RuntimeError("네트워크 끊김")
|
||||
|
||||
async def __aexit__(self, *_):
|
||||
return False
|
||||
|
||||
monkeypatch.setattr(bot.httpx, "AsyncClient", lambda **_kw: Boom())
|
||||
await bot._push("https://callback.example/x", "안녕", "누구") # 예외가 새 나오지 않는다
|
||||
Reference in new issue
Block a user