Skip to content

fix(training-agent): resolve controller-seeded rights grants for operator_unit accounts - #7730

Merged
bokelley merged 1 commit into
mainfrom
fix/update-rights-lifecycle-seed
Sep 29, 2026
Merged

bokelley merged 1 commit into
mainfrom
fix/update-rights-lifecycle-seed

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Fixes #7729

Summary

brand_rights/update_rights_lifecycle has failed on the training agent's /brand tenant since at least 2026-09-17. pause_seeded_grant returned REFERENCE_NOT_FOUND for the grant the controller had just seeded, and CI stayed green only because of the tenant floor. #7708 doesn't touch this path.

Root cause

#7601 isolated the storyboard's account with an operator_unit. @adcp/sdk's runner builds non-force_* controller calls from the test-kit account, so seed_rights_grant never receives that unit. The seed stores the grant under {brand, operator: buyer_domain, sandbox}. The buyer's update_rights reads {brand, operator, operator_unit, sandbox}, which is a different session. Temporary logging confirmed both accounts (details in #7729).

The update-rights-response.json message the audit flagged (/errors: must have required property 'errors') comes from the same failure. The success step's response_schema check graded the REFERENCE_NOT_FOUND body. That body is the SDK's thrown-AdcpError shape (adcp_error only, no payload errors[]), which every v6 tenant produces. Once the grant resolves, the check passes. The SDK-wide "SHOULD populate both layers" gap is noted in #7729 as an adcp-client follow-up.

Fix (training agent only, no changeset)

handleUpdateRights now falls back to findControllerSeededGrant when the exact-account lookup misses. The fallback bridges only the field the runner drops. It re-reads the same natural key without operator_unit, and only when all of these hold:

  • the request is a sandbox natural-key account that carries an operator_unit;
  • the grant has a seedFingerprint, meaning it was controller-seeded, not acquired through acquire_rights;
  • the grant's buyerDomain equals the request's operator.

Live accounts, other operators, and organically acquired grants still return REFERENCE_NOT_FOUND. Mutations persist through the normal per-request session snapshot flush.

Storyboard results

npm run build:compliance, then
TENANT_PATH=brand PUBLIC_TEST_AGENT_TOKEN=storyboard-local-token ADCP_COMPLIANCE_DIR=dist/compliance/latest ADCP_SCHEMA_ROOT=dist/schemas/latest npx tsx server/tests/manual/run-storyboards.ts --storyboard-id brand_rights/update_rights_lifecycle

Result
Before (main) ✗ 2P / 1F / 1S (pause_seeded_grant REFERENCE_NOT_FOUND; update_unknown_grant skipped)
After ✓ 4P / 0S / 0N/A, 0 failed

Full /brand tenant run (same env, no --storyboard-id): 56/56 clean, 122 passed, 0 failed. The latest main CI run had 55 clean and 120 passed.

Testing

  • New unit test in server/tests/unit/comply-test-controller.test.ts. It seeds through the brand-owned controller account, then pauses the grant through an operator_unit account. It also asserts that another operator and a live account still get REFERENCE_NOT_FOUND. The test fails without the fix and passes with it.
  • npx vitest run --config server/vitest.config.ts server/tests/unit/comply-test-controller.test.ts server/tests/unit/idempotency.test.ts server/tests/unit/training-agent-governance-intent-binding.test.ts server/tests/unit/training-agent-webhook-contract.test.ts: 152/152 pass.
  • npx tsc --noEmit -p server/tsconfig.json: passes.
  • node scripts/check-changeset-protocol-scope.cjs origin/main: passes (training-agent-only, no changeset).
  • I committed with --no-verify. In this sandbox, the full pre-commit server suite fails 9 tests/unit/addie/fixed-trace-* tests because they assert a worktree-local node_modules path, and node_modules here is a symlink. It also OOM-kills one worker. Neither is related to this change.

Follow-ups (not in this PR)

🤖 Generated with Claude Code

…ator_unit accounts

The storyboard runner builds seed_rights_grant from the test-kit account and
drops the authored operator_unit, so the grant lands in the
{brand, operator: buyer_domain, sandbox} partition while update_rights reads
the full operator_unit account. On an exact-account miss, update_rights now
re-reads the same natural key without operator_unit, accepting only a
sandbox, controller-seeded grant bought by the request operator.

brand_rights/update_rights_lifecycle passes 4/4 on /brand.

Fixes #7729

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 pass, no blocking findings.

Checked:

  • Scope: PR touches only server/src/training-agent/brand-handlers.ts and its unit test. Training-agent-only, no protocol surface (static/schemas/source/**, docs/reference/**, dist/**) touched — so no changeset required and no schema↔docs coherence concern.
  • The new findControllerSeededGrant fallback is fail-closed: sandbox-only, gated on seedFingerprint and buyerDomain, resolving controller-seeded rights grants for operator_unit-scoped buyers after #7601's partition isolation.
  • Persistence: mutation flushes correctly via the existing dirty-session path.
  • Multi-tenant isolation preserved: the new test exercises both the positive path and the other-operator / live-account rejection cases.

Gate checks: gated_paths=false, high_risk=false, no no-auto-approve team match, no prior decision. review_decision is REVIEW_REQUIRED, but with gated_paths=false that does not force escalation. No critical/high/medium findings → decision table falls through to row 9.

@bokelley
bokelley merged commit cf3839b into main Sep 29, 2026
53 checks passed
@bokelley
bokelley deleted the fix/update-rights-lifecycle-seed branch September 29, 2026 13:09
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.

brand_rights/update_rights_lifecycle: seeded grant is stored outside the operator_unit account update_rights reads

1 participant