Skip to content

Add noop jurisdictions in workerd #4745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Aug 13, 2025
Merged

Add noop jurisdictions in workerd #4745

1 commit merged into from
Aug 13, 2025

Conversation

joshthoward
Copy link
Contributor

I am on the fence whether this is worthwhile. I don't like it because the jurisdictions feature makes no sense in workerd, but customers would like to have jurisdiction support in local development. This adds jurisdictions which effectively do nothing, but should have the same properties that they do in edgeworker. This changes the way that actor IDs are computed in workerd, which is technically a breaking change.

// Check that no two DurableObjectId created via `newUniqueId()` are equal.
const id1 = env.ns.newUniqueId();
const id2 = env.ns.newUniqueId();
assert.equal(id1.equals(id2), false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert.equal(id1.equals(id2), false);
assert.ok(!id1.equals(id2));

// });
assert.throws(() => {
euNs.jurisdiction('fedramp');
});
Copy link
Collaborator

@jasnell jasnell Aug 11, 2025

Choose a reason for hiding this comment

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

assert.throws(...) really ought to have a second argument to test the error type and message (here and in the other cases below).

// jurisdictions.
const id1 = euNs.newUniqueId();
const id2 = euNs.newUniqueId();
assert.equal(id1.equals(id2), false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert.equal(id1.equals(id2), false);
assert.ok(!id1.equals(id2));

Comment on lines 127 to 128
assert.equal(id1.equals(id2), false);
assert.equal(id2.equals(id3), true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert.equal(id1.equals(id2), false);
assert.equal(id2.equals(id3), true);
assert.ok(!id1.equals(id2));
assert.ok(id2.equals(id3));

@@ -87,14 +108,28 @@ kj::Own<ActorIdFactory::ActorId> ActorIdFactoryImpl::idFromString(kj::String str
JSG_REQUIRE(kj::arrayPtr(id).slice(BASE_LENGTH).startsWith(decoded.asPtr().slice(BASE_LENGTH)),
TypeError, "Durable Object ID is not valid for this namespace.");

return kj::heap<ActorIdImpl>(id, kj::none);
// TODO(jhoward): This has an issue that an actor ID will loose its jurisdiction after being
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: we don't typically use names in the TODO comments... generally these should be like TODO(soon), TODO(cleanup), etc.

"Cannot create a jurisdictional subnamespace from a subnamespace that already "
"has a jurisdiction set");
// TODO(jhoward): Do these warnings show up in local dev?
KJ_LOG(WARNING, "jurisdiction restrictions have no affect in workerd", jurisdiction);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might make sense to make this LOG_ONCE or LOG_PERIODICALLY

bool ActorIdFactoryImpl::matchesJurisdiction(const ActorId& id) {
bool ActorIdFactoryImpl::matchesJurisdiction(const ActorId& abstractId) {
// TODO(jhoward): Is there something more idiomatic here? KJ_IF_SOME gives me an unused variable,
// but the tour says to avoid checking kj::none explicitly.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This pattern is fine. You could use a maybeJurisdiction.map(...) but to my eyes that's less readable.

ActorIdImpl(const kj::byte idParam[SHA256_DIGEST_LENGTH], kj::Maybe<kj::String> name);
ActorIdImpl(const kj::byte idParam[SHA256_DIGEST_LENGTH],
kj::Maybe<kj::String> name,
kj::Maybe<kj::String> maybeJurisdiction);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
kj::Maybe<kj::String> maybeJurisdiction);
kj::Maybe<kj::String> maybeJurisdiction = kj::none);

@joshthoward joshthoward force-pushed the joshthoward/jurisdictions branch from 9d1ae14 to 3059777 Compare August 13, 2025 16:46
@joshthoward joshthoward closed this pull request by merging all changes into main in b4d75c0 Aug 13, 2025
@joshthoward joshthoward deleted the joshthoward/jurisdictions branch August 13, 2025 17:50
@joshthoward
Copy link
Contributor Author

If anyone else is confused by the history of this PR like me it shows as merged because the branch name used in this PR was reused in another PR. The commit that was merged into master is 3059777 which does not reflect the changes that James commented on or that match the description "Add noop jurisdictions in workerd".

The decision to not "Add noop jurisdictions in workerd" is due to the fact that jurisdictions have no meaning in workerd and to make them match Cloudflare's production environment we would have to change the way that we encode DurableObjectIds in workerd and therefore either break customers or maintain a mechanism for reading older DurableObjectIds before supporting jurisdictions. This is just more trouble than it is worth. The alternative that we will pursue is to allow jurisdictions to be nullish for workerd so that local development is easier for customers. E.g.

const ns = env.MY_DURABLE_OBJECT.jurisdiction(env.JURISDICTION);

vs.

let ns;
if (!env.JURISDICTION) {
  ns = env.MY_DURABLE_OBJECT;
} else {
  ns = env.MY_DURABLE_OBJECT.jurisdiction(env.JURISDICTION);
}

Assuming that JURISDICTION is a env variable set on production.

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.

2 participants