Repository navigation
feat(training-agent): implement sync_principal and get_principal - #7938
Conversation
Adds the experimental principal layer to the /sales training agent so the universal/principal storyboard executes instead of resolving N/A. - Principal is resolved only from authenticated transport (API key -> buyer_agent, WorkOS user -> operator); anonymous callers get AUTH_REQUIRED and identity fields in the body are refused. - sync_principal: replace-by-section reporting_destinations and declarations, dry_run, expected_configuration_version / expected_principal_kind fences, idempotent replay, section clearing, destination generations and retired destinations, schema-validated input with secret screening. - Reporting destination proof is simulated: active destinations read back action_required, then ready; inactive destinations skip proof. - get_principal: recognized identity before configuration, current readback after, including the declarations accepted intersection. - Advertises adcp.principal and protocol.principal. notification_configs stays on sync_agent_notification_configs for now. - customToolFor no longer caches kind: failed results as idempotent replays. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — clean additive experimental principal layer, no blocking or medium findings.
What I checked:
- Changes are confined to
server/src/training-agent/**(app-only). Nostatic/schemas/source/**,docs/reference/**,dist/**, or migrations touched — so changeset, schema↔docs coherence, oneOf-discriminator, immutable-artifact, and 3.1.x patch-eligibility gates do not apply. App-only, no changeset required (correct). normalizeLocation(principal.ts:193) implements the agent-reporting-destination normalization spec-faithfully (NFC, lowercase scheme+authority, canonical path separators, ASCII-authority rejection);carriesSecretcovers the userinfo secret_rejection rule.- Request/response/capability shapes validate against sync-principal/get-principal/principal-state and the
adcp.principalblock (additionalProperties:false, required companions present). - Idempotency precedes the version fence; the custom-tool-helper
failedResultguard correctly avoids cachingkind:'failed'so a stale CONFLICT re-executes on retry, scoped to the new tool only. hasActiveSubscriberreads the same session+documentId written bysync_agent_notification_configs;principalConfigurationswired into createSession/serialize/deserialize per the Map-field invariant. No external I/O, no timeout surface. Breaking-class: none (additive experimental surface).
Gate evaluation: No critical/high/medium findings (row 1 n/a). gated_paths: false (row 2 n/a) — review_decision: REVIEW_REQUIRED is irrelevant without a gate. high_risk: false (rows 3,5 n/a). No data-loss/schema/infra medium (row 4 n/a). No prior decision (row 6 n/a). No no-auto-approve team match (row 7 n/a). Zero medium findings (row 8 n/a). Falls through to row 9 → approve.
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — clean pass, no blocking or medium findings.
This PR adds an experimental, sales-tenant-only principal layer (sync_principal/get_principal) for the training agent reference seller, plus session storage, capability advertisement, and a scoped idempotency fix. The change is purely server/** platform code — no schema source, changeset surface, oneOf, or released-artifact changes — so none of the AdCP spec-governance hard gates apply.
Reviewed highlights:
- Identity resolved only from transport; request-body identity fields rejected (principal.ts:227-229, 478-484).
- Sections validate before any write; every
failed(...)return precedessession.principalConfigurations.set(principal.ts:642), so the now-uncachedkind:'failed'idempotency retry (custom-tool-helper.ts:689-690) cannot double-write. - Cross-task subscriber coherence uses the shared caller key + document id (principal.ts:437-446).
asSets/normalizeDestinationread array/required fields only after schema validation, so no undefined-deref crash.
Gate checks: high_risk false; gated_paths false; review_decision APPROVED; no no-auto-approve team match. No critical/high/medium findings. Prior decision was also approve. Falls through to decision table row 9.
Summary
Implements the experimental principal layer (
sync_principal/get_principal) on the/salestraining agent so theuniversal/principalstoryboard runs instead of resolving N/A, and implementers have a live reference.Closes #7056
buyer_agent, WorkOS user →operator). Anonymous callers getAUTH_REQUIRED(HTTP 401 at the route);principal_id/agent_url/etc. in the body are refused.principal_idis a hash, never a credential.sync_principal: replace-by-sectionreporting_destinationsanddeclarations;dry_run(no persistence);expected_configuration_versionandexpected_principal_kindfences (CONFLICT); idempotent replay;[]/{}clearing; immutable destination generations (prior_destination_refs) andretired_destinations; input validated againstsync-principal-request.jsonwith credential screening oflocation; all-or-nothing validation before any write.action_required(setup.action: prove_control) and becomesreadyafter 5s on read;active: falsedestinations skip proof and readinactive. No outbound probe, and nocomply_test_controllerscenario (controller-backed principal fixtures stay with Fixture-dependent conformance for agent configuration lifecycle #7010).selected_async_adcp_version, andexclusionscomputed against the training agent's own support.get_principal:recognizedbefore configuration (no record created),currentafterwards.adcp.principalandprotocol.principal; both tools added to the tool catalog (sales, gated off 3.0-compat likesync_agent_notification_configs);sync_principalwas already in the idempotency registry.customToolForno longer cachesresult.kind: "failed"outcomes as idempotent replays.Judgment calls / deviations from the brief
notification_configsis not advertised insupported_sections(onlyreporting_destinationsanddeclarations). The capability schema requirescapability_changes.notifications.registration_task: sync_principalonce that section is advertised, and the required-cleanagent_notification_configsstoryboard hard-assertssync_agent_notification_configs. Flipping it needs a storyboard/spec decision, so webhooks stay on the specialized task and anotification_configssection is rejected withUNSUPPORTED_FEATURE. Follow-up: let that storyboard accept either task, then add the section here.protocolslots): the sales tenant runs throughcreateAdcpServerFromPlatform, which has noprotocolblock for it.principal.changedwebhook is fired for the simulatedaction_required → readytransition, soprincipal.changedis not offered.unconfiguredis never returned). Every holder of the shared public sandbox token is one principal, and state is last-writer-wins across machines (same assync_agent_notification_configs). Documented in the file header.check-changeset-protocol-scopepasses).Testing
npx vitest run server/tests/unit/training-agent-principal.test.ts(32 tests, incl. thecustomToolForwrapper) andtraining-agent-agent-notification-configs.test.ts: pass.universal/principalstoryboard against local/sales: 11/11 steps, clean (all phases).agent_notification_configsstoryboard still clean (3/3).npm run typecheck; training-agent tool-catalog drift / dispatch smoke / account-change-feed / tenant URL tests pass.tenant-smoke"controller-seeded media buys" times out here but also fails on a cleanorigin/mainin this sandbox.fixed-trace-rollout-typecheck-wiringruns a fulltscagainst a hard-coded 30s limit and takes ~40s in this sandbox. The other hook steps were run by hand. The storyboard matrix is left to the authoritative CI workflow.Follow-ups
notification_configssection.🤖 Generated with Claude Code
Open workspace in Conductor