Skip to content

feat: ensure max state memory size#1458

Open
doc-han wants to merge 6 commits into
mainfrom
state-memory-limit
Open

feat: ensure max state memory size#1458
doc-han wants to merge 6 commits into
mainfrom
state-memory-limit

Conversation

@doc-han

@doc-han doc-han commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Short Description

This PR completes the plumbing required to get state limit set for a worker.

2 ways to go about it

  1. state_limit_mb from Lightning
  2. --state-memory / WORKER_MAX_STATE_MEMORY_MB

Fixes #1459

Implementation Details

A more detailed breakdown of the changes, including motivations (if not provided in the issue).

QA Notes

List any considerations/cases/advice for testing/QA here.

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

@github-project-automation github-project-automation Bot moved this to New Issues in Core Jun 18, 2026
@doc-han doc-han marked this pull request as ready for review June 18, 2026 17:05
@doc-han doc-han changed the title feat: ensure max state memory feat: ensure max state memory size Jun 18, 2026
@doc-han doc-han requested a review from josephjclark June 19, 2026 01:58
@josephjclark

Copy link
Copy Markdown
Collaborator

@doc-han this looks great but I think we can add a better test to make sure the limit is set and working. Probably in integration tests? Just set the limit quite low and build a state object big enough to trigger it. Search for Array.fill for patterns of this sort of thing

@doc-han doc-han moved this from New Issues to In review in Core Jun 19, 2026
@doc-han

doc-han commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

There was a flaky test on dataclip loading which I've resolved on this PR

Comment thread packages/ws-worker/test/api/execute.test.ts Outdated
@josephjclark

Copy link
Copy Markdown
Collaborator

@doc-han just a changeset and that log line needed and we can release this. Thank you, nice work!

@doc-han

doc-han commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator Author

Ready!

})
.option('state-memory', {
description:
'Maximum size of the state object returned by each step, in mb. Defaults to 25% of run-memory. Env: WORKER_MAX_STATE_MEMORY_MB',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I want to think about this before merging

I'd missed/forgotten that we're doing this already. Which means the limit in prod right now isn't 500mb (as is the default in the function), it's more like 250mb. And that might be big enough to cause problems still.

Should we reduce the default to 10% of working memory? Is that too strict and small?

Also should we be adding some logging around this? For users or GCP?

I do see a logger.debug line which prints the state size limit but I can't see that being logged in production - what's that all about?

@josephjclark josephjclark left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Picked up a couple of questions in a final review pass before merging. I need to think about these before going ahead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Allow setting max state memory via environment variable

3 participants