Skip to content

fix(compliance): thread cross-phase generated IDs through context in storyboards - #7731

Merged
bokelley merged 1 commit into
mainfrom
fix/storyboard-cross-phase-generated-ids
Sep 29, 2026
Merged

bokelley merged 1 commit into
mainfrom
fix/storyboard-cross-phase-generated-ids

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

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/sdk storyboard runner scopes $generate aliases 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: a context_outputs generator 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/sdk 14.0.0-rc.49)

  • dist/lib/testing/storyboard/context.js: deepReplace resolves $generate:(uuid_v4|opaque_id)#alias through getAliasCache(context), a WeakMap keyed on the context object.
  • dist/lib/testing/storyboard/runner.js: each phase starts with context = { ...context } and does not call forwardAliasCache. Step-to-step updates inside a phase do forward the cache.
  • Result: an alias is stable within a phase (both check_governance steps 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_outputs generators 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 is account_change_feed, which #7716 already fixes. No other instances exist.

Storyboard Alias Phases
media_buy_seller/governance_conditions governance_conditions_create_media_buy intent_negotiation → governed_execution
governance_spend_authority governance_spend_authority_conditions_create_media_buy governance_check_conditions → create_buy_with_conditions
brand_rights/governance_approved rights_governance_approved_acquire authorization → authorized_grant
creative_transformers/governance_approved creative_governance_approved_build authorization → authorized_build
signal_marketplace/governance_approved signal_governance_approved_activate authorization → authorized_activation
media_buy_seller/account_change_feed account_change_feed_external_creative 4 phases (fixed in #7716)

In the five governance storyboards, the alias is the idempotency_key inside the check_governance intent payload. It must equal the governed mutation's idempotency_key so 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 on main without depending on #7716. Git merges identical hunks cleanly in either order. #7716's run-storyboards.ts change, which fixes that storyboard's webhook, is not included.

No assertions, timeouts, or required_tools changed. Generator steps:

  • get_products_brief in governance_conditions.
  • sync_plans in 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>

Storyboard Tenant Before (P/F/S) After (P/F/S)
governance_spend_authority governance 11 / 0 / 1 11 / 0 / 1
brand_rights/governance_approved brand 0 / 0 / 1 0 / 0 / 1
signal_marketplace/governance_approved signals 0 / 0 / 1 0 / 0 / 1
creative_transformers/governance_approved creative-builder 0 / 0 / 1 0 / 0 / 1
media_buy_seller/governance_conditions sales 0 / 0 / 1 0 / 0 / 1
media_buy_seller/account_change_feed sales 3 / 1 / 13 3 / 1 / 13

This runner can't reach the cross-phase step in any of these storyboards:

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 mirrors run-storyboards.ts's authenticated-caller patch, sets skip_controller_seeding (the SDK rejects agents together with controller seeding), and strips requires_capability. The tenants don't declare governance_enforcement, so without stripping it the steps would skip.

The idempotency_key values below are the ones the runner actually resolved into each request:

Storyboard Before: check_governance → mutation After: check_governance → mutation Counts before → after (P/F/S)
governance_spend_authority 98a972da… → 03927e77… ✗ 52cafd6e… → 52cafd6e… ✓ 3/2/0 → 3/2/0
governance_conditions b44fc429… → 805184e5… ✗ 9b51bc65… → 9b51bc65… ✓ 6/2/2 → 6/2/2
brand_rights/governance_approved d8f27dc5… → 49de2cdb… ✗ 99eb0ebd… → 99eb0ebd… ✓ 5/1/1 → 5/1/1
signal_marketplace/governance_approved 25aac745… → 502ce569… ✗ a8a291cc… → a8a291cc… ✓ 5/2/0 → 5/2/0
creative_transformers/governance_approved 855a42ed… → a2ddf4d6… ✗ 8e45643b… → 8e45643b… ✓ 5/1/0 → 5/1/0

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:

  • Token audience/issuer. The governed mutation is rejected with governance_context audience does not match this service or governance_context issuer does not match the registered governance authority. The training agent signs and verifies tokens against the production test-agent.adcontextprotocol.org identities, not the local tenant URLs. sync_governance also rejects a non-https governance URL, so the local harness can't register the local tenant.
  • No declared enforcement. The training-agent brand, signals, creative-builder, and sales tenants don't declare adcp.governance_enforcement.tasks with signed_context. So these storyboards are not_applicable against them in any real run.
  • Harness gaps. run-storyboards.ts has no multi-agent support. The SDK doesn't support agents together with controller_seeding: true.
  • governance_spend_authority, multi-agent only. get_capabilities routes to the sales tenant. There it fails its governance-specialism assertions, and the response schema check fails on governance_enforcement.tasks[3].modes having 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:

  • Walks every storyboard under static/compliance/source that has phases[].
  • Deep-walks each step. It counts only strings that are exactly a $generate:<kind>#<alias> token, the same full-string match the runner uses, so prose in narratives is ignored.
  • Fails with generate_alias_crosses_phases when one alias appears in two or more phases. The message lists every location per phase and names the context_outputs fix.
  • Same-phase reuse (for example, replay tests), distinct per-phase aliases, unaliased $generate:uuid_v4, and $context reads all pass.

Where it's wired:

  • build:compliance runs it as a fail-fast lint before building dist/, next to the other lint-storyboard-* gates.

  • tests/lint-storyboard-generate-phase-scope.test.cjs covers:

    • a source-tree guard;
    • positive and negative fixtures;
    • a check of the runner premise: an injectContext alias 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 into npm test and 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 main before this PR, the lint reports exactly the six instances above.

Validation

  • npm run build:compliance ✓
  • npm run test:schemas ✓
  • Every 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 status reports an adcontextprotocol patch.

🤖 Generated with Claude Code

…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]>

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

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