Repository navigation
fix(compliance): thread cross-phase generated IDs through context in storyboards - #7731
Conversation
…storyboards The @adcp/sdk storyboard runner scopes $generate:<kind>#<alias> values to one phase (adcp-client#1658): the alias cache is keyed on the context object, and each phase starts from a shallow copy that does not carry the cache. A later phase that reuses an alias mints a different UUID. Five storyboards reused an idempotency-key alias between the check_governance payload and the governed mutation in a later phase, so the executed request no longer matched the authorized payload: media_buy_seller/governance_conditions, governance_spend_authority, and the brand_rights, creative_transformers, and signal_marketplace governance_approved scenarios. Each now generates the key once with a context_outputs generator on the step before its first use and reads it as $context.<name>. account_change_feed gets the identical fix from #7716 so the new lint passes on its own. Add scripts/lint-storyboard-generate-phase-scope.cjs, run from build:compliance and from npm test (test:storyboard-generate-phase-scope), which fails when a $generate alias appears in more than one phase. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — clean fix for storyboard cross-phase generated IDs.
The PR resolves a real correctness bug: storyboards reused phase-scoped $generate:uuid_v4#alias tokens across phases, causing a governed mutation's idempotency_key to diverge from the check_governance payload that authorized it. The fix threads each value through a context_outputs generator placed before first use and reads $context.<name> thereafter, matching the established #7716 pattern. Reviewer verified generator placement precedes first use, added a lint (wired into build + npm test) with a source-tree guard and runner-premise test, and included a correct non-breaking patch changeset with no dist/schema/oneOf changes.
No Critical/High/Medium findings. No high-risk paths, no gated paths, no author-team gate, no prior decision. review_decision is REVIEW_REQUIRED but gated_paths is false, so row 2 does not fire. Falls through to row 9 → approve.
Summary
Some compliance storyboards minted an ID with
$generate:uuid_v4#<alias>in one phase and reused the same token in a later phase. The@adcp/sdkstoryboard runner scopes$generatealiases to a single phase (adcp-client#1658), so the later phase silently got a different UUID.This PR fixes every instance in
static/compliance/source/**using #7716's pattern: acontext_outputsgenerator on the step before the value's first use, then$context.<name>everywhere else. It also adds a lint so this bug class can't come back.How the runner scopes
$generate(checked in@adcp/sdk14.0.0-rc.49)dist/lib/testing/storyboard/context.js:deepReplaceresolves$generate:(uuid_v4|opaque_id)#aliasthroughgetAliasCache(context), aWeakMapkeyed on the context object.dist/lib/testing/storyboard/runner.js: each phase starts withcontext = { ...context }and does not callforwardAliasCache. Step-to-step updates inside a phase do forward the cache.check_governancesteps in the same phase got the same key). It is re-minted in every later phase. Values written to context carry over because of the spread.context_outputsgenerators are applied after the step's response. Their value is not visible to the same step's request. That's why each generator sits on the step before the first use, as in fix(compliance): unblock the account_change_feed storyboard webhook and drain steps #7716.Instances found
A scan of every
phases[].steps[]storyboard (210 files) for full-string$generate:<kind>#<alias>tokens reported exactly these six. All five suspects were real. The sixth isaccount_change_feed, which #7716 already fixes. No other instances exist.media_buy_seller/governance_conditionsgovernance_conditions_create_media_buyintent_negotiation→governed_executiongovernance_spend_authoritygovernance_spend_authority_conditions_create_media_buygovernance_check_conditions→create_buy_with_conditionsbrand_rights/governance_approvedrights_governance_approved_acquireauthorization→authorized_grantcreative_transformers/governance_approvedcreative_governance_approved_buildauthorization→authorized_buildsignal_marketplace/governance_approvedsignal_governance_approved_activateauthorization→authorized_activationmedia_buy_seller/account_change_feedaccount_change_feed_external_creativeIn the five governance storyboards, the alias is the
idempotency_keyinside thecheck_governanceintent payload. It must equal the governed mutation'sidempotency_keyso the executed request matches the payload the governance token authorized. Before this PR, the two keys always differed.account_change_feed: this PR carries #7716's YAML hunks byte-for-byte, so the new lint passes onmainwithout depending on #7716. Git merges identical hunks cleanly in either order. #7716'srun-storyboards.tschange, which fixes that storyboard's webhook, is not included.No assertions, timeouts, or
required_toolschanged. Generator steps:get_products_briefin governance_conditions.sync_plansin the other four.Context names are unique per storyboard, so the build's cross-file duplicate-idempotency-key lint doesn't fire.
Before / after
Documented single-tenant runner
Command:
ADCP_COMPLIANCE_DIR=dist/compliance/latest TENANT_PATH=<tenant> npx tsx server/tests/manual/run-storyboards.ts --storyboard-id <id>This runner can't reach the cross-phase step in any of these storyboards:
requires: [multi_agent], andrun-storyboards.tsnever configures anagentsmap. They skip withrequirement_unmet:multi_agent.governance_spend_authorityskipscreate_media_buyon the governance tenant (missing_tool).account_change_feedfails earlier, at its webhook step. fix(compliance): unblock the account_change_feed storyboard webhook and drain steps #7716 fixes that.Multi-agent proof run (local, not committed)
To exercise the cross-phase step, I ran each governance storyboard through
runStoryboard('', sb, { agents }). All training-agent tenants were served from one embedded server. The harness mirrorsrun-storyboards.ts's authenticated-caller patch, setsskip_controller_seeding(the SDK rejectsagentstogether with controller seeding), and stripsrequires_capability. The tenants don't declaregovernance_enforcement, so without stripping it the steps would skip.The
idempotency_keyvalues below are the ones the runner actually resolved into each request:98a972da…→03927e77…✗52cafd6e…→52cafd6e…✓b44fc429…→805184e5…✗9b51bc65…→9b51bc65…✓d8f27dc5…→49de2cdb…✗99eb0ebd…→99eb0ebd…✓25aac745…→502ce569…✗a8a291cc…→a8a291cc…✓855a42ed…→a2ddf4d6…✗8e45643b…→8e45643b…✓The cross-phase ID mismatch is gone: the mutation now sends the exact key the governance check authorized.
Remaining failures (unrelated follow-ups)
The pass/fail counts don't move because every storyboard still fails for reasons that have nothing to do with the key:
governance_context audience does not match this serviceorgovernance_context issuer does not match the registered governance authority. The training agent signs and verifies tokens against the productiontest-agent.adcontextprotocol.orgidentities, not the local tenant URLs.sync_governancealso rejects a non-httpsgovernance URL, so the local harness can't register the local tenant.adcp.governance_enforcement.taskswithsigned_context. So these storyboards arenot_applicableagainst them in any real run.run-storyboards.tshas no multi-agent support. The SDK doesn't supportagentstogether withcontroller_seeding: true.governance_spend_authority, multi-agent only.get_capabilitiesroutes to the sales tenant. There it fails its governance-specialism assertions, and the response schema check fails ongovernance_enforcement.tasks[3].modeshaving more than 1 item.account_change_feed. The webhook step fails locally; fix(compliance): unblock the account_change_feed storyboard webhook and drain steps #7716 fixes it.New lint guard
scripts/lint-storyboard-generate-phase-scope.cjs:static/compliance/sourcethat hasphases[].$generate:<kind>#<alias>token, the same full-string match the runner uses, so prose in narratives is ignored.generate_alias_crosses_phaseswhen one alias appears in two or more phases. The message lists every location per phase and names thecontext_outputsfix.$generate:uuid_v4, and$contextreads all pass.Where it's wired:
build:complianceruns it as a fail-fast lint before buildingdist/, next to the otherlint-storyboard-*gates.tests/lint-storyboard-generate-phase-scope.test.cjscovers:injectContextalias is stable on one context object and re-minted on a per-phase copy.It runs as
test:storyboard-generate-phase-scope, which is chained intonpm testand therefore into the sharded canonical CI stages. That keeps it compatible with ci(tests): run every test file in CI and guard against uncovered tests #7711's coverage guard.On
mainbefore this PR, the lint reports exactly the six instances above.Validation
npm run build:compliance✓npm run test:schemas✓test:storyboard-*suite ✓, including the new one.test:governance-conditions-storyboard,test:signal-governance-storyboard,test:compliance-source-authority,test:compliance-packaged-refs,test:compliance-snippets,test:doc-compliance-drift,test:webhook-emission-storyboard,test:test-script-registration,tests/lint-storyboard-idempotency-generated-context.test.cjs✓node scripts/check-changeset-protocol-scope.cjs origin/main✓;changeset statusreports anadcontextprotocolpatch.🤖 Generated with Claude Code