Skip to content

feat(training-agent): declare account.stable_account_id on v6 tenant routes - #8124

Merged
bokelley merged 3 commits into
mainfrom
bokelley/stable-account-id-training-agent
Oct 12, 2026
Merged

bokelley merged 3 commits into
mainfrom
bokelley/stable-account-id-training-agent

Conversation

@bokelley

@bokelley bokelley commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #8123 (merged), which added the account.stable_account_id capability. Now targets main. This PR makes the training agent conform to it, so media_buy_seller/stable_account_id grades against a real implementation in CI.

The training agent already returned account_id from sync_accounts and accepted { account_id } on account-scoped tasks. However, it stored state under separate session keys for { account_id } and for the natural key. Once both forms had been used, each reference saw only its own buys, which violates "the same account".

  • One partition per account. sessionKeyFromArgs maps a known account_id to its natural AccountRef. The lookup is limited to the authenticated caller's own accounts, through a request-scoped context that the v6 tenant router enters.
  • Rehydration across machines. Accounts missing from the per-process store are reloaded from their durable reporting binding. Seller-managed control jobs re-enter the context and rehydrate too.
  • Capability declared only where it holds. The v6 tenant routes declare it. Legacy /mcp, /<tenant>/mcp-strict* and the 3.0 compat surface don't declare it and keep the opaque a:<id> partition, because the alias can't be guaranteed across machines on the v5 monolith.
  • Static credentials. One helper applies the public shared-brand partition rule to account_id references, for both buyer reads and controller seeds.
  • Hardening. seed_account refuses the built-in compliance fixture ids (acc_luma_shared, acc_pagination_integrity_1..3). This closes a path where one principal could redirect every principal's traffic for a fixture id.

A focused review checked cross-principal isolation before the hardening above. It found no new read exposure: an account_id reaches only the partition its natural key already reached. The alias-hijack and partition-mismatch findings from that review are fixed here.

Known limitations (pre-existing, not changed)

  • A second static principal can still read another principal's buys by sending that principal's account_id. This comes from an existing get_media_buys fallback that matches identical id strings across sessions, not from the alias. In the public sandbox, buys are already shared by brand.
  • Existing open:a:<id> session data is not migrated. Idempotency is still keyed by the reference form.

Test plan

  • server/tests/unit/training-agent-stable-account-id.test.ts (9 tests). Disabling each fix in turn (principal scoping, controller helper, ledger scan) makes the matching test fail.
  • Training-agent, account, controller and reporting unit tests: 1919 passed (one transient boot timeout that re-ran clean)
  • npm run typecheck; pre-commit hook (full server unit suite)
  • Sales tenant storyboards: stable_account_id 6P, account_change_feed 17P, governance_agent_binding_acceptance 5P, unprovisioned_account_reference 3P/1S, frequency_cap_capability_updates 13P, media_buy_frequency_cap_updates 17P, sales_non_guaranteed 12P
  • 3.0 compat sales: 39/39 clean, 235 steps passed
  • Full storyboard matrix: CI (training-agent-storyboards.yml). It timed out locally on the sandbox, so the pre-push matrix was skipped with ADCP_SKIP_STORYBOARD_MATRIX=1.

🤖 Generated with Claude Code


Open workspace in Conductor

@bokelley
bokelley force-pushed the bokelley/operator-auth-account-lifecycle branch from f77d457 to 2dbb389 Compare October 10, 2026 18:31
@bokelley
bokelley force-pushed the bokelley/stable-account-id-training-agent branch from e1bf3ff to e3a1e8c Compare October 10, 2026 18:31

@aao-secretariat aao-secretariat Bot left a comment

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.

Ladon verdict: Approve

Approve — training-agent stable_account_id, no blocking findings.

Checked: account_id→natural-key aliasing is principal-scoped (runWithAccountIdAliasScope + request-owned resolver), the capability is declared only on v6 tenant routes that enter the scope, cross-principal write isolation holds (verified against findAccountByIdAcrossSessions principal prefix and the dedicated 9-test suite). Non-protocol server change — no changeset correctly required. No schema/docs/dist surface touched; seed_account fixture-id hardening closes the alias-hijack; rehydrate is awaited only on the cold path.

Medium findings

  • server/src/training-agent/account-handlers.ts:590 — Silent swallow in rehydrateAccountById hides cross-machine durability failures (bare catch on resolveReportingAccountDurably with no alerting; a DB hiccup on a replacement machine silently reverts an { account_id } reference to its opaque partition). Worth a follow-up but single medium on a cold path — does not gate.

No critical/high findings, high_risk false, gated_paths false, no author team gate, no prior decision. One medium finding falls through to row 9.

Follow-up (non-gating): full storyboard matrix (training-agent-storyboards.yml) is unchecked in the test plan and deferred to CI; primary path is covered by the dedicated suite and sales storyboards.

Medium findings

  • server/src/training-agent/account-handlers.ts:590 — Silent swallow in rehydrateAccountById hides cross-machine durability failures

@aao-secretariat aao-secretariat Bot left a comment

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.

Ladon verdict: Approve

Approve — server-only training-agent change, no blocking findings.

This PR touches only server/src/training-agent/** plus a new unit test — no static/schemas/source/**, docs/**, dist/**, migrations, or protocol surface. So changeset requirements, schema↔docs coherence, oneOf discriminator, artifact immutability, and 3.1.x patch-eligibility gates do not apply.

Reviewer validated the stable-account-id alias design: runWithAccountIdAliasScope is per-request ALS, the resolver is principal-scoped, sessionKeyFromArgs recursion terminates, cross-principal isolation is confirmed by test (an intruder write stays in its own opaque partition), and rehydration ordering is safe. The deferred full storyboard matrix is acceptable since the primary path is covered by 9 unit tests + focused storyboards.

Medium findings

  • server/src/training-agent/account-handlers.ts:589 — rehydrateAccountById swallows durable-read error with no observability

Gates: high_risk false; gated_paths false; no no-auto-approve team match; no prior decision. With a single medium finding (not in data-loss/schema/infra category, no high-risk modification), rows 1–8 do not fire — this falls through to row 9 (approve). Recommend adding at least a warn-level log at account-handlers.ts:589 in a follow-up for observability.

Medium findings

  • server/src/training-agent/account-handlers.ts:589 — rehydrateAccountById swallows durable-read error with no observability

@bokelley
bokelley force-pushed the bokelley/stable-account-id-training-agent branch from e3a1e8c to a5cca78 Compare October 10, 2026 20:31

@aao-secretariat aao-secretariat Bot left a comment

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.

Ladon verdict: Approve

Approve — subsequent pass on the stable_account_id conformance change; net-neutral with one carried-over Medium, no blocking findings.

This is a follow-up to a prior approve. The alias/partition logic, cross-machine rehydration, capability gating, and the 377-line test file are coherent and well-covered; the seed_account fixture guard is clean hardening. No schema/docs surface touched (server/** only), so no changeset/oneOf/immutable-artifact concerns apply. No new High/Critical findings.

Medium findings

  • server/src/training-agent/account-handlers.ts:585 — rehydrateAccountById swallows the durable-read (getPool().query) error with no observability, silently forking an account_id into its opaque partition on a transient DB failure. (Same finding as the prior run at :589; still worth a human's eye but non-blocking.)

Decision path: no critical/high (rows 1 skip); gated_paths false and review_decision APPROVED (rows 2 skip); high_risk false (rows 3,5 skip); the single Medium is not data-loss/schema/infra category (row 4 skip); prior decision was approve not escalate (row 6 skip); no no-auto-approve team match (row 7 skip); only 1 Medium so <3 (row 8 skip) → row 9 approve.

Medium findings

  • server/src/training-agent/account-handlers.ts:585 — rehydrateAccountById swallows durable-read error with no observability

@aao-secretariat aao-secretariat Bot left a comment

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.

Ladon verdict: Approve

Approve — prior Medium resolved, no new findings.

This is a subsequent review following a prior approve. The single prior Medium (rehydrateAccountById swallowing a durable-read error without observability at account-handlers.ts:585/589-593) has been addressed: the bare catch now emits a structured pino warn (err + accountId), with correct logger wiring and pino call shape. Best-effort early-return behavior is unchanged.

No new findings in this run. No critical/high findings. gated_paths is false and review_decision is APPROVED, so no path gate applies. high_risk is false. No no-auto-approve team match. Rows 1–8 do not fire; outcome falls through to row 9 (approve).

Checked: no schema/docs surface touched (changes are confined to server/src/training-agent/** TS + a unit test), so changeset-scope, oneOf-discriminator, immutable-artifact, and schema↔docs coherence gates are not implicated.

@bokelley
bokelley force-pushed the bokelley/operator-auth-account-lifecycle branch from 1d553fa to 3f6da30 Compare October 12, 2026 09:53
@bokelley
bokelley force-pushed the bokelley/stable-account-id-training-agent branch from f5ba52f to 81954a5 Compare October 12, 2026 09:53
@bokelley
bokelley force-pushed the bokelley/operator-auth-account-lifecycle branch from 3f6da30 to 3b39cb2 Compare October 12, 2026 09:57
@bokelley
bokelley force-pushed the bokelley/stable-account-id-training-agent branch from 81954a5 to d3390a9 Compare October 12, 2026 09:57

@aao-secretariat aao-secretariat Bot left a comment

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.

Ladon verdict: Approve

Approve — clean pass, no blocking or medium findings.

Checked:

  • Multi-tenant isolation holds: the resolver (account-handlers.ts:522 findAccountByIdAcrossSessions principal-prefix scan) never crosses principals; the cross-principal test confirms a second static credential's {account_id} write stays in the opaque partition.
  • New rehydrateAccountById control flow (account-handlers.ts:L96-L108) fails closed — returns on already-present, compliance-fixture, or durable-read error, reconstructing only from a natural binding. Warn-only on durable-read failure is consistent with the module's no-Sentry convention; opaque-partition fallback is pre-existing behavior.
  • reporting-reliability.ts ledger scan matches by id and returns only natural refs; cache idKey aligns with the account_id scope lookup.
  • Capability declared only on v6 tenant routes; omitted on v5 /mcp, /mcp-strict*, and frozen 3.0 surface — each verified by a test.
  • App-only server change, no protocol-surface edit, no changeset required. Not Breaking-class. review_decision APPROVED.

No gated paths, no no-auto-approve team match, high_risk false. Prior decision was approve; no new findings. Falls through to decision table row 9.

aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Oct 12, 2026

@aao-secretariat aao-secretariat Bot left a comment

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.

Ladon verdict: Approve

Approve — clean pass, no blocking or medium findings.

Server-only TypeScript implementing the already-specified account.stable_account_id capability (schema/docs/changeset landed in the base ref). No static/schemas/source/**, dist/**, docs/reference, or changeset surface is touched, so schema↔docs coherence, changeset scope, oneOf discriminator, and artifact-immutability gates do not apply. The account_id→natural-ref alias is principal-scoped and fail-closed at every hop (ALS principal + findAccountByIdAcrossSessions filter; unowned ids keep their opaque partition), the sessionKeyFromArgs aliasing recursion terminates in one hop, the reporting-reliability by-id scan mirrors the DB lookup, and the compliance-fixture seed guard closes an overwrite footgun. Cross-principal isolation and rehydration are tested.

Gate checks: gated_paths false; review_decision APPROVED; high_risk false; no no-auto-approve team match; prior decision was approve with no findings. No critical/high/medium findings — decision table rows 1–8 do not fire, falling through to row 9.

Base automatically changed from bokelley/operator-auth-account-lifecycle to main October 12, 2026 10:43
@bokelley
bokelley dismissed aao-secretariat[bot]’s stale review October 12, 2026 10:43

The base branch was changed.

bokelley and others added 2 commits October 12, 2026 10:43
…routes

The training agent now honours the stable_account_id contract on its v6
tenant routes: { account_id } and the buyer-declared natural key resolve
to one session partition, so state written under either reference is
visible under both.

- sessionKeyFromArgs maps a known account_id to its natural AccountRef,
  resolved only within the authenticated caller's accounts via a
  request-scoped context entered by the v6 tenant router. Outside that
  context (legacy /mcp, mcp-strict, 3.0 compat) ids keep their opaque
  partition, and those surfaces do not declare the capability.
- Accounts missing from the per-process store are rehydrated from their
  durable reporting binding, so the alias holds across machines.
- One helper applies the public static-credential shared-brand rule to
  account_id references for both buyer reads and controller seeds.
- seed_account refuses built-in compliance fixture ids.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A transient durable-read failure in rehydrateAccountById left the
account_id on its opaque partition with no signal. Warn with the error
and account id so a split is observable.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@bokelley
bokelley force-pushed the bokelley/stable-account-id-training-agent branch from d3390a9 to ac82a2f Compare October 12, 2026 10:43

@aao-secretariat aao-secretariat Bot left a comment

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.

Ladon verdict: Approve

Approve — clean pass, server-only training-agent change.

This PR implements account.stable_account_id in the training-agent: an AsyncLocalStorage-scoped, principal-bound alias (state.ts) mapping { account_id } to the natural session partition, with durable rehydration (account-handlers.ts rehydrateAccountById) for cross-machine reads. The reviewer verified multi-tenant isolation holds — the resolver reads the principal from the authenticated ALS scope rather than wire args, and findAccountByIdAcrossSessions is principal-scoped. The alias is correctly gated off on v5/mcp, mcp-strict, and frozen 3.0 surfaces (declared only at router.ts:1051), the reporting ledger id-lookup mirrors the DB branch, and the seed guard blocks compliance-fixture hijack. A 377-line test covers provisioning stability, cross-route, rehydration, cross-principal isolation, and scope boundaries.

No critical/high/medium findings. No schema/docs/changeset surface touched (server-only, so no changeset or schema↔docs coherence obligations apply). high_risk is false, gated_paths is false, no no-auto-approve team match. Prior decision was also approve with no findings.

Decision table: rows 1–8 do not fire (no blocking findings, no gated paths, no high-risk deletion/modification concern, no team gate, fewer than three medium findings — in fact zero). Falls through to row 9 → approve.

aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Oct 12, 2026

@aao-secretariat aao-secretariat Bot left a comment

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.

Ladon verdict: Approve

Approve — subsequent pass on PR #8124 (server implementation of account.stable_account_id).

This is a server-only change (no static/schemas/source/**, docs, dist, or changeset-scope surface touched), so none of the schema/changeset/oneOf/immutability spec gates apply. high_risk is false, gated_paths is false, no no-auto-approve team match.

Checked and confirmed by the reviewer: multi-tenant isolation (alias + rehydrate are principal-scoped; test verifies a second principal's id does not alias), capability-vs-behavior coherence (stable_account_id gated to the same !==3.0 branch running withStableAccountIdScope; 3.0 and v5 omit both), alias recursion termination, and preservation of the trusted partition hint.

Medium findings (1):

  • server/src/training-agent/account-handlers.ts:602 — rehydrateAccountById fails open on a transient durable read; a write keyed by { account_id } can strand in the opaque a:<id> partition, invisible to later aliased reads.

A single medium finding with no critical/high and no escalation trigger falls through to row 9 → approve. The prior decision was also approve; this pass adds one new medium on freshly reviewed code (new medium findings on subsequent passes are not penalized and do not change the threshold). Worth a human eye on the rehydrate-failure split at merge time, but non-blocking.

Medium findings

  • server/src/training-agent/account-handlers.ts:602 — rehydrateAccountById fails open on transient durable read; writes strand in opaque partition

…ead the binding

On a cold process, a transient durable-read failure left the account_id on
its opaque partition, so a write such as create_media_buy keyed by
{ account_id } was stranded where later natural-partition reads never see
it. Return a transient SERVICE_UNAVAILABLE instead so the buyer retries.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@aao-secretariat aao-secretariat Bot left a comment

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.

Ladon verdict: Approve

Approve — prior Medium resolved, no new findings.

This is a subsequent review following a prior approve decision. The delta resolves the previously flagged Medium: rehydrateAccountById now fails closed on a transient durable-read failure — throwing AdcpError('SERVICE_UNAVAILABLE', { recovery: 'transient' }) (account-handlers.ts:111-114) rather than warn-and-return, so a write can no longer strand in the opaque partition. Error construction matches the established repo pattern (v6-sales-platform.ts:1877) and the AdcpError import is correct. A new test covers the throw branch.

Checks applied:

  • No critical/high/medium findings in this run (row 1, 4, 5, 6 N/A).
  • gated_paths: false (row 2 N/A); high_risk: false (rows 3, 5 N/A).
  • No no-auto-approve team match (row 7 N/A).
  • Fewer than three medium findings — zero (row 8 N/A).
  • Diff is confined to server/src/training-agent/** and unit tests; touches no static/schemas/source/**, dist/**, docs, or changeset-governed surface, so schema↔docs, changeset-scope, oneOf, artifact-immutability, and breaking-class gates do not apply.

Falls through to row 9 → approve.

@bokelley
bokelley merged commit 127bec4 into main Oct 12, 2026
54 checks passed
@bokelley
bokelley deleted the bokelley/stable-account-id-training-agent branch October 12, 2026 12:11
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.

1 participant