fix(accent): degrade gracefully when OJAD is unavailable#60
Merged
Conversation
OJAD (www.gavo.t.u-tokyo.ac.jp) outages made /MarkAccent/ hang for the full global 10s timeout and then return HTTP 500, because get_ojad_result re-raised the transport error and the pipeline turned it into a 500. Pitch accent from OJAD only enriches the furigana result, so an OJAD outage should not fail the whole request: - ojad.py: add a short per-request timeout (connect=2s, read=5s) so a down OJAD fails fast instead of hanging on the global 10s, and raise a dedicated OJADUnavailableError on any httpx.HTTPError (connect/read timeouts, connection errors, non-2xx status). - pipeline.py: catch OJADUnavailableError and degrade to furigana-only output (align_accent already emits accent_marking_type=0 for an empty OJAD list) with status 200 and a warning, instead of 500. - models.py: add an optional, backward-compatible `warning` field to AccentResponse for degraded results. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Closed
🛡️ PR Quality Check Summary✅ PR Title: Passed (Length: 56/75, Format: OK). 🎉 All checks passed! |
wade00754
approved these changes
Jun 4, 2026
torrid-fish
added a commit
that referenced
this pull request
Jun 4, 2026
#60) # Conflicts: # api/accent/pipeline.py
torrid-fish
added a commit
that referenced
this pull request
Jun 4, 2026
The collected endpoint rebuilds AccentResponse from per-chunk results and silently dropped the new `warning` field (#60), so OJAD-degraded responses looked like full results. Keep the first chunk warning, mirroring the first_error convention. The stream endpoint already passes it through via model_dump(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
torrid-fish
added a commit
that referenced
this pull request
Jun 4, 2026
The collected endpoint rebuilds AccentResponse from per-chunk results and silently dropped the new `warning` field (#60), so OJAD-degraded responses looked like full results. Keep the first chunk warning, mirroring the first_error convention. The stream endpoint already passes it through via model_dump(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OJAD (
www.gavo.t.u-tokyo.ac.jp) is currently globally unreachable (80/443 TCP connect timing out, ping 100% loss — confirmed from an independent external egress, not an IP block). Because every accent chunk POSTs to OJAD for the per-mora pitch contour, an OJAD outage made/MarkAccent/:main.pyhttpx.AsyncClient(timeout=10.0)).httpx.ConnectTimeoutfromget_ojad_result(except Exception: raise).So users waited ~10s only to get a 500. Prod logs showed ~1898
ConnectTimeout/ 1387[OJAD] Request Failedin 24h.Fix
Pitch accent from OJAD only enriches the furigana result, so an OJAD outage should degrade — not fail — the request.
api/accent/ojad.py— Add a short per-request timeoutOJAD_TIMEOUT = httpx.Timeout(5.0, connect=2.0)so a down OJAD fails fast (~2s) instead of hanging on the global 10s. Replaceexcept Exception: raisewithexcept httpx.HTTPError(covers connect/read timeouts, connection errors, andraise_for_status()'s status errors) → log a warning and raise a dedicatedOJADUnavailableError.api/accent/pipeline.py— CatchOJADUnavailableError, setojad_results = []plus a warning, and continue.align_accentalready emitsaccent_marking_type=0for an empty OJAD list (its "MATCH FAILED" branch), so this yields furigana-only output at status 200. The broadexcept → 500stays as a last-resort guard.api/accent/models.py— Add an optional, backward-compatiblewarningfield toAccentResponsefor degraded results.Verification
uv run ruff check api/accent/anduv run mypy api/accent/— both clean.ConnectTimeout):get_ojad_resultraisesOJADUnavailableError, the short timeout is passed through, and the pipeline returnsstatus=200, warning set, allaccent_marking_type==0, furigana preserved. No 500, no 10s hang.status=200,warning=null, real pitch contour preserved — no regression.Close #59