fix: failed-run exit codes, hung pods, and Dockerfile Python skew #5
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/reliability-defects"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes the three top defects found in the architecture review of
docs/arc42-architecture.mdagainst the code. One commit per defect.1. Failed runs exited 0 — failures were invisible to Kubernetes (
7902312)main.pycaught every exception (invalid token, channel not found), logged it, and returned0. WithrestartPolicy: Neverthe CronJob marked every run successful, so nothing could alert on failure. Ironically the only non-zero exit path was a Pushgateway outage, becausemetrics.push()sat outside the try block.WaifuBotnow tracks asuccessflag, set when a post completesmain()returns1on failure and logs tracebacks (exc_info=True)2. Exceptions escaping
on_readyhung the pod forever (7e201e9)client.close()was not in afinally, so any exception escapingtaskrun()skipped it. discord.py's defaulton_errorswallows event exceptions, soclient.start()never returned and the pod hung — and the CronJob had noactiveDeadlineSeconds/concurrencyPolicy, so stuck pods accumulated while new runs kept firing. Realistic escape paths:KeyErroringet_img_url()on an API shape change,KeyError/JSON errors inget_tags()(onlyTaggerErrorwas caught), andaiohttp.ClientErroron connection failures.on_readycloses the client infinallyimage_api/taggerconvert connection errors, timeouts, and unexpected response shapes into their typed errors, so they hit the existing retry / graceful-degradation paths instead of escapingconcurrencyPolicy: Forbid+activeDeadlineSeconds: 3003. Dockerfile build/runtime Python version skew (
f6616e0)Dependencies were built on
python:3.14-slimbut copied into distrolesspython3-debian13, which ships Python 3.13 — cp314-compiled C extensions (aiohttp and friends) grafted onto a 3.13 interpreter. Builder pinned topython:3.13-slim; site-packages path andPYTHONPATHupdated to match.Verification
mypy .cleanblack --checkclean for all changed lines (pre-existing violation onwaifu/discord_bot.py:119left untouched — it exists onmain; CI'sblack .without--checknever catches it, see honorable-mention CI defect)ImageApiError/TaggerError(6/6 pass); both API response shapes (url,items[0].url) still parsebot run failedand exits1(was0)concurrencyPolicy: ForbidandactiveDeadlineSeconds: 300present