Skip to content

fix(inngest): keep experiment scores run-scoped when runId is undefined - #1880

Open
princejain756 wants to merge 2 commits into
inngest:mainfrom
princejain756:fix/experiment-score-run-scope
Open

princejain756 wants to merge 2 commits into
inngest:mainfrom
princejain756:fix/experiment-score-run-scope

Conversation

@princejain756

Copy link
Copy Markdown

Fixes #1848 (EXE-2309)

score.experiment() rejects stepId because experiment scores are always run-scoped, but sendScoreExperiment built target as { runId: options.runId } instead of { runId: options.runId ?? null } (unlike sendStepScore), causing InngestMetadata.performOp to fall back to step scope when called inside step.run() without runId. In createScorer, spreading ...runResult / ...result after runId: parent.runId could also overwrite parent.runId when the scorer handler returned runId: undefined.

This uses options.runId ?? null in sendScoreExperiment and resolves runId with ?? parent.runId in createScorer.

@changeset-bot

changeset-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 842034e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
inngest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@greptile-apps

greptile-apps Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect score targeting in two SDK score-writing workflows.

The PR appears safe to merge, with a non-blocking update needed to the public experiment score docs.

Findings

  1. P2 Docs describe the old behavior ▶
Fix with agent prompt
### Issue 1
packages/inngest/src/components/InngestScore.ts:211-213
The public docs for `ClientScore.experiment` at lines 50–53 still warn that calling inside `step.run()` without `runId` produces a step-scoped write. This fix makes that call run-scoped, so the editor docs now tell developers to avoid a supported call. Remove the warning and explain that an omitted `runId` uses the current run, including inside `step.run()`.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Keeps experiment scores attached to a run when runId is omitted.

  • Experiment scores stay on the current run when called inside a step.
  • Deferred scorer results keep the parent run when the handler ID is undefined.

One non-blocking docs update remains: the public API comment still describes the old behavior.

Reviews (1) · Last reviewed commit: "fix(inngest): keep experiment scores run..." · Reviewed by Greptile

Comment on lines +211 to +213
// Experiment scores are always run-scoped; null keeps current-run lookup
// intact even when called inside step.run().
const target = { runId: options.runId ?? null };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Docs describe the old behavior

The public docs for ClientScore.experiment at lines 50–53 still warn that calling inside step.run() without runId produces a step-scoped write. This fix makes that call run-scoped, so the editor docs now tell developers to avoid a supported call. Remove the warning and explain that an omitted runId uses the current run, including inside step.run().

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/inngest/src/components/InngestScore.ts
Line: 211-213

Comment:
**Docs describe the old behavior**

The public docs for `ClientScore.experiment` at lines 50–53 still warn that calling inside `step.run()` without `runId` produces a step-scoped write. This fix makes that call run-scoped, so the editor docs now tell developers to avoid a supported call. Remove the warning and explain that an omitted `runId` uses the current run, including inside `step.run()`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

This branch has not been deployed

No deployments
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.

sendScoreExperiment and createScorer allow experiment scores to become step-scoped when runId is undefined inside a step

1 participant