Skip to content

Add identity-only mode to the Prebid integration - #1620

Open
prk-Jr wants to merge 19 commits into
feat/s2s-eid-collection-providersfrom
feat/1594-identity-only-tsjs
Open

prk-Jr wants to merge 19 commits into
feat/s2s-eid-collection-providersfrom
feat/1594-identity-only-tsjs

Conversation

@prk-Jr

@prk-Jr prk-Jr commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add opt-in integrations.prebid.mode = "identity" so publishers can use managed Prebid identity without installing Trusted Server's browser auction integration. Existing configurations default to "auction".
  • Deliver the current server mirror to publisher auctions as request-local first-party data while capturing only native User ID module EIDs into ts-eids, including pages that never run an auction.
  • Preserve publisher bidders, ad units, GPT behavior and consent activity controls. Consent-triggered EC fetching remains in Injected script calls the EC route on consent and merges the IDs into Prebid #1599.

Revision status, checked 2026-12-03 12:12 UTC: the maintainer advanced this PR to 98a56e8550, with base feat/s2s-eid-collection-providers at 2239b604b48a39345968f5484340db3019089476 and EdgeZero ef5cbf308. Earlier signed review correction 827f0e38b5 remains in its history. Local/runtime and hosted results below are historical for their named revisions; they do not qualify this later SDK merge. Exact-head CI reports 21 contexts (21 QUEUED); full current-head qualification is assessed separately.

Stacked on #1489, targeting feat/s2s-eid-collection-providers; the mirror writer must land first.

Enable identity-only mode

Update the existing table in your application configuration and publish the updated config:

[integrations.prebid]
enabled = true
mode = "identity"

Keep the existing external bundle, module selection and managed User ID settings. Add or update mode in the existing table; do not create a duplicate TOML table. Deploying the code alone does not enable this mode. Omitted mode defaults to "auction".

See the identity-only setup guide.

Changes

File Change
crates/trusted-server-core/src/integrations/prebid.rs Add typed auction/identity configuration, default and injected browser mode, with parsing and injection tests.
crates/trusted-server-js/lib/src/integrations/prebid/index.ts Retain shared managed identity setup; select identity wrapping before auction hooks, skip GPT refresh, deduplicate capture and contain blocked-cookie failures.
crates/trusted-server-js/lib/src/integrations/prebid/native_capture.ts Sample fresh native IDs without an auction; handle visibility, navigation and BFCache with one timer.
crates/trusted-server-js/lib/src/integrations/prebid/identity.ts Validate and reread the mirror per auction; merge live EIDs without mutating publisher data or persisting mirror values globally.
crates/trusted-server-js/lib/test/integrations/prebid/identity.test.ts Cover mode isolation, native capture without mirror echo, merge validation/metadata/deduplication, cookie changes and request/callback semantics.
crates/trusted-server-js/lib/test/integrations/prebid/index.test.ts Preserve existing auction behavior and capture regressions.
crates/trusted-server-js/lib/test/prebid-artifact-integration.test.mjs Exercise real built Prebid bidder consumption and activity redaction.
docs/guide/integrations/prebid.md Document mode selection, mirror opt-in, publisher ownership and scope.
trusted-server.example.toml Show the default auction mode and opt-in identity setting.
docs/superpowers/specs/2026-11-17-identity-only-tsjs-design.md Define the feature contract and record two spec review rounds.
docs/superpowers/plans/2026-11-17-identity-only-tsjs.md Record implementation and verification steps.

Closes

Closes #1594

Spec

Spec: Identity-only tsjs mode, including two agent review rounds.

Historical correction verification

The correction in 827f0e3 names the capture-mode flag identityCapture: it governs native source selection, changed-only cookie writes, stale clearing and warning deduplication. collectAuctionEids(nativeOnly) keeps its narrower source-selection name. Defaults, call sites and behavior are unchanged; all 13 built JavaScript bundles, including Prebid, are byte-identical before and after the rename.

Fresh local checks on this revision:

  • Existing identity/index and generated Prebid/IIFE artifact suites: 393 tests pass.
  • Full JavaScript suite: 3,366 passed, one skipped, with no type errors; build, JS/docs ESLint and formatting pass.
  • All adapter suites (including both Fastly modes), eight target-matched Clippy aliases, native parity, CLI and build-digest tests/lint pass.
  • Fastly and Cloudflare/Spin deadline runtime controls, current-source changed-line/staged domain lint, Wasm clock/core-executor guards, Node pin guards, documentation proposal/release/response-diff scripts, Rust/docs/Markdown formatting and the docs site build pass.

All 25 hosted checks passed on review-correction commit 827f0e38b5eb3cb4a36022e817f2220a618f78f2; those results do not qualify the later SDK merge. Historical browser/deployed observations below were not repeated for this naming-only correction. Their underlying receipts were unavailable to this audit; they do not establish fresh deployed-service or live-vendor qualification.

Historical runtime observations

Browser verification exercised the actual Fastly and Axum applications, trusted HTTPS development proxy, real Chrome and a controlled bidder. Seven reader scenarios per adapter cover native capture before any auction, mirror delivery/removal/replacement/expiry/malformed input, metadata precedence, consent denial/restoration and no mirror echo. The controlled reader fixture supplied a generated Prebid 10.26 bundle and synthetic mirror; the application injected and served the changed tsjs normally.

A separate operator-config run used the configured publisher origin and external Prebid bundle, without manual requestBids calls. Automatic native capture was observed on the Fastly homepage and an Axum article; captured IDs matched the native getter and unchanged samples did not rewrite the cookie. Some repeated publisher runs encountered external bundle/origin timeouts or absent third-party identity setup, so these observations do not qualify third-party reliability.

Subsequent deployed Fastly staging verification passed six controlled cookie-provider scenarios: provider input, replacement, opt-out, restoration, and persisted-ID reuse after removing the provider input, carried mirror and native capture cookies. The server reissued the mirror and the actual deployed Prebid bidder consumer received the expected ID without mirror echo. The controlled bidder returned no HTTP requests; these checks do not qualify live vendor APIs, bidder HTTP delivery or other provider kinds. The served shim matched the reviewed build; the backend version header identified the branch rather than an exact commit. Local Viceroy still lacks the JA4 metadata required for normal provider activation, and Axum does not support enabled providers.

Checklist

  • Feature PR: spec linked above, ending in a review log of two or more agent review rounds
  • Changes follow AGENTS.md conventions
  • No unwrap() added in production code
  • Uses log macros (not println!)
  • New code has tests
  • No secrets or credentials committed

@prk-Jr prk-Jr self-assigned this Nov 17, 2026
@prk-Jr prk-Jr linked an issue Nov 18, 2026 that may be closed by this pull request
1 task
The merge applied without conflicts. The Prebid integration config keeps
this pull request's mode field next to the base's changes, and the
example config, the Prebid guide and the tsjs Prebid sources take both
sides unchanged. The server mirror cookie the identity mode reads is the
same name and envelope in the base, so no code needed to change.
@aram356

aram356 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration chain (#1608), this PR's base #1489 was ported onto #1506's EdgeZero cutover and #1526's async store, so af8da5a28 merges #1489's new head a7262c7db. It merged with no conflicts and no extra edits: the mirror cookie name and envelope (__Host-ts-eids-mirror, {"v":1,...}) are unchanged in the port.

Checked locally at af8da5a28: cargo fmt, all eight clippy aliases and the core build-digest clippy, scripts/lint-wasm-clock.sh, test-fastly, test-fastly-reuse, test-axum (64), test-cloudflare (66), test-spin (89), parity (33), build-digest (10), host CLI tests (972), docs and Markdown format, and the URL-host lint against #1489, all passing (test-fastly 4,064), plus vitest (3,341), JS format and lint, and build-all.mjs.

Takes #1489's new head e4ae9ca, which brings #1506's repin of
EdgeZero to rc/identity at 9d02d7b3. The merge is clean, and this PR's tree
changes only by that repin.
@aram356 aram356 mentioned this pull request Nov 19, 2026
20 of 21 tasks
Takes #1489's new head 8623c4e. The merge is clean, and this PR's tree
changes only by the commits #1489 and the PRs below it added since
e4ae9ca.
aram356 added a commit that referenced this pull request Nov 20, 2026
#1620 (4de6864) adds the identity-only mode to the Prebid integration
(#1594) and merged #1489's new head, so this merge is clean.
@aram356

aram356 commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration chain (#1608), 4de68646d merges #1489's new head 8623c4e3b, which brings dhruv8sh's latest #1487, #1488 and #1489 commits. The merge is clean, and this PR's tree changes by exactly those commits. rc/identity takes it as a plain merge, and its full checks cover this head.

This brings in 1f054c6 from #1488, which forwards ortb2.user.ext.eids
from the Prebid config into the auction EIDs, and a99dd66, a62601b,
d1eb75f and 394892b from #1489, which cap mirrored UID expiry at 30
days from the UTC day start and pass the request time into finalize.

Prebid shim: syncPrebidEidsCookie keeps this PR's single payload check
with change-only writes and stale-capture clearing, since both sides
already removed the getUserIdsAsEids guard. collectAuctionEids now reads
ortb2.user.ext.eids from the global Prebid config in both modes. Identity
mode still writes mirrored IDs only into the request-local ortb2, so they
never reach the global config or the ts-eids capture.

Artifact test: the merged shim measures 55,336 characters, so the size
guard keeps this PR's 55.5 KB limit, and its comment now names the
ortb2.user.ext.eids forwarding.

It also brings b2d4bfd from #1488, which records the known UID hashes
on lookup results with a setter, so the provider IDs the write planner
logs are not derived from them.

The base now also carries #1506's repin of EdgeZero to rc/identity at
d063a8e7 and its merge of main's Fastly SDK 0.13.3 upgrade (#1671): fastly
0.13.3, url 2.5.9 and Viceroy 0.22.0.
Takes #1489's new head 8e5642b, which carries #1506's repin of EdgeZero to
rc/identity at 459bd27d (42e0c46): PR 275 at 0e2a58ae, the stack's test
fixes and EdgeZero 536's bounded record update, RecordHandle::update.

The merge is clean.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#1608), I pushed abbf63f15, a merge of #1489's new head 8e5642b36, which brings #1506's repin of EdgeZero to rc/identity at 459bd27d (42e0c46c7): EdgeZero #275 at 0e2a58ae, the EdgeZero stack's test fixes and EdgeZero #536's bounded record update, RecordHandle::update. The merge had no conflicts.

@dhruv8sh dhruv8sh 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.

Summary

This PR adds a PrebidMode setting on the Rust side. It defaults to auction and can be set to identity, and the value is passed into the injected browser config. In identity mode the JS shim:

  • leaves bidders, ad units and GPT refresh alone;
  • merges the __Host-ts-eids-mirror EIDs into each request's own ortb2, skipping IDs that are already present, without changing the publisher's objects;
  • polls native IDs every second (and on visibility changes and BFCache restores), rewriting the ts-eids cookie only when the value has changed.

Auction-mode setup now runs after the identity early return and behaves the same as before. One gap remains: the module installs the GPT refresh handler based only on the server-injected mode. That breaks the promise that identity mode leaves GPT untouched when a publisher picks the mode through the JS config.

Cross-cutting / body-level findings

  • 🔧 GPT refresh handler ignores the JS-configured mode — crates/trusted-server-js/lib/src/integrations/prebid/index.ts:482 (this line isn't in a diff hunk, so the finding lives here). The check reads only the server-injected window.__tsjs_prebid.mode. But PrebidNpmConfig.mode is public and can override the injected value (config?.mode ?? injected?.mode). Two cases break:

    • A publisher who sets identity mode only through installPrebidNpm({ mode: 'identity' }) still has GPT refresh taken over by the auction refresh handler. That goes against the promise that identity mode leaves GPT untouched.
    • If the server injects identity and the JS call passes mode: 'auction', no refresh handler is installed at all.

    Proposed fix: install (or tear down) the refresh handler based on merged.mode inside installPrebidNpm. Alternatively, document that mode can only be set from the server and drop it from PrebidNpmConfig. Either way, add a test for the JS-config path.

  • 👍 Defensive mirror parsing — EID mirror parsing is defensive. It requires unpadded URL-safe base64, which matches the server's URL_SAFE_NO_PAD encoding.

  • 👍 Thorough tests — the new identity-mode behaviour has thorough test coverage.

CI Status

  • integration tests: PASS
  • integration tests (Fastly EC lifecycle): PASS
  • vitest: PASS
  • format-typescript: PASS
  • format-docs: PASS
  • cargo check/build/test (spin native + wasm32-wasip1): PASS
  • Fastly response diff script: PASS
  • worker-deadlines (spin): PASS
  • cargo test (axum native): PASS
  • cargo test (cross-adapter parity): PASS
  • cargo test: PASS
  • cargo test (ts CLI, native) (ubuntu-latest): PASS
  • browser integration tests: PASS
  • trace runtime and browser acceptance: PASS
  • CI Node pin guard: PASS
  • cargo check (cloudflare native + wasm32-unknown-unknown): PASS
  • cargo fmt: PASS
  • worker-deadlines (cloudflare): PASS
  • HTML EOF runtime (Fastly): PASS
  • release scripts: PASS
  • docs-proposal scripts: PASS
  • ts dev lint domains (changed lines): PASS
  • CLAUDE.md symlink guard: PASS
  • prepare integration artifacts: PASS
  • cargo test (ts CLI, native) (macos-latest): PASS

The shim chose identity or auction hooks from the merged JS and injected
config, but decided whether to wrap GPT refresh from the injected value
alone, so a JS `mode` could leave the two disagreeing. The shipped shim
self-installs without arguments, so the JS field had no real caller.
Drop `mode` from PrebidNpmConfig and read it only from the injected
config, and add tests with a stable pubads object that observe whether
the refresh handler is installed.
@prk-Jr

prk-Jr commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Addressing dhruv8sh's review: the GPT refresh handler didn't follow the JS-configured mode.

Fixed in c3b0c84, following your second option: mode is now set by the server only.

  • I removed mode from PrebidNpmConfig. installPrebidNpm now reads it only from window.__tsjs_prebid, the same value the module-load refresh decision reads, so the hooks and GPT refresh can't disagree.
  • Why I didn't keep a JS override: the shipped shim installs itself at load with no arguments, and the page sentinel turns any later installPrebidNpm(config) into a no-op. The JS mode had no real caller. In the shipped bundle neither of your two cases could happen, but the API said it could. The PR description and the guide already say the mode comes from TOML only.
  • New tests in identity.test.ts (server-owned Prebid mode) use a stable pubads() object. Auction mode wraps refresh, identity mode leaves it as it was, and a mode passed through JS no longer changes which hooks get installed. The JS-config test failed before the fix.
  • Negative control: I made the module-load path install the refresh handler unconditionally. Only the new identity test failed. The existing "leaves … GPT … untouched" test still passed, because its fixture returns a new pubads object on every call, so a wrapped refresh was invisible to it.

Checked locally on Node 24.12.0 (the repo pins 24.20.0): vitest 3352 passed with 1 skipped, plus JS format, eslint, build-all.mjs and cargo test -p trusted-server-js (11 passed). CI for the new head hasn't been checked yet.

@prk-Jr
prk-Jr requested a review from dhruv8sh November 27, 2026 13:32

@dhruv8sh dhruv8sh 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.

I'm approving this PR. It adds a server-owned mode setting (auction by default, or identity) to the Prebid integration. Identity mode does four things:

  • It wraps requestBids to merge the __Host-ts-eids-mirror cookie into the request-local ortb2.user.ext.eids, without mutating the publisher's objects.
  • It skips the bidder, ad-unit and GPT-refresh hooks.
  • It samples native IDs into ts-eids every second, pausing and resuming around back/forward-cache navigation.
  • It only rewrites the cookie when the value changes.

I found no blocking issues.

  • Validation and dedup: the mirror parser checks the length cap, the charset, strict UTF-8, v, atype and exp before using anything. Deduplication covers both the global and the request EID locations.
  • Mode can't be overridden from JS: only the server-injected config sets the mode, and the refresh-handler decision reads the same value.
  • Auction mode unchanged: syncPrebidEidsCookie() with no argument behaves as before.
  • Tests: the new tests cover lifecycle, blocked cookies, malformed mirrors and expiry.

One non-blocking item: the 1-second setInterval runs for the whole life of every identity-mode page, and each tick calls getUserIdsAsEids and reads document.cookie, including while the tab is hidden. Pausing it while document.visibilityState === 'hidden', or backing off once IDs are stable, would cut the background cost. It doesn't affect correctness. The shim size guard going from 53 KB to 55.5 KB is justified.

Takes #1489's new head e6c0e51, which carries #1506's repin of EdgeZero to
rc/identity at 1619078a (8edc50e), a revert that removes EdgeZero 522
(portable Fastly record providers) and 524 (outbound mTLS client
identities).

The merge is clean.
@aram356

aram356 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#1608), I pushed 78c2aed5a.

Takes #1489's new head e6c0e51, which carries #1506's repin of EdgeZero to rc/identity at 1619078a (8edc50e), a revert that removes IABTechLab/edgezero#522 (portable Fastly record providers) and IABTechLab/edgezero#524 (outbound mTLS client identities).

The merge is clean.

This merge sits on your new commit c3b0c8410, which rc/identity does not include yet. #1622 merges #1620, and taking c3b0c8410 there conflicts in crates/trusted-server-js/lib/src/integrations/prebid/index.ts: #1622 adds the EC-route setup just above the if (merged.mode === 'identity') line that c3b0c8410 changes to injected?.mode. Resolving that in #1622's merge of #1620 brings the commit into the next round.

@ChristianPavilonis ChristianPavilonis 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.

Reviewed #1620 against the live feat/s2s-eid-collection-providers base at e6c0e51af. I’m requesting changes for the native-only capture contract and the publisher request compatibility issue. The inline comments distinguish blockers from follow-ups.

The shipped shim was exercised in memory with a generated Prebid 10.26 bundle in JSDOM, using synthetic IDs and a controlled bidder. I did not rerun real Chrome or deployed adapter checks.

Capture only native IDs in identity mode, preserve publisher User Sync policy,
and read mirrors after Prebid admits requests while retaining its hook API.
Retry replaced consent APIs without repeatedly subscribing to unchanged CMPs.

Pause hidden-document polling and document fail-closed startup clearing.
Cover these paths with native capture and generated Prebid regressions.
@prk-Jr
prk-Jr marked this pull request as draft December 1, 2026 09:38
@prk-Jr
prk-Jr marked this pull request as ready for review December 1, 2026 10:00
PR #1489's new head brings its reserved generated pull-sync provider ID prefix, plus the cascaded owner review fixes from #1525, #1526 and #1488. The merge is clean.

@ChristianPavilonis ChristianPavilonis 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.

Re-review of 78c2aed5a..7f4e59565 (one commit).

All seven items from my last review are addressed, along with dhruv8sh's hidden-tab polling note. R4 (the first empty sample clearing a valid carried cookie) is handled as a documented fail-closed choice; I'd still argue the other way, but I'm fine with it as written.

Approving. One naming nit inline, please take care of it before merging.

PR #1489's new head brings wave B: #1506's merge of main ab5c24f (#1501, js_asset_proxy rewriter ordering) and its repin of EdgeZero to rc/identity 8a73c0978806, carried up through the chain. The merge is clean. Cargo.lock changes only the 10 EdgeZero package sources, now at 8a73c097; the codegen crate's nested Cargo.lock is unchanged.
@aram356

aram356 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Round 12 identity realignment: rc/identity is now at db7dce634, and EdgeZero is pinned to its rc/identity at 8a73c097. This branch fast-forwarded from 7f4e59565 to 63d4be62d:

Each merge message says what it carries and how any conflict was resolved.

PR #1489's new head brings #1506's move of the five auction endpoint test requests from test-publisher.com to publisher.example.com, for the URL-host lint. The merge is clean.
aram356 added a commit that referenced this pull request Dec 2, 2026
PR #1620's new head brings #1506's move of the five auction endpoint test requests from test-publisher.com to publisher.example.com, for the URL-host lint. The merge is clean.
prk-Jr and others added 2 commits December 2, 2026 21:33
PR #1489's new head brings #1506's repin of EdgeZero to rc/identity ef5cbf30, which renames Fastly backends to ez_b31v2_* and moves the yanked pin-project-lite, chacha20 and spin. The merge is clean. Cargo.lock changes only the EdgeZero package sources (now ef5cbf30) and the yanked pin-project-lite, chacha20 and spin; the codegen crate's nested Cargo.lock is unchanged.
@aram356

aram356 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Round 15 identity realignment: rc/identity is now at 391a08578, and EdgeZero is pinned to its rc/identity at ef5cbf308. This branch fast-forwarded from 827f0e38b to 98a56e855:

#1622 now merges this branch's new head, including 827f0e38b, so the parameter rename reaches the endpoint-switch stack.

Each merge message says what it carries and how any conflict was resolved.

@prk-Jr

prk-Jr commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Fixed mirror/native EID overlap in 4938660f3. Native User ID enrichment appends IDs after the mirror merge, so identity mode now removes exact repeated UID data at client bidder delivery and in the final PBS HTTP body before optional gzip. Different IDs, atype values and EID/UID metadata remain distinct; publisher inputs and native-only capture are preserved.

Verification: JS build, lint and format pass, with 3,387 tests passing. Generated Prebid 10.26 and isolated 10.28 caller probes cover cold/warm initialization, normal/gzip PBS delivery and consent redaction. An early getter-only filter still fails the cold case; a client-only fix still fails both PBS wire cases. All required local gate groups passed, including the committed PR domain scan.

Supplemental browser verification attached the candidate listeners to the existing Prebid 10.28 runtime and removed identical duplicates from actual outgoing requests. This was temporary local instrumentation; the AWS deployment still uses its previous build. Hosted CI is pending for this commit; no merge-readiness claim is made.

PR #1489's new head brings #1487's change that strips `ts-eids` from publisher-origin requests unless the operator opts in. The merge is clean.
@aram356

aram356 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Round 17 identity realignment: rc/identity is now at 0ed862633, and EdgeZero stays pinned to its rc/identity at ef5cbf308. This branch fast-forwarded from 4938660f3 to 6491a9eae:

Each merge message says what it carries and how any conflict was resolved.

@aram356

aram356 commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Merged #1614's /_ts/ local answers (48930c270) into this branch as ad81e4c82, on top of 6491a9eae.

Trusted Server owns the /_ts/ namespace (#1740). A request for /_ts or any /_ts/ path that no route handles now gets a local 404 on Fastly, Axum, Cloudflare and Spin, and never reaches the publisher origin. The path is matched after percent-decoding. Paths outside the namespace, such as /_tsx or /articles/_ts/x, still go to the publisher origin, and every routed /_ts/ path answers as before.

This merge takes #1489's new head (8c5a63ff5), which carries 48930c270 and nothing else new to this branch. It was clean.

Checks on this head: no conflict markers; cargo fmt --all -- --check passes; the merge adds exactly #1614's change to this branch's files; it merges cleanly with every lower head in its stack. rc/identity (e72407155) passed the full CI gate list with the change.

This branch has not been deployed

No deployments
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.

Identity-only tsjs mode

4 participants