Skip to content
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

Change API layering in spec #51

Merged
merged 12 commits into from
Jun 9, 2023
Merged

Change API layering in spec #51

merged 12 commits into from
Jun 9, 2023

Conversation

alexmturner
Copy link
Collaborator

@alexmturner alexmturner commented May 30, 2023

Creates new exported algorithms and one algorithm to be overriden. This cl doesn't actually move any content to other specs, but is a step to making that simpler. This change also addresses batching, by defining the batching scopes more completely.


Preview | Diff

@alexmturner
Copy link
Collaborator Author

@yoavweiss could you take a quick look? I wasn't sure if this was the best direction towards fixing the layering, but I'm trying to allow each implementing API to define its own 'batching scope'. Specifically, I wasn't really sure whether functions being 'overridden' was a well-supported spec concept. Thanks!

@alexmturner
Copy link
Collaborator Author

I've reworked this to separate out the parts that will (eventually) be moved to other specs into separate sections at the end as well as moved from 'overrides' to having a field that gets set by implementing specs

cc @linnan-github

Copy link
Contributor

@yoavweiss yoavweiss left a comment

Choose a reason for hiding this comment

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

Looks good overall. A few comments

1. [=list/Append=] |contribution| to the [=contributions cache=].
1. Let |batchingScopeSteps| be the {{PrivateAggregation}} object's
[=PrivateAggregation/get batching scope steps=].
1. If |batchingScopeSteps| is null, throw a new {{DOMException}} with name
Copy link
Contributor

Choose a reason for hiding this comment

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

Can that happen? If not, it's better to assert it doesn't, rather than throwing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a note here -- below we say "The global scope may wait to set the field to indicate that the API is not yet available."

Copy link
Contributor

Choose a reason for hiding this comment

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

What would be the behavior expected from developers here? Is there a way for them to check availability before hitting an exception?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is really just to prevent the API being available during the initial execution of a script (e.g. while addModule() runs). We only want the API to be available after that point. Definitely open to suggestions for better structuring this, but for now I've updated the description slightly to clarify.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added an example to better illustrate this, lmk if you think it's clear enough

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine as far as the spec go, but worthwhile thinking about the developer ergonomics here:

  • How would developers know when it's fine to run this API call and when it isn't? Is that part of our developer documentation?
  • If I'm a library provider enabling folks to send reports, how should I write my code so that it never runs too early? (regardless of when callers may call it)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, makes sense. Added an issue to think about this a bit further/follow up.

spec.bs Outdated

Structures {#structures}
========================

General {#general-structures}
-----------------------------

<h4 dfn-type=dfn>Aggregatable report</h3>
<h4 dfn-type=dfn>Batching scope</h4>
A batching scope is a unique internal value that identifies which
Copy link
Contributor

Choose a reason for hiding this comment

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

s/unique internal value/implementation-defined value/

https://infra.spec.whatwg.org/#implementation-defined

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For this, I was trying to emulate the "opaque origin" kind of concept. I saw "unique internal value" in the HTML spec (https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#unique-values), but I don't think it's exported, so I might need to move that definition in here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@domenic - thoughts? Should we try to export "unique internal value"?

Copy link

Choose a reason for hiding this comment

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

Huh I didn't realize that we made that into a whole concept with a definition. Probably we should move that to Infra and make it exported.

In the meantime, you could do <a spec=HTML>unique internal value</a> to link to the concept despite it not being exported.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, moved to the tag as suggested. Also added an issue and filed whatwg/infra#583 to track this.

spec.bs Outdated Show resolved Hide resolved
@alexmturner
Copy link
Collaborator Author

@linnan-github, could you PTAL? Thanks!

spec.bs Show resolved Hide resolved
1. [=list/Append=] |contribution| to the [=contributions cache=].
1. Let |batchingScopeSteps| be the {{PrivateAggregation}} object's
[=PrivateAggregation/get batching scope steps=].
1. If |batchingScopeSteps| is null, throw a new {{DOMException}} with name
Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine as far as the spec go, but worthwhile thinking about the developer ergonomics here:

  • How would developers know when it's fine to run this API call and when it isn't? Is that part of our developer documentation?
  • If I'm a library provider enabling folks to send reports, how should I write my code so that it never runs too early? (regardless of when callers may call it)

spec.bs Outdated
`run()` or to `selectURL()`), create a new [=batching scope=] and associate it
with that invocation.

When a {{PrivateAggregation}} object is exposed on a
Copy link
Contributor

Choose a reason for hiding this comment

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

The "when..." here doesn't make sense, as you're defining that exposure above, with the partial interface. It'd be better to actually find algorithmic hooks that indicate that the addModule execution is done, and set the algorithm there.

spec.bs Outdated
Note: Multiple operation invocations can be in-progress at the same time, each
with a different batching scope. However, only one can be currently executing.

When an operation invocation completes, [=mark a batching scope complete=] given
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here - is there an algorithm that runs the operation invocation, that can call this logic?

spec.bs Outdated
Issue: Do we want to align naming with implementation?

At the start of each Protected Audience auction (i.e. a call to
`runAdAuction()`), create a new [=batching scope=] for each unique origin
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you state that in terms of an algorithm step? (e.g. before step 1 of https://wicg.github.io/turtledove/#dom-navigator-runadauction)

spec.bs Outdated
`runAdAuction()`), create a new [=batching scope=] for each unique origin
participating in the auction (including both bidders and the seller).

When a {{PrivateAggregation}} object is exposed on a
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as for SharedStorage

spec.bs Outdated
1. Return the [=batching scope=] associated with the auction and the |scope|'s
[=relevant settings object=]'s [=environment settings object/origin=].

When an auction completes, perform the following steps:
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, would be better to hook onto a specific algorithm.

@alexmturner
Copy link
Collaborator Author

alexmturner commented Jun 7, 2023

@yoavweiss Thanks for the feedback! Had a go reworking to better integrate with the specs. Ran into a few issues with the other specs, so opened issues and noted those in this spec too where relevant. Some of the integrations I've put here are a little more handwavy than I'd like, but that should be fixable once those issues are resolved.

spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved

Note: This last requirement means that global scopes with different origins

Choose a reason for hiding this comment

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

Probably can mention or link to the Same-Origin policy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a comment (and an issue to actually link the section in the security considerations once that PR lands)

See infra/201
See <a href="https://github.com/whatwg/infra/issues/201">infra/201</a>.

To <dfn algorithm export>append an entry to the contribution cache</dfn> given a

Choose a reason for hiding this comment

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

Given this is only one step, does it need to be a standalone algorithm?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did it this way to allow other APIs to integrate, e.g. for the Protected Audience extensions. I put these under a new heading "Exported algorithms" to make this clearer

spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
spec.bs Outdated Show resolved Hide resolved
@alexmturner
Copy link
Collaborator Author

Thanks for all the improvements!

@alexmturner alexmturner merged commit 3d32307 into main Jun 9, 2023
@alexmturner alexmturner deleted the layering-batching branch June 9, 2023 19:53
github-actions bot added a commit that referenced this pull request Jun 9, 2023
SHA: 3d32307
Reason: push, by alexmturner

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

4 participants