feat(ci): add RunnerContext and RegressionError for experiment GH action#1635
Open
feat(ci): add RunnerContext and RegressionError for experiment GH action#1635
Conversation
Adds the SDK-side primitives consumed by the upcoming `langfuse/experiment-action` GitHub Action (LFE-9241): - `RunnerContext` wraps `Langfuse.run_experiment` with action-injected defaults (data, dataset_version, name, run_name, metadata). Users can override any default on the call site; metadata is merged with user-supplied keys winning on collision. - `RegressionError` lets users signal a CI gate failure and optionally pass structured `metric`/`value`/`threshold` fields so the action can render a callout in the PR comment. Both live in a dedicated `langfuse/ci.py` module so the CI surface stays isolated from the general experiment API. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
wochinge
commented
Apr 21, 2026
…eriment module Relocates the CI-action primitives from the standalone `langfuse/ci.py` module into `langfuse/experiment.py` alongside the other experiment types. Deletes `langfuse/ci.py` and renames the tests accordingly. The public import paths (`from langfuse import RunnerContext, RegressionError`) are unchanged. `CompositeEvaluatorFunction` is imported under `TYPE_CHECKING` to avoid a circular import with `langfuse.batch_evaluation`. The signature-drift guard now resolves the forward reference via `typing.get_type_hints(..., localns=...)`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Mirrors the module name now that RunnerContext and RegressionError live in `langfuse.experiment`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@claude review |
- RunnerContext no longer carries `name` or `run_name` as context-level defaults. `name` is now required on every `run_experiment` call (supports the action's directory-of-experiments mode where each script must name itself). `run_name` passes straight through to `Langfuse.run_experiment`. - RegressionError gains three typed `@overload` signatures (minimal, free-form message, structured metric/value/threshold) so type checkers enforce that `metric` and `value` are supplied together. At runtime, partial structured input falls back to the default message instead of rendering misleading `None` placeholders in PR comments. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
hassiebp
reviewed
Apr 22, 2026
Contributor
hassiebp
left a comment
There was a problem hiding this comment.
One SDK-side API comment to keep the action and SDK contract lined up.
| class RunnerContext: | ||
| """Wraps :meth:`Langfuse.run_experiment` with CI-injected defaults. | ||
|
|
||
| Intended for use with the ``langfuse/experiment-action`` GitHub Action |
Contributor
There was a problem hiding this comment.
RunnerContext feels like the right abstraction here, and I think the action side should lean into it as the single public integration path: construct the context, then call experiment(context) explicitly instead of also teaching users to read action-specific env vars. Since this is likely to become the primary authoring model, I’d optimize for that clean contract end-to-end.
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.
Summary
Adds the SDK-side primitives consumed by the upcoming
langfuse/experiment-actionGitHub Action (LFE-9241).RunnerContextwrapsLangfuse.run_experimentwith action-injected defaults (data,dataset_version,name,run_name,metadata). Users can override any default on the call site;metadatais merged with user-supplied keys winning on collision. Supports bothLocalExperimentItemandDatasetItem.RegressionErrorlets a user'sexperimentfunction signal a CI gate failure. Exposes optional structuredmetric/value/thresholdfields so the action can render a targeted callout in the PR comment; falls back to a free-formmessageor a default string.Usage (from the proposal)
Out of scope
langfuse/experiment-actionGitHub Action itselfregressions: List[Regression]later)🤖 Generated with Claude Code
Disclaimer: Experimental PR review
Greptile Summary
This PR adds two new SDK primitives —
RunnerContextandRegressionError— intended for use with the upcominglangfuse/experiment-actionGitHub Action.RunnerContextwrapsLangfuse.run_experimentwith action-injected defaults (dataset, name, run name, metadata) that users can override per-call, with user-supplied metadata keys winning on collision.RegressionErroris a structured exception that lets a user's experiment function signal a CI gate failure with optional metric/value/threshold fields.Confidence Score: 4/5
Safe to merge with two minor improvements worth addressing before the companion GitHub Action ships.
Both findings are P2, but the value/threshold-without-metric case silently drops structured diagnostic fields from the exception message, which could mislead action consumers. Neither is a hard blocker, but fixing them before the companion GitHub Action ships would avoid surprising behaviour.
langfuse/experiment.py — RunnerContext.run_experiment mutable defaults and RegressionError message formatting.
Important Files Changed
Sequence Diagram
sequenceDiagram participant A as experiment-action participant RC as RunnerContext participant L as Langfuse.run_experiment participant U as user experiment() A->>RC: RunnerContext(client, data, name, run_name, metadata, ...) A->>U: experiment(context=rc) U->>RC: context.run_experiment(task=..., [overrides]) RC->>RC: resolve name / data / run_name (call overrides ctx defaults) RC->>RC: merge metadata (user keys win on collision) RC->>L: run_experiment(name, data, run_name, metadata, ...) L-->>RC: ExperimentResult RC-->>U: ExperimentResult alt regression detected U->>U: raise RegressionError(result, metric, value, threshold) U-->>A: RegressionError propagates A->>A: fail workflow, render PR callout else success U-->>A: ExperimentResult endPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "test: rename test_runner_context.py to t..." | Re-trigger Greptile