Skip to content

Add updateCohort RPC to ActorStorage and limit cohort length#6599

Draft
maxmcd wants to merge 1 commit intomainfrom
mmcdonnell/do-cohort-persistence
Draft

Add updateCohort RPC to ActorStorage and limit cohort length#6599
maxmcd wants to merge 1 commit intomainfrom
mmcdonnell/do-cohort-persistence

Conversation

@maxmcd
Copy link
Copy Markdown
Contributor

@maxmcd maxmcd commented Apr 17, 2026

No description provided.

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

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

I'm Bonk, and I've done a quick review of your PR.

Adds an updateCohort RPC to ActorStorage and a client-side length limit (10 bytes) on cohort values, silently dropping oversized inputs.

Issues (ranked by severity):

  1. [MEDIUM] The capnp comment says "If cohort is omitted, clear the stored value" but cohort :Text is not optional in Cap'n Proto — it always has a value (defaults to empty string). The comment should document the actual convention (e.g., "empty string clears") or the field should be rethought.
  2. [LOW] Silent drop of oversized cohorts may frustrate developers debugging routing behavior. Consider whether a JSG_REQUIRE / thrown exception would be more appropriate here.

This review was generated by an AI assistant and may contain inaccuracies.

# Get the storage capability for the given stage of the pipeline, identified by its stable ID.

updateCohort @1 (cohort :Text);
# Persist the actor's resolved cohort. If `cohort` is omitted, clear the stored value.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The comment says "If cohort is omitted" but in Cap'n Proto a non-optional Text parameter always has a value (defaults to empty string) — it can never truly be omitted. Should the comment say "If cohort is empty, clear the stored value" instead, to match the actual wire semantics?

Suggested change
# Persist the actor's resolved cohort. If `cohort` is omitted, clear the stored value.
# Persist the actor's resolved cohort. If `cohort` is empty, clear the stored value.

Comment thread src/workerd/api/actor.c++
// Cohort length is limited to kMaxActorCohortLength bytes, so silently drop
// oversized values rather than passing them through.
if (c.size() > kMaxActorCohortLength) {
v.cohort = kj::none;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Silently discarding the cohort is a defensive choice, but it may make debugging hard for developers who set a cohort and see it ignored with no feedback. Would a JSG_REQUIRE(c.size() <= kMaxActorCohortLength, RangeError, "cohort must be at most ", kMaxActorCohortLength, " characters") be more appropriate? That way callers learn about the limit immediately instead of having their cohort silently cleared.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is good advice, FWIW. It's better to reject invalid input than to silently ignore it.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 17, 2026

I'm Bonk, and I've done a quick review of your PR.

Review posted on PR #6599 with 2 inline comments:

  1. [MEDIUM] actor-storage.capnp:26 — The comment says "If cohort is omitted" but cohort :Text in Cap'n Proto always has a value (defaults to empty string). Suggested rewording the comment to match actual wire semantics.

  2. [LOW] actor.c++:167 — Silent drop of oversized cohorts may make debugging difficult. Raised whether a JSG_REQUIRE throwing a RangeError would be more developer-friendly.

github run

@maxmcd maxmcd force-pushed the mmcdonnell/do-cohort-persistence branch from 20229d9 to 0ed4732 Compare April 17, 2026 00:16
@kentonv
Copy link
Copy Markdown
Member

kentonv commented Apr 23, 2026

Please don't post commits nor PRs with empty descriptions. The PR description should explain not just what is changing, but why. Do not assume that anyone already knows what you're up to.

(I know this is a draft, but even for a draft, please do this, or if it's just a test with no intent to ever merge, write that.)

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.

3 participants