Skip to content

Commit 6b34898

Browse files
qingxinwuQingxin Wudomfarolino
authored
Add per buyer cumulative timeout (#836)
* Add buyer's cumulative timeout. * Finish. * Decrement timeout one step earlier. * Use monotonic clock instead of wall clock. * all buyers cumulative timeout default to null. * Apply suggestions from code review Co-authored-by: Dominic Farolino <domfarolino@gmail.com> * Revert to use table, and update column names * Get monotonic clock from settings, and add issue. * Change a note to normative. --------- Co-authored-by: Qingxin Wu <qingxinwu@google.com> Co-authored-by: Dominic Farolino <domfarolino@gmail.com>
1 parent 50ff31a commit 6b34898

File tree

1 file changed

+97
-33
lines changed

1 file changed

+97
-33
lines changed

spec.bs

Lines changed: 97 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ dictionary AuctionAdConfig {
706706
USVString sellerCurrency;
707707
Promise<record<USVString, any>> perBuyerSignals;
708708
Promise<record<USVString, unsigned long long>> perBuyerTimeouts;
709+
Promise<record<USVString, unsigned long long>> perBuyerCumulativeTimeouts;
709710
record<USVString, unsigned short> perBuyerGroupLimits;
710711
record<USVString, unsigned short> perBuyerExperimentGroupIds;
711712
record<USVString, record<USVString, double>> perBuyerPrioritySignals;
@@ -1163,23 +1164,36 @@ To <dfn>validate and convert auction ad config</dfn> given an {{AuctionAdConfig}
11631164
1. [=map/Set=] |auctionConfig|'s [=auction config/per buyer signals=][|buyer|] to
11641165
|signalsString|.
11651166
* To handle an error, set |auctionConfig|'s [=auction config/per buyer signals=] to failure.
1166-
1. If |config|["{{AuctionAdConfig/perBuyerTimeouts}}"] [=map/exists=]:
1167-
1. Set |auctionConfig|'s [=auction config/per buyer timeouts=] to
1168-
|config|["{{AuctionAdConfig/perBuyerTimeouts}}"].
1169-
1. [=Handle an input promise in configuration=] given |auctionConfig| and |auctionConfig|'s
1170-
[=auction config/per buyer timeouts=]:
1171-
* To parse the value |result|:
1172-
1. Set |auctionConfig|'s [=auction config/per buyer timeouts=] to a new [=ordered map=] whose
1173-
[=map/keys=] are [=origins=] and whose [=map/values=] are [=durations=] in milliseconds.
1174-
1. [=map/For each=] |key| → |value| of |result|:
1175-
1. If |key| is "*", then set |auctionConfig|'s [=auction config/all buyers timeout=]
1176-
to |value| in milliseconds or 500 milliseconds, whichever is smaller, and
1177-
[=iteration/continue=].
1178-
1. Let |buyer| be the result of [=parsing an https origin=] with |key|. If |buyer| is
1179-
failure, [=exception/throw=] a {{TypeError}}.
1180-
1. [=map/Set=] |auctionConfig|'s [=auction config/per buyer timeouts=][|buyer|] to
1181-
|value| in milliseconds or 500 milliseconds, whichever is smaller.
1182-
* To handle an error, set |auctionConfig|'s [=auction config/per buyer timeouts=] to failure.
1167+
1. For each |idlTimeoutMember|, |perBuyerTimeoutField|, |allBuyersTimeoutField| in the following table
1168+
<table class="data">
1169+
<thead><tr><th>IDL timeout member</th><th>Per buyer timeout field</th><th>All buyers timeout field</th></tr></thead>
1170+
<tr>
1171+
<td>"{{AuctionAdConfig/perBuyerTimeouts}}"</td>
1172+
<td>[=auction config/per buyer timeouts=]</td>
1173+
<td>[=auction config/all buyers timeout=]</td>
1174+
</tr>
1175+
<tr>
1176+
<td>"{{AuctionAdConfig/perBuyerCumulativeTimeouts}}"</td>
1177+
<td>[=auction config/per buyer cumulative timeouts=]</td>
1178+
<td>[=auction config/all buyers cumulative timeout=]</td>
1179+
</tr>
1180+
</table>
1181+
1. If |config| [=map/contains=] |idlTimeoutMember|:
1182+
1. Set |auctionConfig|'s |perBuyerTimeoutField| to |config|[|idlTimeoutMember|].
1183+
1. [=Handle an input promise in configuration=] given |auctionConfig| and |auctionConfig|'s
1184+
|perBuyerTimeoutField|:
1185+
* To parse the value |result|:
1186+
1. Set |auctionConfig|'s |perBuyerTimeoutField| to a new [=ordered map=] whose
1187+
[=map/keys=] are [=origins=] and whose [=map/values=] are [=durations=] in milliseconds.
1188+
1. [=map/For each=] |key| → |value| of |result|:
1189+
1. If |perBuyerTimeoutField| is "{{AuctionAdConfig/perBuyerTimeouts}}", and
1190+
|value| &gt; 500, then set |value| to 500.
1191+
1. If |key| is "*", then set |auctionConfig|'s |allBuyersTimeoutField| to |value| in
1192+
milliseconds, and [=iteration/continue=].
1193+
1. Let |buyer| be the result of [=parsing an https origin=] with |key|. If |buyer| is
1194+
failure, [=exception/throw=] a {{TypeError}}.
1195+
1. [=map/Set=] |auctionConfig|'s |perBuyerTimeoutField|[|buyer|] to |value| in milliseconds.
1196+
* To handle an error, set |auctionConfig|'s |perBuyerTimeoutField| to failure.
11831197
1. If |config|["{{AuctionAdConfig/perBuyerGroupLimits}}"] [=map/exists=], [=map/for each=]
11841198
|key| → |value| of |config|["{{AuctionAdConfig/perBuyerGroupLimits}}"]:
11851199
1. If |value| is 0, then return failure.
@@ -1483,6 +1497,12 @@ To <dfn>generate and score bids</dfn> given an [=auction config=] |auctionConfig
14831497
1. Decrement |pendingAdditionalBids| by 1.
14841498
1. [=map/For each=] |buyer| → |perBuyerGenerator| of |bidGenerators|,
14851499
[=parallel queue/enqueue steps|enqueue the following steps=] to |queue|:
1500+
1. Let |perBuyerCumulativeTimeout| be |auctionConfig|'s
1501+
[=auction config/all buyers cumulative timeout=].
1502+
1. If |auctionConfig|'s [=auction config/per buyer cumulative timeouts=] is not null and
1503+
[=auction config/per buyer cumulative timeouts=][|buyer|] [=map/exists=], then set
1504+
|perBuyerCumulativeTimeout| to |auctionConfig|'s
1505+
[=auction config/per buyer cumulative timeouts=][|buyer|].
14861506
1. Let |buyerExperimentGroupId| be |allBuyersExperimentGroupId|.
14871507
1. Let |perBuyerExperimentGroupIds| be |auctionConfig|'s
14881508
[=auction config/per buyer experiment group ids=].
@@ -1516,6 +1536,8 @@ To <dfn>generate and score bids</dfn> given an [=auction config=] |auctionConfig
15161536
1. [=map/For each=] |signalsUrl| → |perSignalsUrlGenerator| of |perBuyerGenerator|:
15171537
1. Let |keys| be a new [=ordered set=].
15181538
1. Let |igNames| be a new [=ordered set=].
1539+
1. Let |fetchSignalStartTime| be |settings|'s [=environment settings object/current monotonic time=].
1540+
15191541
1. [=map/For each=] joiningOrigin → |groups| of |perSignalsUrlGenerator|:
15201542
1. [=list/For each=] |ig| of |groups|:
15211543
1. [=set/Append=] |ig|'s [=interest group/trusted bidding signals keys=] to |keys|.
@@ -1526,16 +1548,25 @@ To <dfn>generate and score bids</dfn> given an [=auction config=] |auctionConfig
15261548
with |biddingSignalsUrl| and true.
15271549
1. If |dataVersion| is not null, then [=map/set=]
15281550
|browserSignals|["{{BiddingBrowserSignals/dataVersion}}"] to |dataVersion|.
1551+
1. Let |fetchSignalDuration| be the [=duration from=] |fetchSignalStartTime| to |settings|'s
1552+
[=environment settings object/current monotonic time=], in milliseconds.
1553+
1. If |perBuyerCumulativeTimeout| is not null:
1554+
1. Decrement |perBuyerCumulativeTimeout| by |fetchSignalDuration|.
1555+
1. If |perBuyerCumulativeTimeout| is negative, then [=iteration/break=];
15291556
1. [=map/For each=] joiningOrigin → |groups| of |perSignalsUrlGenerator|:
15301557
1. [=list/For each=] |ig| of |groups|:
15311558
1. If |ig|'s [=interest group/bidding url=] is null, [=iteration/continue=].
1532-
1. Let |directFromSellerSignalsForBuyer| be the result of running
1533-
[=get direct from seller signals for a buyer=] with |directFromSellerSignals|, and
1534-
|ig|'s [=interest group/owner=].
1535-
1. Let |generatedBid| be the result of [=generate a bid=] given
1536-
|allTrustedBiddingSignals|, |auctionSignals|, a [=map/clone=] of |browserSignals|,
1537-
|perBuyerSignals|, |directFromSellerSignalsForBuyer|, |perBuyerTimeout|, |expectedCurrency|,
1538-
|ig|, and |auctionStartTime|.
1559+
1. If |perBuyerCumulativeTimeout| is not null and is less than |perBuyerTimeout|, then set
1560+
|perBuyerTimeout| to |perBuyerCumulativeTimeout|.
1561+
1. Let |generateBidStartTime| be |settings|'s
1562+
[=environment settings object/current monotonic time=].
1563+
1. Let |generatedBid| be the result of [=generate a bid=] given |allTrustedBiddingSignals|,
1564+
|auctionSignals|, a [=map/clone=] of |browserSignals|, |perBuyerSignals|,
1565+
|perBuyerTimeout|, |expectedCurrency|, |ig|, and |auctionStartTime|.
1566+
1. Let |generateBidDuration| be the [=duration from=] |generateBidStartTime| to |settings|'s
1567+
[=environment settings object/current monotonic time=], in milliseconds.
1568+
1. If |perBuyerCumulativeTimeout| is not null, decrement |perBuyerCumulativeTimeout| by
1569+
|generateBidDuration|.
15391570
1. If |generatedBid| is failure, [=iteration/continue=].
15401571
1. If [=query generated bid k-anonymity count=] given |generatedBid| returns false:
15411572

@@ -1563,13 +1594,20 @@ To <dfn>generate and score bids</dfn> given an [=auction config=] |auctionConfig
15631594
1. If [=query component ad k-anonymity count=] given |adComponent|'s
15641595
[=interest group ad/render url=] returns true, [=list/append=] |adComponent| to |ig|'s
15651596
[=interest group/ad components=].
1597+
1. If |perBuyerCumulativeTimeout| is not null and is less than |perBuyerTimeout|, then set
1598+
|perBuyerTimeout| to |perBuyerCumulativeTimeout|.
1599+
1. Let |generateBidStartTime| be |settings|'s
1600+
[=environment settings object/current monotonic time=].
15661601
1. Set |generatedBid| to the result of [=generate a bid=] given
15671602
|allTrustedBiddingSignals|, |auctionSignals|, a [=map/clone=] of |browserSignals|,
15681603
|perBuyerSignals|, |directFromSellerSignalsForBuyer|, |perBuyerTimeout|, |expectedCurrency|,
15691604
and |ig|.
1570-
15711605
1. Set |ig|'s [=interest group/ads=] to |originalAds|.
15721606
1. Set |ig|'s [=interest group/ad components=] to |originalAdComponents|.
1607+
1. Let |generateBidDuration| be the [=duration from=] |generateBidStartTime| to
1608+
|settings|'s [=environment settings object/current monotonic time=], in milliseconds.
1609+
1. If |perBuyerCumulativeTimeout| is not null, then decrement |perBuyerCumulativeTimeout|
1610+
by |generateBidDuration|.
15731611
1. If |generatedBid| is failure, [=iteration/continue=].
15741612
1. [=list/Insert=] |generatedBid|'s [=generated bid/interest group=] in |bidIgs|.
15751613
1. [=Score and rank a bid=] with |auctionConfig|, |generatedBid|, |leadingBidInfo|,
@@ -2953,6 +2991,10 @@ of the following global objects:
29532991
1. Let |realm| be the result of [=creating a new script runner realm=] given
29542992
{{InterestGroupBiddingScriptRunnerGlobalScope}}.
29552993
1. Let |global| be |realm|'s [=realm/global object=].
2994+
1. Let |settings| be |realm|'s [=realm/settings object=].
2995+
2996+
Issue: <a href="https://github.com/WICG/turtledove/issues/676">WICG/turtledove#676</a> needs
2997+
to be fixed in order to get |realm|'s [=realm/settings object=].
29562998
1. Set |global|'s
29572999
[=InterestGroupBiddingScriptRunnerGlobalScope/group has ad components=] to true if |ig|'s
29583000
[=interest group/ad components=] is not null, or false otherwise.
@@ -2972,11 +3014,12 @@ of the following global objects:
29723014
1. Let |browserSignalsJS| be |browserSignals| [=converted to ECMAScript values=].
29733015
1. Let |directFromSellerSignalsJs| be |directFromSellerSignalsForBuyer|
29743016
[=converted to ECMAScript values=].
2975-
1. Let |startTime| be the [=current wall time=].
3017+
1. Let |startTime| be |settings|'s [=environment settings object/current monotonic time=].
29763018
1. Let |result| be the result of [=evaluating a script=] with |realm|, |script|, "`generateBid`",
29773019
« |igJS|, |auctionSignalsJS|, |perBuyerSignalsJS|, |trustedBiddingSignalsJS|, |browserSignalsJS|,
29783020
|directFromSellerSignalsJs| », and |timeout|.
2979-
1. Let |duration| be the [=current wall time=] minus |startTime| in milliseconds.
3021+
1. Let |duration| be |settings|'s [=environment settings object/current monotonic time=] minus
3022+
|startTime| in milliseconds.
29803023
1. If |global|'s [=InterestGroupBiddingScriptRunnerGlobalScope/priority=] is not null and not failure:
29813024
1. Set |ig|'s [=interest group/priority=] to |global|'s
29823025
[=InterestGroupBiddingScriptRunnerGlobalScope/priority=].
@@ -3056,13 +3099,16 @@ of the following global objects:
30563099

30573100
<div algorithm>
30583101
To <dfn>evaluate a script</dfn> with a [=ECMAScript/realm=] |realm|, [=string=] |script|, [=string=]
3059-
|functionName|, a [=list=] |arguments|, and an integer millisecond duration |timeout|, run these steps.
3102+
|functionName|, a [=list=] |arguments|, and an integer millisecond [=duration=] |timeout|, run these steps.
30603103
They return a [=ECMAScript/Completion Record=], which is either an [=ECMAScript/abrupt completion=] (in
30613104
the case of a parse failure or execution error), or a [=ECMAScript/normal completion=] populated with the
30623105
[=ECMAScript/ECMAScript language value=] result of invoking |functionName|.
30633106

30643107
1. [=Assert=] that these steps are running [=in parallel=].
30653108

3109+
1. If |timeout| &le; 0, [=immediately=] interrupt the execution and set |finalCompletion| to a
3110+
new [=ECMAScript/throw completion=] given null.
3111+
30663112
1. Let |global| be |realm|'s [=realm/global object=], and run these steps in |realm|'s [=realm/agent=]:
30673113

30683114
1. Let |result| be [$ParseScript$](|script|, |realm|, `empty`).
@@ -3233,7 +3279,7 @@ To <dfn>convert GenerateBidOutput to generated bid</dfn> given a {{GenerateBidOu
32333279
[=generated bid/ad cost=] to |generateBidOutput|["{{GenerateBidOutput/adCost}}"].
32343280
1. If |generateBidOutput|["{{GenerateBidOutput/modelingSignals}}"] [=map/exists=]:
32353281
1. Let |modelingSignals| be |generateBidOutput|["{{GenerateBidOutput/modelingSignals}}"].
3236-
1. If |modelingSignals| &ge; 0 and |modelingSignals| < 4096, then set |bid|'s
3282+
1. If |modelingSignals| &ge; 0 and |modelingSignals| &lt; 4096, then set |bid|'s
32373283
[=generated bid/modeling signals=] to the result of [=converted to an IDL value|converting=]
32383284
the ECMAScript value represented by |modelingSignals| to an {{unsigned short}}.
32393285
1. Return |bid|.
@@ -4274,6 +4320,23 @@ An auction config is a [=struct=] with the following items:
42744320
Restricts the `generateBid()` script's runtime for all buyers without a timeout specified in
42754321
[=auction config/per buyer timeouts=]. If the timeout expires, only the bid submitted via
42764322
`setBid()` is considered.
4323+
: <dfn>per buyer cumulative timeouts</dfn>
4324+
:: Null, a {{Promise}}, failure, or an [=ordered map=] whose [=map/keys=] are [=origins=] and
4325+
whose [=map/values=] are [=durations=] in milliseconds.
4326+
[=map/Keys=] are buyers and must be valid HTTPS [=origins=]. [=map/Values=] are collective
4327+
timeouts for all interest groups of the buyer represented by the [=map/key=]. Includes the time of
4328+
loading scripts and signals, and running the `generateBid()` functions. Once the timer expires,
4329+
the affected buyer's interest groups may no longer generate any bids. All bids generated before
4330+
the timeout will continue to participate in the auction.
4331+
Implementations should attempt, on a best-effort basis, to generate bids for each buyer in
4332+
priority order, so lower priority [=interest groups=] are the ones more likely to be timed out. If
4333+
{{Promise}}s are passed in to the [=auction config=] for fields that support them,
4334+
[=wait until configuration input promises resolve=] before starting the timer.
4335+
4336+
: <dfn>all buyers cumulative timeout</dfn>
4337+
:: Null or a [=duration=] in milliseconds, initially null.
4338+
Restricts a buyer's cumulative timeout for all buyers without one specified in
4339+
[=auction config/per buyer cumulative timeouts=].
42774340
: <dfn>per buyer group limits</dfn>
42784341
:: Null or an [=ordered map=] whose [=map/keys=] are [=origins=] and whose [=map/values=] are
42794342
{{unsigned short}}s.
@@ -4359,12 +4422,13 @@ To <dfn>wait until configuration input promises resolve</dfn> given an [=auction
43594422
1. Wait until |auctionConfig|'s [=auction config/pending promise count=] is 0.
43604423
1. [=Assert=] |auctionConfig|'s [=auction config/auction signals=], [=auction config/seller signals=],
43614424
[=auction config/per buyer signals=], [=auction config/per buyer currencies=],
4362-
[=auction config/per buyer timeouts=], and [=auction config/direct from seller signals header ad slot=]
4363-
are not {{Promise}}s, and [=auction config/expects additional bids=] is false.
4425+
[=auction config/per buyer timeouts=], [=auction config/per buyer cumulative timeouts=], and
4426+
[=auction config/direct from seller signals header ad slot=] are not {{Promise}}s, and
4427+
[=auction config/expects additional bids=] is false.
43644428
1. If |auctionConfig|'s [=auction config/auction signals=], [=auction config/seller signals=],
43654429
[=auction config/per buyer signals=], [=auction config/per buyer currencies=],
4366-
[=auction config/per buyer timeouts=], or [=auction config/direct from seller signals header ad slot=]
4367-
is failure, return failure.
4430+
[=auction config/per buyer timeouts=], [=auction config/per buyer cumulative timeouts=], or
4431+
[=auction config/direct from seller signals header ad slot=] is failure, return failure.
43684432
1. Return.
43694433

43704434
</div>

0 commit comments

Comments
 (0)