GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix type inference for `ActionState` by mbg · Pull Request #4220 · github/codeql-action

Conversation

@mbg

@mbg mbg commented Oct 9, 2026

Copy link
Copy Markdown
Member

While working on something else, I noticed that type inference for ActionState was broken in some cases. The problem is that, when given a chance, TypeScript will simplify an ActionState<Fs> type as much as possible, which results in a concrete object type that doesn't mention Fs. That causes problems for functions which accept ActionState<Fs> values, but need to know the feature keys Fs such as the callee function from testing-utils.ts.

Assuming that we have a function test(action: ActionState<["Logger", "Env"]): boolean, then before this change the result of callee(test) would be a value of type CallableEnvBuilder<[], boolean, readonly (keyof FeatureState)[]>. That's no good since readonly (keyof FeatureState)[] satisfies any StateFeature[] constraint and doesn't tell us which features the function actually needs.

The fix here is a bit complex, but fundamentally focuses around adding a property to the result of ActionState that tracks Fs. That's straight-forward, but we also need to ensure that ActionState values which provide a superset of the required properties can be passed to functions which don't require all of it. That is accomplished by making the extra property a function and tracking the features Fs in its parameter to exploit the contravariance of function parameters.

Finally, we also need to account for Env implying ReadOnlyEnv. That's addressed by expanding "Env" to "Env" | "ReadOnlyEnv" in the tracked features.

Extending ActionState objects is also tricky because in e.g. the existing { ...action, features } constructions, features: FeatureEnablement and so the "Features" key is not mentioned. The extendActionState function works around that by using a reverse lookup (implemented in FeatureNameFor) to lookup the feature key for a given object.

Risk assessment

For internal use only. Please select the risk level of this change:

  • Low risk: Changes are fully under feature flags, or have been fully tested and validated in pre-production environments and are highly observable, or are documentation or test only.

Which use cases does this change impact?

Environments:

  • Testing/None - This change does not impact any CodeQL workflows in production.

How did/will you validate this change?

  • Unit tests - I am depending on unit test coverage (i.e. tests in .test.ts files).
  • End-to-end tests - I am depending on PR checks (i.e. tests in pr-checks).

If something goes wrong after this change is released, what are the mitigation and rollback strategies?

  • Development/testing only - This change cannot cause any failures in production.

How will you know if something goes wrong after this change is released?

  • Other - Please provide details.

Are there any special considerations for merging or releasing this change?

  • No special considerations - This change can be merged at any time.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Consider adding a changelog entry for this change.
  • Confirm the readme and docs have been updated if necessary.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mbg
Fix type inference for ActionState
e57c0e6
@mbg
mbg requested a review from a team as a code owner October 9, 2026 13:29
Copilot AI balanced review requested due to automatic review settings October 9, 2026 13:29
@github-actions github-actions Bot added the size/S Should be easy to review label Oct 9, 2026
Copilot started reviewing on behalf of mbg October 9, 2026 13:30
View session
Copilot AI reviewed Oct 9, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Warning

  • Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.

🟡 Changes recommended

The helper’s documented generic escape hatch is unusable, and the compile-time behavior lacks regression coverage.

2 open findings
  • High severity F type argument prevents inference of required type parameters · New
  • Low severity Add type-level regression tests for phantom field contracts · New
What changed in this PR

This PR improves ActionState feature inference for testing utilities and state extension.

Changes:

  • Adds phantom feature tracking with Env implication handling.
  • Introduces extendActionState and updates three action entry points.
  • Updates the generated bundle.
File Description
src/​action-common.ts Adds feature tracking and state extension types.
src/​init-action.ts Uses the state extension helper.
src/​setup-codeql-action.ts Uses the state extension helper.
src/​start-proxy-action.ts Uses the state extension helper.
lib/​entry-points.js Generated bundle; excluded from review by policy.
Files excluded by content exclusion policy (1)
  • lib/entry-points.js

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/action-common.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/action-common.ts
Comment on lines +117 to +122
* `Fs[number]` returns the union of all features in `Fs`. We wrap it in `ImpliedFeatures`
* so that `Env` is expanded into `Env | ReadOnlyEnv`, allowing functions that expect the
* `ReadOnlyEnv` feature to be provided with an `ActionState` that has the `Env` feature
* without requiring this to be made explicit.
*/
readonly [stateFeatures]?: (ts: ImpliedFeatures<Fs[number]>) => void;
mario-campos
mario-campos approved these changes Oct 9, 2026
View reviewed changes
@mbg
mbg added this pull request to the merge queue Oct 9, 2026
Merged via the queue into main with commit 6e7fe2e Oct 9, 2026
237 of 238 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@mbg
mbg deleted the mbg/fix-action-state-type-inference branch October 9, 2026 22:45
This was referenced Oct 14, 2026
Merge main into releases/v4 dsp-testing/mario-campos-post-comment-test#6
Merged
Merge main into releases/v4 #4239
Merged
Merge releases/v4 into releases/v3 #4241
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@mario-campos mario-campos mario-campos approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

size/S Should be easy to review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@mbg @mario-campos
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.