fix(projekt-matching): final-review fixes — safe redeploy, poison-mail hardening, plan deviations note

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
tlg
2026-07-09 17:15:39 +02:00
parent 1863ce087c
commit 9ca7767208
6 changed files with 154 additions and 73 deletions

View File

@@ -26,42 +26,46 @@ done
# Langflow runs as uid 1000 gid 0 -> needs group read
chmod -R g+rX "$DEST/projektmatch" "$DEST/vorgaben"
# Make /app/langflow importable as a Python path root inside the container.
# The component files (Task 9) do `sys.path.insert(0, "/app/langflow")` as
# a *runtime* statement, but Langflow 1.10's custom-component loader
# (lfx/custom/validate.py: prepare_global_scope/create_class) statically
# scans the module's top-level `import`/`from ... import` AST nodes and
# resolves them via importlib BEFORE executing any other code -- an `if:`
# block containing the sys.path hack is a plain ast.If node, which that
# loader silently drops without ever executing it. So "import projektmatch"
# 404s both at design time (POST /custom_component, used by build_flows.py)
# and at real flow-run time, regardless of the in-file sys.path trick,
# unless /app/langflow is already on sys.path when the interpreter starts.
# Fix: drop a .pth file into the venv's site-packages (only takes effect
# for *new* Python processes, so the running langflow server needs a
# restart to pick it up -- the venv itself lives in the container's
# ephemeral overlay, not the bind-mounted data dir, so this must be
# redone after any container recreation).
# /app/langflow is already on sys.path inside the container: create_pod_langflow.sh
# runs the langflow container with `-e PYTHONPATH=/app/langflow` baked into the
# `podman run` invocation itself (see the comment block above that env var in
# create_pod_langflow.sh), so "import projektmatch" resolves from the very first
# boot without any venv-local .pth file. Do NOT reintroduce a .pth here: this
# container's systemd unit is generated with `podman generate systemd --new`
# (--rm + --replace in ExecStart), so the venv's site-packages lives in the
# container's ephemeral overlay and is wiped on every recreation anyway.
#
# The freshly copied code still needs a running-process restart to take effect
# (Python doesn't hot-reload modules), so restart via the systemd user unit --
# never a bare `podman restart`: since the unit is `--new`-managed, a bare
# `podman restart` on a container systemd also manages can leave systemd's
# view of the unit out of sync with the container's actual state (documented
# pitfall: the unit can end up believing the container is REMOVED). Restarting
# through systemd keeps systemd and podman in agreement.
CTR="langflow_ctr"
SVC="container-langflow_ctr.service"
if podman inspect "$CTR" >/dev/null 2>&1; then
SITE_PKGS="$(podman exec "$CTR" python -c 'import site; print(site.getsitepackages()[0])')"
PTH_FILE="$SITE_PKGS/projektmatch.pth"
CURRENT="$(podman exec "$CTR" cat "$PTH_FILE" 2>/dev/null || true)"
if [ "$CURRENT" != "/app/langflow" ]; then
echo "Registering /app/langflow on container sys.path (restart required)..."
podman exec "$CTR" sh -c "echo /app/langflow > '$PTH_FILE'"
podman restart "$CTR" >/dev/null
echo "Restarting $CTR via $SVC to pick up new code..."
if systemctl --user restart "$SVC"; then
code=""
for i in $(seq 1 40); do
code=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8090/api/v1/auto_login || true)
code=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8090/health || true)
[ "$code" = "200" ] && break
sleep 3
done
if [ "$code" != "200" ]; then
echo "WARN: $CTR did not come back healthy after restart (last health code: $code)" >&2
echo "WARN: $CTR did not come back healthy within 120s after restart" \
"(last health code: ${code:-none}). Recover with:" \
"'systemctl --user restart $SVC && curl -fsS http://127.0.0.1:8090/health'" >&2
fi
else
echo "WARN: 'systemctl --user restart $SVC' failed - $CTR may not have" \
"picked up the new code. Recover with:" \
"'systemctl --user restart $SVC'" >&2
fi
else
echo "WARN: container $CTR not found - skipping sys.path fix" >&2
echo "WARN: container $CTR not found - skipping restart" \
"(recover with: 'systemctl --user start $SVC')" >&2
fi
echo "Deployed to $DEST"