Skip to content

Fix hook crashing on every call under the host's Python 3.9 - #9

Merged
agb1986 merged 1 commit into
mainfrom
fix-hook-python-compat
Aug 8, 2026
Merged

agb1986 merged 1 commit into
mainfrom
fix-hook-python-compat

Conversation

@agb1986

@agb1986 agb1986 commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary

Diagnosed via a handoff from a prior debugging session on the CasaOS host: no data was reaching Mongo/:8743 despite the hook being installed and finance-agent producing artifacts. Two independent bugs, this PR fixes the first.

  • log_artifact_entry.py uses PEP 604 union syntax (str | None, dict | None) in three signatures (render, find_project_root, build_entry). This requires Python 3.10+ to evaluate at def time. The Docker image is unaffected (python:3.12-slim), but the hook runs directly on the host via ~/.claude/settings.json's PostToolUse (python3 ~/.claude/hooks/log_artifact_entry.py) — and the host's only python3 is 3.9.2. Result: TypeError on every single invocation, in every project, since install — silent, since hook stderr isn't surfaced anywhere visible.
  • Fix: from __future__ import annotations as the first import, deferring annotation evaluation to strings. No syntax rewrite, no host Python upgrade needed. Confirmed no other 3.10+ constructs exist in the file (only those three annotations use |; no match statements; all isinstance calls use plain builtin types).

A second, independent bug from the same handoff — finance-agent never had a .ai-data-store.json to opt in — is fixed separately in agb1986/finance-agent#13, since that config lives in finance-agent's own repo.

Test plan

  • ruff check . — clean
  • pytest — 57 passed
  • Confirmed by grep that the three flagged lines are the only PEP 604 usages in the file, and that no other constructs in it require Python ≥ 3.10 at runtime
  • Requires the CasaOS host to apply this — I have no access to that host from this session (this ran on the dev machine, not casaos). After merge, on the host:
    git pull
    cp hooks/log_artifact_entry.py ~/.claude/hooks/log_artifact_entry.py
    Then, once Opt in to the ai-data-store artifact-logging hook finance-agent#13 is also merged and pulled there, re-run the handoff's smoke test (artifact JSON → hook invocation → Mongo count increments → visible on :8743), and clean up the test doc/tmp file afterward.

🤖 Generated with Claude Code

log_artifact_entry.py uses PEP 604 union syntax (str | None, dict | None)
in three function signatures, which requires evaluating annotations at
def time on Python < 3.10. The Docker image is fine (python:3.12-slim),
but the hook itself runs directly on the host via PostToolUse, and the
CasaOS host's only python3 is 3.9.2 — so the hook has raised TypeError
on every single invocation, in every project, since it was installed.
Silent, because hook stderr isn't surfaced anywhere visible.

`from __future__ import annotations` defers annotation evaluation to
strings, which fixes all three signatures with no syntax rewrite and no
host Python upgrade needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@agb1986
agb1986 merged commit f7ccbaa into main Aug 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant