feat: MLflow tracing with async Stop hook (opt-in)#15
Open
Conversation
Enables opt-in MLflow tracing for Claude Code sessions. Key design:
- setup_mlflow.py registers a Stop hook when MLFLOW_CLAUDE_TRACING_ENABLED=true
- Hook delegates to mlflow-trace-stop.sh which backgrounds the handler via
`nohup timeout 30 ... & disown`, returning in <1s so the Stop chain
(brain-push, /til, etc.) is not blocked
- Handler receives hook-event JSON via a temp file captured synchronously
before backgrounding (naive nohup would redirect stdin to /dev/null)
- Hard 30s ceiling on the backgrounded flush to prevent stuck handlers
leaking memory/CPU across sessions
- Pins mlflow-skinny and mlflow-tracing to 3.11.1 to match the Apps
runtime image (version mismatch caused silent import failures)
Tracing is disabled by default — set MLFLOW_CLAUDE_TRACING_ENABLED=true
in app.yaml to opt in.
Tests: TestStopHook and TestSettingsMerge updated to match shell-script
delegation model; TestAppOwnerExport mocks app_state.set_app_owner
to avoid ~/.coda writes in unit test context.
Co-authored-by: Isaac
Collaborator
Author
|
@datasciencemonkey — flagging for review. P1: README claims auto-tracing works on every session; deployed code has the master flag hardcoded |
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.
Priority
P1 — silent feature failure. README claims "every Claude Code session is automatically traced — zero configuration required", but the deployed
setup_mlflow.pyhardcodesMLFLOW_CLAUDE_TRACING_ENABLED="false", which makes the upstream Stop hook short-circuit before any trace is written. No traces, no error, no breadcrumb. Every user thinks tracing works; nothing does. This PR introduces the opt-in env-var override so users who want it can flip it on.Summary
Migrates the work from datasciencemonkey PR #139 to the new repo home, rebased onto
databrickslabs/main.MLFLOW_CLAUDE_TRACING_ENABLED=trueinapp.yaml— keeps default behaviour unchanged for existing deployments, but gives users a single env-var to flip.mlflow-trace-stop.sh, which backgrounds the handler vianohup timeout 30 … & disown. Returns in <1s so the rest of the Stop hook chain isn't blocked.nohupwould redirect stdin to/dev/nulland the handler would lose the transcript path.mlflow-skinnyandmlflow-tracingto3.11.1to match the Apps runtime — version mismatches caused silent import failures.Why this matters
Issue #9 documents that today's
MLFLOW_CLAUDE_TRACING_ENABLED="false"insetup_mlflow.pycauses the upstream Stop hook to short-circuit before any trace is written. The README promises auto-tracing; the code delivers nothing. This PR introduces a real opt-in path so the experiment actually gets populated when a user wants it on.Test plan
uv run pytest tests/test_mlflow_tracing.py— should pass locallyMLFLOW_CLAUDE_TRACING_ENABLED=true, run a session, confirm trace appears at/Users/{owner}/{app_name}in MLflow~/.claude/settings.json(default-off behaviour preserved)Closes #9
Closes #11
This pull request and its description were written by Isaac.
Test Evidence (verified on the live deployment 2026-05-06)
Triple-confirmed the bug on a fresh databricks/main v0.18.1 deployment:
1. Settings on disk (read directly from the running container):
2. Upstream Stop hook gates on the flag (
mlflow-skinny 3.11.1):3. MLflow experiment doesn't even exist on the deployed workspace:
So nothing is written. MLflow auto-creates experiments on first write — the Stop hook short-circuits before any write, so the experiment never materializes and the user has no trail to follow when they go looking.
Adjacent finding:
tests/test_mlflow_tracing.py:63is namedtest_tracing_enabledbut asserts... == "false"— a green test certifying the broken state. Fix should rename the assertion to match the new behaviour.