From 2f2572a7f352615f56d0f81656699f90b543903b Mon Sep 17 00:00:00 2001 From: Ben Hook <5009589+benhook1013@users.noreply.github.com> Date: Fri, 9 Oct 2026 06:29:13 +1300 Subject: [PATCH 1/5] Define non-admitting canonical Entity roster wire contract --- .../v1/entity_management_service.proto | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/protos/entity-management/v1/entity_management_service.proto b/protos/entity-management/v1/entity_management_service.proto index 3bc971bcde..3996021eff 100644 --- a/protos/entity-management/v1/entity_management_service.proto +++ b/protos/entity-management/v1/entity_management_service.proto @@ -36,6 +36,86 @@ service EntityManagementService { returns (ValidateEntityUpgradeMappingsResponse); } +// Canonical gameplay roster discovery is a separate non-admitting boundary. This wire contract +// does not authorize the legacy numeric ListCharactersByAccount RPC for canonical gameplay. +service CanonicalGameplayRosterService { + rpc ListPreseededRoster(CanonicalGameplayRosterRequest) + returns (CanonicalGameplayRosterResponse); + rpc ReadSelectedPreseededAssignment(CanonicalGameplayRosterSelectedAssignmentRequest) + returns (CanonicalGameplayRosterSelectedAssignmentResponse); +} + +message CanonicalGameplayRosterRequest { + string request_uuid = 1; + string canonical_account_uuid = 2; + CanonicalGameplayRosterTarget expected_target = 3; +} + +message CanonicalGameplayRosterTarget { + string tenant_uuid = 1; + string realm_uuid = 2; + string world_slug = 3; + string realm_slug = 4; + string game_instance_uuid = 5; + int64 catalog_revision = 6; + reserved 7, 8; + string published_policy_digest = 9; + string published_release_bundle_ref = 10; + string admission_pointer_snapshot_digest = 11; + string published_owner_proof_digest = 12; + string playable_state_namespace_uuid = 13; + PlayableStateScope playable_state_scope = 14; + CanonicalGameplayRosterEntryPolicy entry_policy = 15; + string canonical_version_uuid = 16; + // Exact positive counters observed from the current owning Game Session target. + int64 pointer_version = 17; + int64 active_world_epoch = 18; +} + +enum CanonicalGameplayRosterEntryPolicy { + CANONICAL_ROSTER_ENTRY_POLICY_UNSPECIFIED = 0; + CANONICAL_ROSTER_ENTRY_POLICY_PLAYER_CREATED = 1; + CANONICAL_ROSTER_ENTRY_POLICY_PRESEEDED_ONLY = 2; + CANONICAL_ROSTER_ENTRY_POLICY_AUTO_PROVISIONED = 3; +} + +message CanonicalGameplayRosterResponse { + string canonical_account_uuid = 1; + CanonicalGameplayRosterTarget target = 2; + string snapshot_uuid = 3; + string snapshot_digest = 4; + repeated CanonicalGameplayRosterActor actors = 5; + shared.v1.ErrorDetail error = 6; +} + +message CanonicalGameplayRosterActor { + string character_uuid = 1; + string display_name = 2; + CanonicalGameplayRosterActorKind actor_kind = 3; +} + +message CanonicalGameplayRosterSelectedAssignmentRequest { + string request_uuid = 1; + string canonical_account_uuid = 2; + string selected_character_uuid = 3; + CanonicalGameplayRosterTarget expected_target = 4; +} + +message CanonicalGameplayRosterSelectedAssignmentResponse { + string request_uuid = 1; + string canonical_account_uuid = 2; + string selected_character_uuid = 3; + CanonicalGameplayRosterTarget target = 4; + string assignment_uuid = 5; + string intent_digest = 6; + shared.v1.ErrorDetail error = 7; +} + +enum CanonicalGameplayRosterActorKind { + CANONICAL_ROSTER_ACTOR_KIND_UNSPECIFIED = 0; + CANONICAL_ROSTER_ACTOR_KIND_PLAYER = 1; +} + message CreateCharacterRequest { string tenant_id = 1; string account_id = 2; From 57953d2be3a6bfd00a430837e9d9b1587bddeea4 Mon Sep 17 00:00:00 2001 From: Ben Hook <5009589+benhook1013@users.noreply.github.com> Date: Fri, 9 Oct 2026 08:38:08 +1300 Subject: [PATCH 2/5] Bind canonical roster selection to immutable snapshot evidence --- .../api-contracts.md | 2 + .../v1/entity_management_service.proto | 30 +++++++++-- ...icalGameplayRosterProtoDescriptorTest.java | 50 +++++++++++++++++++ 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java diff --git a/design/architecture/microservices/entity-management-service/api-contracts.md b/design/architecture/microservices/entity-management-service/api-contracts.md index 47464c1037..be9e177e62 100644 --- a/design/architecture/microservices/entity-management-service/api-contracts.md +++ b/design/architecture/microservices/entity-management-service/api-contracts.md @@ -6,6 +6,8 @@ The authoritative REST schema source lives in [../../../../services/entity-manag ## Implementation Status +The separate `CanonicalGameplayRosterService` proto is a wire contract only; it has no handler or activation in the current stage. `ListPreseededRoster` may successfully return zero actors and binds the exact target to its snapshot UUID and digest. `ReadSelectedPreseededAssignment` requires that same typed snapshot reference, echoes it on success, and returns `FAILED_PRECONDITION` if it is stale or the selected actor is absent from it. Malformed input is `INVALID_ARGUMENT`; authorization failures are `UNAUTHENTICATED` or `PERMISSION_DENIED` as applicable; unavailable dependencies are `UNAVAILABLE`. Failures use non-OK gRPC status with no partial response, not response-level `ErrorDetail`. These semantics do not authorize the legacy numeric `ListCharactersByAccount` RPC for canonical gameplay. + The live crafting REST surface is runtime-reachable but is not a tenant-authorized gameplay or design-time boundary: `POST /crafting/recipes` accepts a caller-supplied `tenantId` in `CraftingRecipeDto`, and `GET /crafting/recipes/{id}` accepts only a globally-shaped recipe id. The ping-only authoritative OpenAPI document declares root `security: []`; the crafting handlers and schemas are omitted from that contract. The deployed Entity HTTP interceptor currently requires only an `AUTHENTICATED` bearer (crafting is not in the public-route list), while the controllers do not apply `SessionContext` tenant authorization and the service/repository do not bind either operation to the authenticated caller. The create path can therefore persist a caller-selected tenant (and an existing DTO id can update by id), while the read path performs an ID-only recipe lookup. `CraftingControllerTest` and `CraftingServiceImplTest` cover request/recipe validation and happy-path persistence only; they do not prove unauthenticated denial, tenant-qualified lookup/update, or cross-tenant item ownership. The handlers must remain unsupported/fenced or gain the target caller-bound authorization before they can be treated as a supported route. The live `CharacterController`, `InventoryController`, `EquipmentController`, and `FriendController` REST handlers are also legacy direct adapters. They remain runtime-reachable behind baseline bearer authentication and their implemented tenant-access checks. diff --git a/protos/entity-management/v1/entity_management_service.proto b/protos/entity-management/v1/entity_management_service.proto index 3996021eff..558083936b 100644 --- a/protos/entity-management/v1/entity_management_service.proto +++ b/protos/entity-management/v1/entity_management_service.proto @@ -37,10 +37,21 @@ service EntityManagementService { } // Canonical gameplay roster discovery is a separate non-admitting boundary. This wire contract -// does not authorize the legacy numeric ListCharactersByAccount RPC for canonical gameplay. +// does not authorize the legacy numeric ListCharactersByAccount RPC for canonical gameplay. A +// valid ListPreseededRoster response may contain zero actors; that is a successful lookup. These +// RPCs use canonical non-OK gRPC statuses rather than in-response errors: malformed requests are +// INVALID_ARGUMENT, stale snapshots or selections not present in the bound snapshot are +// FAILED_PRECONDITION, unauthorized callers are UNAUTHENTICATED or PERMISSION_DENIED as +// applicable, and unavailable dependencies are UNAVAILABLE. No partial success is returned. service CanonicalGameplayRosterService { + // Returns the persisted preseeded roster for the exact expected target. A successful response + // includes its immutable snapshot UUID and digest, including when the roster is empty. rpc ListPreseededRoster(CanonicalGameplayRosterRequest) returns (CanonicalGameplayRosterResponse); + // Reads the selected assignment only if the supplied snapshot UUID and digest still identify + // the roster from which selected_character_uuid was chosen. The response echoes that exact + // snapshot reference. A changed snapshot or selection absent from it fails with + // FAILED_PRECONDITION. rpc ReadSelectedPreseededAssignment(CanonicalGameplayRosterSelectedAssignmentRequest) returns (CanonicalGameplayRosterSelectedAssignmentResponse); } @@ -85,7 +96,14 @@ message CanonicalGameplayRosterResponse { string snapshot_uuid = 3; string snapshot_digest = 4; repeated CanonicalGameplayRosterActor actors = 5; - shared.v1.ErrorDetail error = 6; + reserved 6; + reserved "error"; +} + +// Immutable identity and content digest of one exact roster snapshot. +message CanonicalGameplayRosterSnapshotReference { + string snapshot_uuid = 1; + string snapshot_digest = 2; } message CanonicalGameplayRosterActor { @@ -99,6 +117,9 @@ message CanonicalGameplayRosterSelectedAssignmentRequest { string canonical_account_uuid = 2; string selected_character_uuid = 3; CanonicalGameplayRosterTarget expected_target = 4; + // Exact snapshot_uuid and snapshot_digest returned by ListPreseededRoster. Retries must reuse + // these values and may not silently select against a changed roster. + CanonicalGameplayRosterSnapshotReference expected_snapshot = 5; } message CanonicalGameplayRosterSelectedAssignmentResponse { @@ -108,7 +129,10 @@ message CanonicalGameplayRosterSelectedAssignmentResponse { CanonicalGameplayRosterTarget target = 4; string assignment_uuid = 5; string intent_digest = 6; - shared.v1.ErrorDetail error = 7; + reserved 7; + reserved "error"; + // Exact snapshot reference supplied by the caller and validated by this operation. + CanonicalGameplayRosterSnapshotReference snapshot = 8; } enum CanonicalGameplayRosterActorKind { diff --git a/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java b/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java new file mode 100644 index 0000000000..1bb8daa592 --- /dev/null +++ b/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java @@ -0,0 +1,50 @@ +package net.firedevops.firemud.common.entity; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.protobuf.Descriptors.Descriptor; +import com.google.protobuf.Descriptors.FieldDescriptor; +import net.firedevops.firemud.entitymanagement.v1.CanonicalGameplayRosterResponse; +import net.firedevops.firemud.entitymanagement.v1.CanonicalGameplayRosterSelectedAssignmentRequest; +import net.firedevops.firemud.entitymanagement.v1.CanonicalGameplayRosterSelectedAssignmentResponse; +import net.firedevops.firemud.entitymanagement.v1.CanonicalGameplayRosterSnapshotReference; +import org.junit.jupiter.api.Test; + +class CanonicalGameplayRosterProtoDescriptorTest { + @Test + void selectedAssignmentRoundTripsTheExactTypedSnapshotReference() { + FieldDescriptor expectedSnapshot = + CanonicalGameplayRosterSelectedAssignmentRequest.getDescriptor().findFieldByNumber(5); + FieldDescriptor snapshot = + CanonicalGameplayRosterSelectedAssignmentResponse.getDescriptor().findFieldByNumber(8); + + assertThat(expectedSnapshot.getName()).isEqualTo("expected_snapshot"); + assertThat(expectedSnapshot.getMessageType()) + .isEqualTo(CanonicalGameplayRosterSnapshotReference.getDescriptor()); + assertThat(snapshot.getName()).isEqualTo("snapshot"); + assertThat(snapshot.getMessageType()) + .isEqualTo(CanonicalGameplayRosterSnapshotReference.getDescriptor()); + + Descriptor snapshotDescriptor = CanonicalGameplayRosterSnapshotReference.getDescriptor(); + assertThat(snapshotDescriptor.findFieldByNumber(1).getName()).isEqualTo("snapshot_uuid"); + assertThat(snapshotDescriptor.findFieldByNumber(2).getName()).isEqualTo("snapshot_digest"); + } + + @Test + void canonicalRosterResponsesHaveNoInResponseErrorAndReserveItsSlot() { + assertErrorSlotReserved(CanonicalGameplayRosterResponse.getDescriptor(), 6); + assertErrorSlotReserved(CanonicalGameplayRosterSelectedAssignmentResponse.getDescriptor(), 7); + assertThat(CanonicalGameplayRosterResponse.getDescriptor().findFieldByNumber(6)).isNull(); + assertThat( + CanonicalGameplayRosterSelectedAssignmentResponse.getDescriptor() + .findFieldByNumber(8) + .getName()) + .isEqualTo("snapshot"); + } + + private static void assertErrorSlotReserved(Descriptor descriptor, int fieldNumber) { + assertThat(descriptor.toProto().getReservedRangeList()) + .anySatisfy(range -> assertThat(range.getStart()).isEqualTo(fieldNumber)); + assertThat(descriptor.toProto().getReservedNameList()).contains("error"); + } +} From b9be3928dfcc74b52b47da284ac77bab85bb90a0 Mon Sep 17 00:00:00 2001 From: Ben Hook <5009589+benhook1013@users.noreply.github.com> Date: Fri, 9 Oct 2026 08:51:50 +1300 Subject: [PATCH 3/5] Bind preseeded roster reads to trusted player context and policy --- .../api-contracts.md | 5 +-- .../game-session-service/api-contracts.md | 2 ++ .../system-architecture-transactions.md | 13 +++---- .../v1/entity_management_service.proto | 34 +++++++++++++------ ...icalGameplayRosterProtoDescriptorTest.java | 15 ++++++++ 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/design/architecture/microservices/entity-management-service/api-contracts.md b/design/architecture/microservices/entity-management-service/api-contracts.md index be9e177e62..d3393450d9 100644 --- a/design/architecture/microservices/entity-management-service/api-contracts.md +++ b/design/architecture/microservices/entity-management-service/api-contracts.md @@ -6,7 +6,7 @@ The authoritative REST schema source lives in [../../../../services/entity-manag ## Implementation Status -The separate `CanonicalGameplayRosterService` proto is a wire contract only; it has no handler or activation in the current stage. `ListPreseededRoster` may successfully return zero actors and binds the exact target to its snapshot UUID and digest. `ReadSelectedPreseededAssignment` requires that same typed snapshot reference, echoes it on success, and returns `FAILED_PRECONDITION` if it is stale or the selected actor is absent from it. Malformed input is `INVALID_ARGUMENT`; authorization failures are `UNAUTHENTICATED` or `PERMISSION_DENIED` as applicable; unavailable dependencies are `UNAVAILABLE`. Failures use non-OK gRPC status with no partial response, not response-level `ErrorDetail`. These semantics do not authorize the legacy numeric `ListCharactersByAccount` RPC for canonical gameplay. +The separate `CanonicalGameplayRosterService` proto is a wire contract only; it has no handler or activation in the current stage. Its two methods define pre-admission, non-admitting reads restricted to `PRESEEDED_ONLY`; any other policy value is non-authorizing and returns `FAILED_PRECONDITION`. `ListPreseededRoster` may successfully return zero actors and binds the exact target to its snapshot UUID and digest. `ReadSelectedPreseededAssignment` requires that same typed snapshot reference, echoes it on success, and returns `FAILED_PRECONDITION` if it is stale or the selected actor is absent from it. Both require a server-derived typed `PlayerExecutionContext`, the exact same-namespace Game Session mTLS caller allowlist, and equality between context and request/target fields. The initial roster read has no selected actor and requires no admitted-character or current-binding proof; the selection read requires `context.character_id` to equal `selected_character_uuid`. The context is unsigned scope data, not a credential, and does not authorize an additional Account lookup solely for the read. Malformed input is `INVALID_ARGUMENT`; authorization failures are `UNAUTHENTICATED` or `PERMISSION_DENIED` as applicable; unavailable dependencies are `UNAVAILABLE`. Failures use non-OK gRPC status with no partial response, not response-level `ErrorDetail`. These semantics do not authorize the legacy numeric `ListCharactersByAccount` RPC for canonical gameplay. The live crafting REST surface is runtime-reachable but is not a tenant-authorized gameplay or design-time boundary: `POST /crafting/recipes` accepts a caller-supplied `tenantId` in `CraftingRecipeDto`, and `GET /crafting/recipes/{id}` accepts only a globally-shaped recipe id. The ping-only authoritative OpenAPI document declares root `security: []`; the crafting handlers and schemas are omitted from that contract. The deployed Entity HTTP interceptor currently requires only an `AUTHENTICATED` bearer (crafting is not in the public-route list), while the controllers do not apply `SessionContext` tenant authorization and the service/repository do not bind either operation to the authenticated caller. The create path can therefore persist a caller-selected tenant (and an existing DTO id can update by id), while the read path performs an ID-only recipe lookup. `CraftingControllerTest` and `CraftingServiceImplTest` cover request/recipe validation and happy-path persistence only; they do not prove unauthenticated denial, tenant-qualified lookup/update, or cross-tenant item ownership. The handlers must remain unsupported/fenced or gain the target caller-bound authorization before they can be treated as a supported route. @@ -41,10 +41,11 @@ curl http://localhost:8080/ping ## gRPC - `Ping(PingRequest) returns (PingResponse)` – connectivity check defined in `entity_management_service.proto`. +- `CanonicalGameplayRosterService.ListPreseededRoster` and `ReadSelectedPreseededAssignment` – separate target wire contract for the `PRESEEDED_ONLY` pre-admission roster branch. Both carry `shared.v1.PlayerExecutionContext`; the first binds the authenticated account/session/request and prospective tenant/realm/namespace/scope/instance target, while the second additionally binds `context.character_id` to the selected UUID and the exact roster snapshot. The exact same-namespace Game Session workload mTLS identity is allowlisted. These reads are not actor admission or a session-binding shortcut, and their proto has no handler or activation yet. - `CreateCharacter(CreateCharacterRequest) returns (CreateCharacterResponse)` – Entity-owned allocation and persistence of a primary controllable actor after the caller has passed Account membership/grant/realm admission. The target request carries the resolved `{accountId, tenantId, worldSlug, realmSlug}`, stable `playableStateNamespaceId`, the `playableStateScope` supplied only as authoritative realm-snapshot/attestation evidence, active `gameInstanceId`, explicit `entryPolicy=PLAYER_CREATED`, exact published descriptor identity/version, player creation input, and proof of the catalog/admission-pointer snapshot. Entity rejects a missing or mismatched policy before allocation or replay, and cross-checks the policy against the canonical snapshot and the applicable descriptor identity/version. It also carries caller-stable `createCharacterRequestId` and canonical `mutationDigest`; Entity recomputes the digest over the immutable trusted target, `entryPolicy`, exact descriptor/version, and creation input. The durable operation guard key is `{tenantId, playableStateNamespaceId, accountId, createCharacterRequestId}`. Within one local transaction, Entity admits and locks that guard plus digest, serializes the `PLAYER_CREATED` zero-roster boundary on `{tenantId, playableStateNamespaceId, accountId}`, and rereads the roster against the unchanged policy and descriptor/version before allocation. Only a still-empty roster may allocate; concurrent distinct request identities cannot both cross a stale zero-roster observation. Entity then atomically persists the allocated `{accountId, tenantId, playableStateNamespaceId, characterId}` association and replayable response. The same guard and digest exact-replay the original response; the same guard with a different digest returns `IDEMPOTENCY_CONFLICT` before allocation. Callers cannot choose or derive `playableStateScope`; Entity must reject caller-derived evidence and validate the exact immutable namespace/scope pair. A scope change under one namespace is rejected and never creates a second or split actor record. Entity allocates `characterId` only after the operation guard, validates the namespace/scope and active-instance fence, and never derives identity from account/name/hash or delegates character ownership to Account. Durable persistence/keying remains `{tenantId, playableStateNamespaceId, characterId}`; `playableStateScope` remains separately validated immutable routing/authorization evidence, `gameInstanceId` is only the replaceable active-runtime fence, and neither is a durable character-identity dimension. Entity Management does not expose a direct player REST route. The current request path and enforcement do not yet prove this complete target boundary, so it remains an implementation/proof gap rather than a claim about live enforcement. - `UpdateEntity(UpdateEntityRequest) returns (UpdateEntityResponse)` – updates mutable character state for the requested `{tenantId, playableStateNamespaceId, gameInstanceId, playableStateScope, characterId}` target. `playableStateScope` must be the authoritative realm-snapshot/attestation result; callers cannot choose or derive it, and Entity validates the exact immutable namespace/scope pair before mutation. A caller-selected or changed scope, missing/mismatched namespace or scope, stale snapshot, caller-asserted instance, or global `characterId` is rejected rather than updating or splitting records. Target state also requires a fresh, server-resolved active-instance authorization fence for that exact namespace/scope and instance, checked atomically immediately before mutation. The current request path does not yet carry and prove the complete fresh fence, so it remains an implementation/proof gap and must not be treated as target enforcement. - `QueryInventory(QueryInventoryRequest) returns (QueryInventoryResponse)` – the current response is an unpaged repeated `InventoryItem items[]` projection. The live handler emits `item_id`, `item_name`, `item_description`, and `quantity`, and conditionally emits `container_instance_id`, `item_instance_id`, and `visible_ref` when those values are present. This projection does not establish complete instance-aware identity or stack/concurrency safety: rich pagination, complete holder-local stack uniqueness, find-then-create concurrency, and explicit-family duplicate handling remain target/proof gaps documented in [Runtime and Data](./runtime-and-data.md#implementation-status). -- `ListCharactersByAccount` (target-state policy/descriptor/template/namespace fields) – returns only persisted actors valid for the trusted account selector and resolved `{tenantId, playableStateNamespaceId, playableStateScope}` target. Entity validates the account-to-character association before returning any roster or visibility result; an account identifier is ownership evidence, not controller identity. The target response includes exactly one published v1 entry policy (`PLAYER_CREATED`, `PRESEEDED_ONLY`, or `AUTO_PROVISIONED`) plus only its policy-applicable versioned identity: a descriptor identity/version for `PLAYER_CREATED`, a template identity/version for `AUTO_PROVISIONED`, and neither descriptor nor template fields for `PRESEEDED_ONLY`; it echoes the resolved namespace/scope. It also returns one immutable roster snapshot identity and digest for the exact target, policy/version, and ordered roster; an exact unchanged snapshot reuses both values, while a roster or policy/version change advances the identity or digest. Callers bind that snapshot for selection and retry and reject a changed snapshot rather than silently selecting a different actor. `gameInstanceId` is a fresh active-runtime fence, not durable lookup identity. Zero, one, and many results are explicit: policy determines the zero-result next action, one may be selected automatically, and many require explicit selection. A roster is discovery evidence, not admission authority. The current proto surface has none of the target policy, descriptor/template, namespace, or roster-snapshot fields and does not prove this boundary. +- `ListCharactersByAccount` (broader target-state policy/descriptor/template/namespace behavior) – the eventual policy-aware roster contract returns only persisted actors valid for the trusted account selector and resolved `{tenantId, playableStateNamespaceId, playableStateScope}` target. Entity validates account-to-character ownership; account identity is ownership evidence, not controller identity. The target response includes the exact published v1 entry policy and only its applicable versioned identity: descriptor/version for `PLAYER_CREATED`, template/version for `AUTO_PROVISIONED`, neither for `PRESEEDED_ONLY`; it echoes namespace/scope and returns an immutable roster snapshot identity/digest for the exact target, policy/version, and ordered roster. `gameInstanceId` is a fresh active-runtime fence, not durable lookup identity. Zero, one, and many results follow policy-specific next actions; a roster is discovery evidence, not admission authority. The separate `CanonicalGameplayRosterService` wire above currently specifies only the `PRESEEDED_ONLY` branch. `PLAYER_CREATED` and `AUTO_PROVISIONED` remain later-owned target branches, and the legacy numeric `ListCharactersByAccount` method is not trusted for canonical gameplay. Current handlers do not prove these target contracts. - `AutoProvisionCharacter` (target-state) – after explicit entry, idempotently provisions at most one actor from the published realm template using the trusted `{tenantId, accountId, playableStateNamespaceId}` as the at-most-one uniqueness tuple. The request carries explicit `entryPolicy=AUTO_PROVISIONED`, the unchanged discovered-entry object and `discoveredEntryDigest`, the applicable exact template identity/version, a caller-stable `autoProvisionRequestId` that is stable and unique only within that exact `{tenantId, accountId, playableStateNamespaceId}` target scope, canonical `mutationDigest`, and an explicit absent-creation-input marker following ADR 0140's fixed-position presence encoding. Entity rejects a missing or mismatched policy before allocation or replay, and cross-checks it against the canonical snapshot and applicable template identity/version. Entity recomputes the mutation digest over the immutable trusted target, `entryPolicy`, exact template identity/version, and absent-input marker, and durably guards the operation by `{tenantId, accountId, playableStateNamespaceId, autoProvisionRequestId}` separately from the at-most-one-actor constraint; these operation-guard and actor-uniqueness constraints remain distinct. An actor-uniqueness race between distinct request IDs has one winner; each loser transactionally rereads and validates the exact target, policy, template provenance, and digest, durably stores its own guard result, and returns/replays the same actor only on exact match. A loser with mismatched provenance or digest stores a terminal `IDEMPOTENCY_CONFLICT` outcome and never replaces or allocates another actor. `playableStateScope` is only server-validated routing/authorization-fence evidence and is not an alternate key; `gameInstanceId` is the replaceable active-runtime fence. The same target-scoped guard with the same digest exact-replays the persisted actor, including under concurrent delivery; the same scoped guard with a changed digest-bound intent returns `IDEMPOTENCY_CONFLICT` before allocation. A different tenant, account, or namespace selects a different target-scoped guard and must not conflict solely because the text request ID is reused; no global request registry is implied. The current surface and proof are not implemented. - `QueryActorState` – returns gameplay-attested actor resources and active conditions for a scoped character. - `ApplyActorCondition` – **target-state request:** applies a gameplay-attested active condition or transient action state for a scoped character. The canonical target request carries a dedicated operation-unique `effectId`, separate source provenance, optional expiry, and the exact release-pinned typed effect declaration/reference and digest resolved by the server-side gameplay path; caller-defined effect JSON is not mutation authority. The target mutation persists the frozen definition/release and its server-resolved typed applied-effect snapshot and digest, never a caller-supplied payload. The current request still accepts transitional `effectPayloadJson`, so this typed-plan/no-caller-payload boundary is not live enforcement yet. diff --git a/design/architecture/microservices/game-session-service/api-contracts.md b/design/architecture/microservices/game-session-service/api-contracts.md index 44ed3630df..c0b07e0052 100644 --- a/design/architecture/microservices/game-session-service/api-contracts.md +++ b/design/architecture/microservices/game-session-service/api-contracts.md @@ -30,6 +30,8 @@ For script transitions, the live boundary includes the exact `scriptPinEpoch` an Game Session communicates with other platform services exclusively via gRPC for gameplay-domain work. Player-delegated calls carry the typed unsigned `PlayerExecutionContext` defined in the authentication architecture, including the required gameplay scope for admission. Downstream services authenticate the concrete mTLS caller, enforce an exact RPC caller allowlist, validate context/request equality and domain scope, and reject client-supplied identity metadata. Routine gameplay calls do not use signed per-action attestations or a generic replay cache; mutations retain their owning command/effect/request idempotency. +The Entity `CanonicalGameplayRosterService` calls for `PRESEEDED_ONLY` are pre-admission discovery reads, not already-admitted player actions. Game Session supplies a server-derived `PlayerExecutionContext` containing authenticated account, session, request, and the prospective tenant/realm/namespace/scope/instance target, and calls under the exact same-namespace Game Session mTLS identity allowlisted for each method. Entity requires exact context/request/target equality. The initial roster request has no selected actor or admitted-character/current-binding requirement; for `ReadSelectedPreseededAssignment`, `context.character_id` equals `selected_character_uuid`. The unsigned context is scope data, not a credential, and these reads add no Account lookup solely for authorization. This wire currently has no handler or activation, and its policy does not authorize other roster branches or actor admission. + For target gameplay forwarding, `PlayerExecutionContext` carries the server-resolved `{tenantId, playableStateNamespaceId, playableStateScope, gameInstanceId}` binding and, for region-scoped work, its `{regionId, regionEpoch}` fence as one context. Game Session forwards the namespace and scope unchanged and validates exact context/request equality on every downstream response or mutation result; it never accepts a caller-selected namespace or substitutes a current one after admission. The current context/forwarding wire is narrower in places and does not yet carry or prove this complete namespace-plus-fence tuple, so that path remains an implementation/proof gap and must fail closed on missing authority. It also communicates game lifecycle changes to other microservices over gRPC so they can react to game instances starting, stopping, or changing runtime configuration. diff --git a/design/architecture/system-architecture-transactions.md b/design/architecture/system-architecture-transactions.md index 58ec423939..dcc649c22c 100644 --- a/design/architecture/system-architecture-transactions.md +++ b/design/architecture/system-architecture-transactions.md @@ -250,9 +250,9 @@ These workflows: - Modify **persistent storage (PostgreSQL)** across multiple services - Require compensation and persisted step status, but not durable workflow execution -For `explicitRealmEntry`, the accepted policy outcomes are exactly `PLAYER_CREATED`, `AUTO_PROVISIONED`, and `PRESEEDED_ONLY`; the immutable discovered-entry request may carry an optional `selectedCharacterId`, and its digest covers that selection without duplicating policy semantics. For any branch that reads a roster, the durable saga step binds the selected policy branch, Entity-returned roster snapshot identity/digest, and resolved selected character when one exists; retries reuse those applicable values rather than silently following a changed roster. The saga branches on that unchanged bound outcome: `PLAYER_CREATED` first uses Entity's `ListCharactersByAccount` against the unchanged bound target, then evaluates any supplied creation input against that roster. An exactly-one roster auto-selects its actor; if the request supplies `selectedCharacterId`, it must equal that one actor. A multiple-actor roster requires an explicit `selectedCharacterId` that belongs to the unchanged roster/snapshot; missing or invalid selection fails before binding. Any supplied creation input is valid only for a zero-roster `PLAYER_CREATED` branch; after the roster lookup, a nonempty `PLAYER_CREATED` roster rejects its presence before selection, binding, or mutation, while `AUTO_PROVISIONED` and `PRESEEDED_ONLY` reject it before their branch-specific lookup or mutation. A zero roster with no creation input offers/requires creation without mutation, and zero-roster creation never accepts a caller-selected character ID. A submitted creation input with absent required fields, malformed data, or failure to validate against the exact realm-published descriptor and version bound in the discovered-entry object fails closed; and only valid submitted input calls `CreateCharacter` with the unchanged discovered-entry object/digest plus that input. The preliminary roster read is discovery and selection evidence, not concurrency authority; the Entity-owned `CreateCharacter` contract serializes and rereads the zero-roster boundary before allocation. If a durable saga step has already entered `CreateCharacter`, a retry calls Entity with the stored request identity, digest, and canonical input before any fresh roster rejection so a committed operation with a lost response replays its original result. Each mutating branch carries a caller-stable operation request identity derived from its durable forward saga-step identity (`createCharacterRequestId` for `PLAYER_CREATED`, `autoProvisionRequestId` for `AUTO_PROVISIONED`) and a `mutationDigest` over the trusted target, exact descriptor or template identity/version, and canonical `creationInput`; the auto-provision branch uses the explicit absent-input marker defined by [ADR 0140](./decisions/adr-0140-realm-authored-controllable-actor-entry.md). Entity recomputes and binds the digest and operation identity, while `discoveredEntryDigest` remains admission/discovery evidence rather than actor-write identity. A retry reuses the same operation identity, digest, and canonical input and replays the original result; changed target, descriptor/template/version, or input fails closed as an idempotency conflict. +For `explicitRealmEntry`, the accepted policy outcomes are exactly `PLAYER_CREATED`, `AUTO_PROVISIONED`, and `PRESEEDED_ONLY`; the immutable discovered-entry request may carry an optional `selectedCharacterId`, and its digest covers that selection without duplicating policy semantics. For any branch that reads a roster, the durable saga step binds the selected policy branch, Entity-returned roster snapshot identity/digest, and resolved selected character when one exists; retries reuse those applicable values rather than silently following a changed roster. The saga branches on that unchanged bound outcome: `PLAYER_CREATED` first uses its later-owned policy-aware Entity roster contract against the unchanged bound target, then evaluates any supplied creation input against that roster. An exactly-one roster auto-selects its actor; if the request supplies `selectedCharacterId`, it must equal that one actor. A multiple-actor roster requires an explicit `selectedCharacterId` that belongs to the unchanged roster/snapshot; missing or invalid selection fails before binding. Any supplied creation input is valid only for a zero-roster `PLAYER_CREATED` branch; after the roster lookup, a nonempty `PLAYER_CREATED` roster rejects its presence before selection, binding, or mutation, while `AUTO_PROVISIONED` and `PRESEEDED_ONLY` reject it before their branch-specific lookup or mutation. A zero roster with no creation input offers/requires creation without mutation, and zero-roster creation never accepts a caller-selected character ID. A submitted creation input with absent required fields, malformed data, or failure to validate against the exact realm-published descriptor and version bound in the discovered-entry object fails closed; and only valid submitted input calls `CreateCharacter` with the unchanged discovered-entry object/digest plus that input. The preliminary roster read is discovery and selection evidence, not concurrency authority; the Entity-owned `CreateCharacter` contract serializes and rereads the zero-roster boundary before allocation. If a durable saga step has already entered `CreateCharacter`, a retry calls Entity with the stored request identity, digest, and canonical input before any fresh roster rejection so a committed operation with a lost response replays its original result. Each mutating branch carries a caller-stable operation request identity derived from its durable forward saga-step identity (`createCharacterRequestId` for `PLAYER_CREATED`, `autoProvisionRequestId` for `AUTO_PROVISIONED`) and a `mutationDigest` over the trusted target, exact descriptor or template identity/version, and canonical `creationInput`; the auto-provision branch uses the explicit absent-input marker defined by [ADR 0140](./decisions/adr-0140-realm-authored-controllable-actor-entry.md). Entity recomputes and binds the digest and operation identity, while `discoveredEntryDigest` remains admission/discovery evidence rather than actor-write identity. A retry reuses the same operation identity, digest, and canonical input and replays the original result; changed target, descriptor/template/version, or input fails closed as an idempotency conflict. The separate `CanonicalGameplayRosterService.ListPreseededRoster` wire implements only the pre-admission `PRESEEDED_ONLY` lookup; `PLAYER_CREATED` remains a later-owned target branch, and neither it nor `AUTO_PROVISIONED` may fall back to the legacy numeric `ListCharactersByAccount` RPC for canonical gameplay. -`AUTO_PROVISIONED` requires `selectedCharacterId` to be absent; any supplied selection fails closed before the provisioning call. It calls `AutoProvisionCharacter` with the same immutable discovered-entry inputs plus its stable `autoProvisionRequestId`, `mutationDigest`, and canonical absent-input marker after explicit entry, allowing its owner-defined idempotent existing-actor result. `PRESEEDED_ONLY` calls `ListCharactersByAccount` as a lookup: zero actors returns the pre-seeded-only denial, while a nonzero roster applies the same exact-one-versus-many selection rule without actor mutation. Its durable selection step binds the returned roster snapshot identity/digest and selected character; a retry must validate that exact snapshot and selection and fails closed if the roster changed rather than silently selecting another actor. No branch re-resolves policy or substitutes a different descriptor/template, namespace, scope, roster, or digest. Catalog and admission-pointer identity/semantics remain in [Multi-Tenancy](./system-architecture-multi-tenancy.md), while Game Session owns realm/pointer resolution, selection, and serving orchestration and Entity Management owns descriptor/template consumption and actor allocation/persistence. [ADR 0140](./decisions/adr-0140-realm-authored-controllable-actor-entry.md) remains decision rationale for this boundary; its canonical presence encoding is retained by the auto-provision request above. The Entity API contract names these target surfaces, but the current proto, implementation, and focused proof do not establish this saga. +`AUTO_PROVISIONED` requires `selectedCharacterId` to be absent; any supplied selection fails closed before the provisioning call. It calls `AutoProvisionCharacter` with the same immutable discovered-entry inputs plus its stable `autoProvisionRequestId`, `mutationDigest`, and canonical absent-input marker after explicit entry, allowing its owner-defined idempotent existing-actor result. `PRESEEDED_ONLY` calls `CanonicalGameplayRosterService.ListPreseededRoster` as a lookup: zero actors returns the pre-seeded-only denial, while a nonzero roster applies the same exact-one-versus-many selection rule without actor mutation. Its durable selection step binds the returned roster snapshot identity/digest and selected character; a retry calls `ReadSelectedPreseededAssignment` with that exact snapshot and selection and fails closed if the roster changed rather than silently selecting another actor. The separate wire accepts only `PRESEEDED_ONLY`; other policy values fail with `FAILED_PRECONDITION`. `PLAYER_CREATED` remains a later-owned policy-aware roster branch, and `AUTO_PROVISIONED` remains its owner-defined idempotent existing-actor operation; neither branch may use the legacy numeric `ListCharactersByAccount` RPC as canonical gameplay authority. No branch re-resolves policy or substitutes a different descriptor/template, namespace, scope, roster, or digest. Catalog and admission-pointer identity/semantics remain in [Multi-Tenancy](./system-architecture-multi-tenancy.md), while Game Session owns realm/pointer resolution, selection, and serving orchestration and Entity Management owns descriptor/template consumption and actor allocation/persistence. [ADR 0140](./decisions/adr-0140-realm-authored-controllable-actor-entry.md) remains decision rationale for this boundary; its canonical presence encoding is retained by the auto-provision request above. The Entity API contract names these target surfaces, but the current proto, implementation, and focused proof do not establish this saga. If a workflow needs restart-safe continuation, durable waits/timers, or operator-visible in-flight state that survives one service lifetime, it should use the shared Temporal substrate described in [Temporal Control-Plane Workflows](./system-architecture-temporal-workflows.md) instead of extending `SagaRunner` toward durable workflow behavior. @@ -359,7 +359,7 @@ explicitRealmEntry(discoveredEntry, discoveredEntryDigest): boundCreateCharacterRequestId, boundMutationDigest, boundCanonicalCreationInput) # replay before fresh-roster rejection return stored-or-replayed result - rosterSnapshot = Entity.ListCharactersByAccount(discoveredEntry, discoveredEntryDigest) + rosterSnapshot = Entity.ListCharactersByAccount(discoveredEntry, discoveredEntryDigest) # later-owned target contract; legacy numeric RPC is not canonical authority if retrying roster-selection step: require rosterSnapshot.identity == boundRosterSnapshot.identity require rosterSnapshot.digest == boundRosterSnapshot.digest @@ -396,11 +396,12 @@ explicitRealmEntry(discoveredEntry, discoveredEntryDigest): Entity.AutoProvisionCharacter(discoveredEntry, discoveredEntryDigest, autoProvisionRequestId, mutationDigest, canonicalCreationInput) PRESEEDED_ONLY: require creation input is absent - rosterSnapshot = Entity.ListCharactersByAccount(discoveredEntry, discoveredEntryDigest) if retrying selection step: - require rosterSnapshot.identity == boundRosterSnapshot.identity - require rosterSnapshot.digest == boundRosterSnapshot.digest + assignment = Entity.CanonicalGameplayRosterService.ReadSelectedPreseededAssignment(discoveredEntry, boundRosterSnapshot.reference, selectedCharacterId) + require assignment.snapshot == boundRosterSnapshot.reference + rosterSnapshot = boundRosterSnapshot else: + rosterSnapshot = Entity.CanonicalGameplayRosterService.ListPreseededRoster(discoveredEntry, discoveredEntryDigest) bind rosterSnapshot.identity and rosterSnapshot.digest to sagaStep roster = rosterSnapshot.roster if roster is zero: diff --git a/protos/entity-management/v1/entity_management_service.proto b/protos/entity-management/v1/entity_management_service.proto index 558083936b..66971a72b0 100644 --- a/protos/entity-management/v1/entity_management_service.proto +++ b/protos/entity-management/v1/entity_management_service.proto @@ -4,6 +4,7 @@ package entity_management.v1; import "shared/v1/errors.proto"; import "shared/v1/instance_refs.proto"; +import "shared/v1/player_execution_context.proto"; option java_package = "net.firedevops.firemud.entitymanagement.v1"; option java_multiple_files = true; @@ -36,22 +37,33 @@ service EntityManagementService { returns (ValidateEntityUpgradeMappingsResponse); } -// Canonical gameplay roster discovery is a separate non-admitting boundary. This wire contract -// does not authorize the legacy numeric ListCharactersByAccount RPC for canonical gameplay. A -// valid ListPreseededRoster response may contain zero actors; that is a successful lookup. These -// RPCs use canonical non-OK gRPC statuses rather than in-response errors: malformed requests are -// INVALID_ARGUMENT, stale snapshots or selections not present in the bound snapshot are -// FAILED_PRECONDITION, unauthorized callers are UNAUTHENTICATED or PERMISSION_DENIED as -// applicable, and unavailable dependencies are UNAVAILABLE. No partial success is returned. +// Canonical gameplay roster discovery is a pre-admission, non-admitting boundary. Both methods +// are restricted to PRESEEDED_ONLY; other policy values are non-authorizing and fail with +// FAILED_PRECONDITION. This wire contract does not authorize the legacy numeric +// ListCharactersByAccount RPC for canonical gameplay. A valid ListPreseededRoster response may +// contain zero actors; that is a successful lookup. These RPCs use canonical non-OK gRPC statuses +// rather than in-response errors: malformed requests are INVALID_ARGUMENT, stale snapshots or +// selections not present in the bound snapshot are FAILED_PRECONDITION, unauthorized callers are +// UNAUTHENTICATED or PERMISSION_DENIED as applicable, and unavailable dependencies are +// UNAVAILABLE. No partial success is returned. service CanonicalGameplayRosterService { - // Returns the persisted preseeded roster for the exact expected target. A successful response - // includes its immutable snapshot UUID and digest, including when the roster is empty. + // Returns the persisted preseeded roster for the exact expected target. The server requires an + // authenticated, server-derived PlayerExecutionContext and exact same-namespace Game Session + // mTLS caller allowlisting. Context account_id equals canonical_account_uuid; request_id equals + // request_uuid; tenant_id, realm_id, playable_state_namespace_id, playable_state_scope, and + // game_instance_id equal the corresponding expected_target values; session_id identifies the + // authenticated session. No character_id is selected yet. The target policy must be + // PRESEEDED_ONLY. These equality checks do not require an additional Account lookup. A + // successful response includes its immutable snapshot UUID and digest, including when the + // roster is empty. rpc ListPreseededRoster(CanonicalGameplayRosterRequest) returns (CanonicalGameplayRosterResponse); // Reads the selected assignment only if the supplied snapshot UUID and digest still identify // the roster from which selected_character_uuid was chosen. The response echoes that exact // snapshot reference. A changed snapshot or selection absent from it fails with - // FAILED_PRECONDITION. + // FAILED_PRECONDITION. It has the same authenticated context and exact target equality + // requirements as ListPreseededRoster, and context.character_id must equal + // selected_character_uuid. The target policy must be PRESEEDED_ONLY. rpc ReadSelectedPreseededAssignment(CanonicalGameplayRosterSelectedAssignmentRequest) returns (CanonicalGameplayRosterSelectedAssignmentResponse); } @@ -60,6 +72,7 @@ message CanonicalGameplayRosterRequest { string request_uuid = 1; string canonical_account_uuid = 2; CanonicalGameplayRosterTarget expected_target = 3; + shared.v1.PlayerExecutionContext player_execution_context = 4; } message CanonicalGameplayRosterTarget { @@ -120,6 +133,7 @@ message CanonicalGameplayRosterSelectedAssignmentRequest { // Exact snapshot_uuid and snapshot_digest returned by ListPreseededRoster. Retries must reuse // these values and may not silently select against a changed roster. CanonicalGameplayRosterSnapshotReference expected_snapshot = 5; + shared.v1.PlayerExecutionContext player_execution_context = 6; } message CanonicalGameplayRosterSelectedAssignmentResponse { diff --git a/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java b/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java index 1bb8daa592..6fde8fe528 100644 --- a/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java +++ b/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java @@ -4,13 +4,22 @@ import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.FieldDescriptor; +import net.firedevops.firemud.entitymanagement.v1.CanonicalGameplayRosterRequest; import net.firedevops.firemud.entitymanagement.v1.CanonicalGameplayRosterResponse; import net.firedevops.firemud.entitymanagement.v1.CanonicalGameplayRosterSelectedAssignmentRequest; import net.firedevops.firemud.entitymanagement.v1.CanonicalGameplayRosterSelectedAssignmentResponse; import net.firedevops.firemud.entitymanagement.v1.CanonicalGameplayRosterSnapshotReference; +import net.firedevops.firemud.shared.v1.PlayerExecutionContext; import org.junit.jupiter.api.Test; class CanonicalGameplayRosterProtoDescriptorTest { + @Test + void canonicalRosterRequestsCarryTheTypedPlayerExecutionContext() { + assertPlayerExecutionContextField(CanonicalGameplayRosterRequest.getDescriptor(), 4); + assertPlayerExecutionContextField( + CanonicalGameplayRosterSelectedAssignmentRequest.getDescriptor(), 6); + } + @Test void selectedAssignmentRoundTripsTheExactTypedSnapshotReference() { FieldDescriptor expectedSnapshot = @@ -47,4 +56,10 @@ private static void assertErrorSlotReserved(Descriptor descriptor, int fieldNumb .anySatisfy(range -> assertThat(range.getStart()).isEqualTo(fieldNumber)); assertThat(descriptor.toProto().getReservedNameList()).contains("error"); } + + private static void assertPlayerExecutionContextField(Descriptor descriptor, int fieldNumber) { + FieldDescriptor context = descriptor.findFieldByNumber(fieldNumber); + assertThat(context.getName()).isEqualTo("player_execution_context"); + assertThat(context.getMessageType()).isEqualTo(PlayerExecutionContext.getDescriptor()); + } } From a6efc8fe192de77192f062c454697234ebd5e101 Mon Sep 17 00:00:00 2001 From: Ben Hook <5009589+benhook1013@users.noreply.github.com> Date: Fri, 9 Oct 2026 09:10:02 +1300 Subject: [PATCH 4/5] Keep roster selection readback non-authorizing --- .../api-contracts.md | 4 ++-- .../game-session-service/api-contracts.md | 2 +- .../system-architecture-transactions.md | 11 ++++++++--- .../v1/entity_management_service.proto | 19 +++++++++++-------- ...icalGameplayRosterProtoDescriptorTest.java | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/design/architecture/microservices/entity-management-service/api-contracts.md b/design/architecture/microservices/entity-management-service/api-contracts.md index d3393450d9..dea1eea61b 100644 --- a/design/architecture/microservices/entity-management-service/api-contracts.md +++ b/design/architecture/microservices/entity-management-service/api-contracts.md @@ -6,7 +6,7 @@ The authoritative REST schema source lives in [../../../../services/entity-manag ## Implementation Status -The separate `CanonicalGameplayRosterService` proto is a wire contract only; it has no handler or activation in the current stage. Its two methods define pre-admission, non-admitting reads restricted to `PRESEEDED_ONLY`; any other policy value is non-authorizing and returns `FAILED_PRECONDITION`. `ListPreseededRoster` may successfully return zero actors and binds the exact target to its snapshot UUID and digest. `ReadSelectedPreseededAssignment` requires that same typed snapshot reference, echoes it on success, and returns `FAILED_PRECONDITION` if it is stale or the selected actor is absent from it. Both require a server-derived typed `PlayerExecutionContext`, the exact same-namespace Game Session mTLS caller allowlist, and equality between context and request/target fields. The initial roster read has no selected actor and requires no admitted-character or current-binding proof; the selection read requires `context.character_id` to equal `selected_character_uuid`. The context is unsigned scope data, not a credential, and does not authorize an additional Account lookup solely for the read. Malformed input is `INVALID_ARGUMENT`; authorization failures are `UNAUTHENTICATED` or `PERMISSION_DENIED` as applicable; unavailable dependencies are `UNAVAILABLE`. Failures use non-OK gRPC status with no partial response, not response-level `ErrorDetail`. These semantics do not authorize the legacy numeric `ListCharactersByAccount` RPC for canonical gameplay. +The separate `CanonicalGameplayRosterService` proto is a wire contract only; it has no handler or activation in the current stage. Its two methods define pre-admission, non-admitting reads restricted to `PRESEEDED_ONLY`; any other policy value is non-authorizing and returns `FAILED_PRECONDITION`. `ListPreseededRoster` may successfully return zero actors and binds the exact target to its snapshot UUID and digest. `ReadSelectedPreseededAssignment` requires that same typed snapshot reference, echoes the exact request/account/selected-character/target/snapshot discovery bindings, and returns `FAILED_PRECONDITION` if the snapshot is stale or the selected actor is absent from it. Its response does not mint an assignment receipt or prove admission; any later assignment/admission write and authoritative readback remain with the owning downstream operation. Both methods require a server-derived typed `PlayerExecutionContext`, the exact same-namespace Game Session mTLS caller allowlist, and equality between context and request/target fields. Context `playable_state_scope` is exactly the text `SHARED` or `ISOLATED` matching the target enum, never numeric enum text. The initial roster read has no selected actor and requires no admitted-character or current-binding proof; the selection read requires `context.character_id` to equal `selected_character_uuid`. The context is unsigned scope data, not a credential, and does not authorize an additional Account lookup solely for the read. Malformed input is `INVALID_ARGUMENT`; authorization failures are `UNAUTHENTICATED` or `PERMISSION_DENIED` as applicable; unavailable dependencies are `UNAVAILABLE`. Failures use non-OK gRPC status with no partial response, not response-level `ErrorDetail`. These semantics do not authorize the legacy numeric `ListCharactersByAccount` RPC for canonical gameplay. The live crafting REST surface is runtime-reachable but is not a tenant-authorized gameplay or design-time boundary: `POST /crafting/recipes` accepts a caller-supplied `tenantId` in `CraftingRecipeDto`, and `GET /crafting/recipes/{id}` accepts only a globally-shaped recipe id. The ping-only authoritative OpenAPI document declares root `security: []`; the crafting handlers and schemas are omitted from that contract. The deployed Entity HTTP interceptor currently requires only an `AUTHENTICATED` bearer (crafting is not in the public-route list), while the controllers do not apply `SessionContext` tenant authorization and the service/repository do not bind either operation to the authenticated caller. The create path can therefore persist a caller-selected tenant (and an existing DTO id can update by id), while the read path performs an ID-only recipe lookup. `CraftingControllerTest` and `CraftingServiceImplTest` cover request/recipe validation and happy-path persistence only; they do not prove unauthenticated denial, tenant-qualified lookup/update, or cross-tenant item ownership. The handlers must remain unsupported/fenced or gain the target caller-bound authorization before they can be treated as a supported route. @@ -41,7 +41,7 @@ curl http://localhost:8080/ping ## gRPC - `Ping(PingRequest) returns (PingResponse)` – connectivity check defined in `entity_management_service.proto`. -- `CanonicalGameplayRosterService.ListPreseededRoster` and `ReadSelectedPreseededAssignment` – separate target wire contract for the `PRESEEDED_ONLY` pre-admission roster branch. Both carry `shared.v1.PlayerExecutionContext`; the first binds the authenticated account/session/request and prospective tenant/realm/namespace/scope/instance target, while the second additionally binds `context.character_id` to the selected UUID and the exact roster snapshot. The exact same-namespace Game Session workload mTLS identity is allowlisted. These reads are not actor admission or a session-binding shortcut, and their proto has no handler or activation yet. +- `CanonicalGameplayRosterService.ListPreseededRoster` and `ReadSelectedPreseededAssignment` – separate target wire contract for the `PRESEEDED_ONLY` pre-admission roster branch. Both carry `shared.v1.PlayerExecutionContext`; its scope string is exactly `SHARED` or `ISOLATED` matching the target enum, never numeric enum text. The first binds the authenticated account/session/request and prospective tenant/realm/namespace/scope/instance target, while the second additionally binds `context.character_id` to the selected UUID and exact roster snapshot. The selection response echoes discovery bindings only; it mints no assignment receipt or admission proof, which remain with the owning downstream write/readback. The exact same-namespace Game Session workload mTLS identity is allowlisted. These reads are not actor admission or a session-binding shortcut, and their proto has no handler or activation yet. - `CreateCharacter(CreateCharacterRequest) returns (CreateCharacterResponse)` – Entity-owned allocation and persistence of a primary controllable actor after the caller has passed Account membership/grant/realm admission. The target request carries the resolved `{accountId, tenantId, worldSlug, realmSlug}`, stable `playableStateNamespaceId`, the `playableStateScope` supplied only as authoritative realm-snapshot/attestation evidence, active `gameInstanceId`, explicit `entryPolicy=PLAYER_CREATED`, exact published descriptor identity/version, player creation input, and proof of the catalog/admission-pointer snapshot. Entity rejects a missing or mismatched policy before allocation or replay, and cross-checks the policy against the canonical snapshot and the applicable descriptor identity/version. It also carries caller-stable `createCharacterRequestId` and canonical `mutationDigest`; Entity recomputes the digest over the immutable trusted target, `entryPolicy`, exact descriptor/version, and creation input. The durable operation guard key is `{tenantId, playableStateNamespaceId, accountId, createCharacterRequestId}`. Within one local transaction, Entity admits and locks that guard plus digest, serializes the `PLAYER_CREATED` zero-roster boundary on `{tenantId, playableStateNamespaceId, accountId}`, and rereads the roster against the unchanged policy and descriptor/version before allocation. Only a still-empty roster may allocate; concurrent distinct request identities cannot both cross a stale zero-roster observation. Entity then atomically persists the allocated `{accountId, tenantId, playableStateNamespaceId, characterId}` association and replayable response. The same guard and digest exact-replay the original response; the same guard with a different digest returns `IDEMPOTENCY_CONFLICT` before allocation. Callers cannot choose or derive `playableStateScope`; Entity must reject caller-derived evidence and validate the exact immutable namespace/scope pair. A scope change under one namespace is rejected and never creates a second or split actor record. Entity allocates `characterId` only after the operation guard, validates the namespace/scope and active-instance fence, and never derives identity from account/name/hash or delegates character ownership to Account. Durable persistence/keying remains `{tenantId, playableStateNamespaceId, characterId}`; `playableStateScope` remains separately validated immutable routing/authorization evidence, `gameInstanceId` is only the replaceable active-runtime fence, and neither is a durable character-identity dimension. Entity Management does not expose a direct player REST route. The current request path and enforcement do not yet prove this complete target boundary, so it remains an implementation/proof gap rather than a claim about live enforcement. - `UpdateEntity(UpdateEntityRequest) returns (UpdateEntityResponse)` – updates mutable character state for the requested `{tenantId, playableStateNamespaceId, gameInstanceId, playableStateScope, characterId}` target. `playableStateScope` must be the authoritative realm-snapshot/attestation result; callers cannot choose or derive it, and Entity validates the exact immutable namespace/scope pair before mutation. A caller-selected or changed scope, missing/mismatched namespace or scope, stale snapshot, caller-asserted instance, or global `characterId` is rejected rather than updating or splitting records. Target state also requires a fresh, server-resolved active-instance authorization fence for that exact namespace/scope and instance, checked atomically immediately before mutation. The current request path does not yet carry and prove the complete fresh fence, so it remains an implementation/proof gap and must not be treated as target enforcement. - `QueryInventory(QueryInventoryRequest) returns (QueryInventoryResponse)` – the current response is an unpaged repeated `InventoryItem items[]` projection. The live handler emits `item_id`, `item_name`, `item_description`, and `quantity`, and conditionally emits `container_instance_id`, `item_instance_id`, and `visible_ref` when those values are present. This projection does not establish complete instance-aware identity or stack/concurrency safety: rich pagination, complete holder-local stack uniqueness, find-then-create concurrency, and explicit-family duplicate handling remain target/proof gaps documented in [Runtime and Data](./runtime-and-data.md#implementation-status). diff --git a/design/architecture/microservices/game-session-service/api-contracts.md b/design/architecture/microservices/game-session-service/api-contracts.md index c0b07e0052..5ac122863b 100644 --- a/design/architecture/microservices/game-session-service/api-contracts.md +++ b/design/architecture/microservices/game-session-service/api-contracts.md @@ -30,7 +30,7 @@ For script transitions, the live boundary includes the exact `scriptPinEpoch` an Game Session communicates with other platform services exclusively via gRPC for gameplay-domain work. Player-delegated calls carry the typed unsigned `PlayerExecutionContext` defined in the authentication architecture, including the required gameplay scope for admission. Downstream services authenticate the concrete mTLS caller, enforce an exact RPC caller allowlist, validate context/request equality and domain scope, and reject client-supplied identity metadata. Routine gameplay calls do not use signed per-action attestations or a generic replay cache; mutations retain their owning command/effect/request idempotency. -The Entity `CanonicalGameplayRosterService` calls for `PRESEEDED_ONLY` are pre-admission discovery reads, not already-admitted player actions. Game Session supplies a server-derived `PlayerExecutionContext` containing authenticated account, session, request, and the prospective tenant/realm/namespace/scope/instance target, and calls under the exact same-namespace Game Session mTLS identity allowlisted for each method. Entity requires exact context/request/target equality. The initial roster request has no selected actor or admitted-character/current-binding requirement; for `ReadSelectedPreseededAssignment`, `context.character_id` equals `selected_character_uuid`. The unsigned context is scope data, not a credential, and these reads add no Account lookup solely for authorization. This wire currently has no handler or activation, and its policy does not authorize other roster branches or actor admission. +The Entity `CanonicalGameplayRosterService` calls for `PRESEEDED_ONLY` are pre-admission discovery reads, not already-admitted player actions. Game Session supplies a server-derived `PlayerExecutionContext` containing authenticated account, session, request, and the prospective tenant/realm/namespace/scope/instance target, and calls under the exact same-namespace Game Session mTLS identity allowlisted for each method. Entity requires exact context/request/target equality; context `playable_state_scope` is the exact text `SHARED` or `ISOLATED` matching the target enum, never numeric enum text. The initial roster request has no selected actor or admitted-character/current-binding requirement; for `ReadSelectedPreseededAssignment`, `context.character_id` equals `selected_character_uuid`. Its response echoes discovery bindings only and mints no assignment receipt or admission proof. Any later assignment/admission write and authoritative readback remain with the owning downstream operation. The unsigned context is scope data, not a credential, and these reads add no Account lookup solely for authorization. This wire currently has no handler or activation, and its policy does not authorize other roster branches or actor admission. For target gameplay forwarding, `PlayerExecutionContext` carries the server-resolved `{tenantId, playableStateNamespaceId, playableStateScope, gameInstanceId}` binding and, for region-scoped work, its `{regionId, regionEpoch}` fence as one context. Game Session forwards the namespace and scope unchanged and validates exact context/request equality on every downstream response or mutation result; it never accepts a caller-selected namespace or substitutes a current one after admission. The current context/forwarding wire is narrower in places and does not yet carry or prove this complete namespace-plus-fence tuple, so that path remains an implementation/proof gap and must fail closed on missing authority. diff --git a/design/architecture/system-architecture-transactions.md b/design/architecture/system-architecture-transactions.md index dcc649c22c..9b6b1d981c 100644 --- a/design/architecture/system-architecture-transactions.md +++ b/design/architecture/system-architecture-transactions.md @@ -252,7 +252,7 @@ These workflows: For `explicitRealmEntry`, the accepted policy outcomes are exactly `PLAYER_CREATED`, `AUTO_PROVISIONED`, and `PRESEEDED_ONLY`; the immutable discovered-entry request may carry an optional `selectedCharacterId`, and its digest covers that selection without duplicating policy semantics. For any branch that reads a roster, the durable saga step binds the selected policy branch, Entity-returned roster snapshot identity/digest, and resolved selected character when one exists; retries reuse those applicable values rather than silently following a changed roster. The saga branches on that unchanged bound outcome: `PLAYER_CREATED` first uses its later-owned policy-aware Entity roster contract against the unchanged bound target, then evaluates any supplied creation input against that roster. An exactly-one roster auto-selects its actor; if the request supplies `selectedCharacterId`, it must equal that one actor. A multiple-actor roster requires an explicit `selectedCharacterId` that belongs to the unchanged roster/snapshot; missing or invalid selection fails before binding. Any supplied creation input is valid only for a zero-roster `PLAYER_CREATED` branch; after the roster lookup, a nonempty `PLAYER_CREATED` roster rejects its presence before selection, binding, or mutation, while `AUTO_PROVISIONED` and `PRESEEDED_ONLY` reject it before their branch-specific lookup or mutation. A zero roster with no creation input offers/requires creation without mutation, and zero-roster creation never accepts a caller-selected character ID. A submitted creation input with absent required fields, malformed data, or failure to validate against the exact realm-published descriptor and version bound in the discovered-entry object fails closed; and only valid submitted input calls `CreateCharacter` with the unchanged discovered-entry object/digest plus that input. The preliminary roster read is discovery and selection evidence, not concurrency authority; the Entity-owned `CreateCharacter` contract serializes and rereads the zero-roster boundary before allocation. If a durable saga step has already entered `CreateCharacter`, a retry calls Entity with the stored request identity, digest, and canonical input before any fresh roster rejection so a committed operation with a lost response replays its original result. Each mutating branch carries a caller-stable operation request identity derived from its durable forward saga-step identity (`createCharacterRequestId` for `PLAYER_CREATED`, `autoProvisionRequestId` for `AUTO_PROVISIONED`) and a `mutationDigest` over the trusted target, exact descriptor or template identity/version, and canonical `creationInput`; the auto-provision branch uses the explicit absent-input marker defined by [ADR 0140](./decisions/adr-0140-realm-authored-controllable-actor-entry.md). Entity recomputes and binds the digest and operation identity, while `discoveredEntryDigest` remains admission/discovery evidence rather than actor-write identity. A retry reuses the same operation identity, digest, and canonical input and replays the original result; changed target, descriptor/template/version, or input fails closed as an idempotency conflict. The separate `CanonicalGameplayRosterService.ListPreseededRoster` wire implements only the pre-admission `PRESEEDED_ONLY` lookup; `PLAYER_CREATED` remains a later-owned target branch, and neither it nor `AUTO_PROVISIONED` may fall back to the legacy numeric `ListCharactersByAccount` RPC for canonical gameplay. -`AUTO_PROVISIONED` requires `selectedCharacterId` to be absent; any supplied selection fails closed before the provisioning call. It calls `AutoProvisionCharacter` with the same immutable discovered-entry inputs plus its stable `autoProvisionRequestId`, `mutationDigest`, and canonical absent-input marker after explicit entry, allowing its owner-defined idempotent existing-actor result. `PRESEEDED_ONLY` calls `CanonicalGameplayRosterService.ListPreseededRoster` as a lookup: zero actors returns the pre-seeded-only denial, while a nonzero roster applies the same exact-one-versus-many selection rule without actor mutation. Its durable selection step binds the returned roster snapshot identity/digest and selected character; a retry calls `ReadSelectedPreseededAssignment` with that exact snapshot and selection and fails closed if the roster changed rather than silently selecting another actor. The separate wire accepts only `PRESEEDED_ONLY`; other policy values fail with `FAILED_PRECONDITION`. `PLAYER_CREATED` remains a later-owned policy-aware roster branch, and `AUTO_PROVISIONED` remains its owner-defined idempotent existing-actor operation; neither branch may use the legacy numeric `ListCharactersByAccount` RPC as canonical gameplay authority. No branch re-resolves policy or substitutes a different descriptor/template, namespace, scope, roster, or digest. Catalog and admission-pointer identity/semantics remain in [Multi-Tenancy](./system-architecture-multi-tenancy.md), while Game Session owns realm/pointer resolution, selection, and serving orchestration and Entity Management owns descriptor/template consumption and actor allocation/persistence. [ADR 0140](./decisions/adr-0140-realm-authored-controllable-actor-entry.md) remains decision rationale for this boundary; its canonical presence encoding is retained by the auto-provision request above. The Entity API contract names these target surfaces, but the current proto, implementation, and focused proof do not establish this saga. +`AUTO_PROVISIONED` requires `selectedCharacterId` to be absent; any supplied selection fails closed before the provisioning call. It calls `AutoProvisionCharacter` with the same immutable discovered-entry inputs plus its stable `autoProvisionRequestId`, `mutationDigest`, and canonical absent-input marker after explicit entry, allowing its owner-defined idempotent existing-actor result. `PRESEEDED_ONLY` calls `CanonicalGameplayRosterService.ListPreseededRoster` as a lookup: zero actors returns the pre-seeded-only denial, while a nonzero roster applies the same exact-one-versus-many selection rule without actor mutation. Its durable selection step binds the returned roster snapshot identity/digest and selected character; a retry calls `ReadSelectedPreseededAssignment` with that exact snapshot and selection and fails closed if the roster changed rather than silently selecting another actor. The response echoes request/account/selected-character/target/snapshot discovery bindings only: it mints no assignment receipt and proves no admission. Any later assignment/admission write and authoritative readback remain with the owning downstream operation. The separate wire accepts only `PRESEEDED_ONLY`; other policy values fail with `FAILED_PRECONDITION`. `PLAYER_CREATED` remains a later-owned policy-aware roster branch, and `AUTO_PROVISIONED` remains its owner-defined idempotent existing-actor operation; neither branch may use the legacy numeric `ListCharactersByAccount` RPC as canonical gameplay authority. No branch re-resolves policy or substitutes a different descriptor/template, namespace, scope, roster, or digest. Catalog and admission-pointer identity/semantics remain in [Multi-Tenancy](./system-architecture-multi-tenancy.md), while Game Session owns realm/pointer resolution, selection, and serving orchestration and Entity Management owns descriptor/template consumption and actor allocation/persistence. [ADR 0140](./decisions/adr-0140-realm-authored-controllable-actor-entry.md) remains decision rationale for this boundary; its canonical presence encoding is retained by the auto-provision request above. The Entity API contract names these target surfaces, but the current proto, implementation, and focused proof do not establish this saga. If a workflow needs restart-safe continuation, durable waits/timers, or operator-visible in-flight state that survives one service lifetime, it should use the shared Temporal substrate described in [Temporal Control-Plane Workflows](./system-architecture-temporal-workflows.md) instead of extending `SagaRunner` toward durable workflow behavior. @@ -397,8 +397,13 @@ explicitRealmEntry(discoveredEntry, discoveredEntryDigest): PRESEEDED_ONLY: require creation input is absent if retrying selection step: - assignment = Entity.CanonicalGameplayRosterService.ReadSelectedPreseededAssignment(discoveredEntry, boundRosterSnapshot.reference, selectedCharacterId) - require assignment.snapshot == boundRosterSnapshot.reference + selectionReadback = Entity.CanonicalGameplayRosterService.ReadSelectedPreseededAssignment(discoveredEntry, boundRosterSnapshot.reference, selectedCharacterId) + require selectionReadback.request_uuid == boundRequest.request_uuid + require selectionReadback.canonical_account_uuid == boundRequest.canonical_account_uuid + require selectionReadback.selected_character_uuid == selectedCharacterId + require selectionReadback.target == boundRequest.expected_target + require selectionReadback.snapshot == boundRosterSnapshot.reference + # discovery binding only; assignment/admission write and readback are downstream rosterSnapshot = boundRosterSnapshot else: rosterSnapshot = Entity.CanonicalGameplayRosterService.ListPreseededRoster(discoveredEntry, discoveredEntryDigest) diff --git a/protos/entity-management/v1/entity_management_service.proto b/protos/entity-management/v1/entity_management_service.proto index 66971a72b0..69a7bb6fd1 100644 --- a/protos/entity-management/v1/entity_management_service.proto +++ b/protos/entity-management/v1/entity_management_service.proto @@ -52,10 +52,11 @@ service CanonicalGameplayRosterService { // mTLS caller allowlisting. Context account_id equals canonical_account_uuid; request_id equals // request_uuid; tenant_id, realm_id, playable_state_namespace_id, playable_state_scope, and // game_instance_id equal the corresponding expected_target values; session_id identifies the - // authenticated session. No character_id is selected yet. The target policy must be - // PRESEEDED_ONLY. These equality checks do not require an additional Account lookup. A - // successful response includes its immutable snapshot UUID and digest, including when the - // roster is empty. + // authenticated session. Context playable_state_scope is the exact text "SHARED" or + // "ISOLATED" corresponding to the target enum value; numeric enum text is invalid. No + // character_id is selected yet. The target policy must be PRESEEDED_ONLY. These equality + // checks do not require an additional Account lookup. A successful response includes its + // immutable snapshot UUID and digest, including when the roster is empty. rpc ListPreseededRoster(CanonicalGameplayRosterRequest) returns (CanonicalGameplayRosterResponse); // Reads the selected assignment only if the supplied snapshot UUID and digest still identify @@ -141,11 +142,13 @@ message CanonicalGameplayRosterSelectedAssignmentResponse { string canonical_account_uuid = 2; string selected_character_uuid = 3; CanonicalGameplayRosterTarget target = 4; - string assignment_uuid = 5; - string intent_digest = 6; + reserved 5, 6; reserved 7; - reserved "error"; - // Exact snapshot reference supplied by the caller and validated by this operation. + reserved "assignment_uuid", "intent_digest", "error"; + // Exact snapshot reference supplied by the caller and validated by this operation. The + // response echoes discovery bindings only; it does not mint an assignment receipt or prove + // admission. Any later assignment/admission write and its authoritative readback belong to + // the owning downstream operation. CanonicalGameplayRosterSnapshotReference snapshot = 8; } diff --git a/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java b/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java index 6fde8fe528..780b51b380 100644 --- a/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java +++ b/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java @@ -51,6 +51,24 @@ void canonicalRosterResponsesHaveNoInResponseErrorAndReserveItsSlot() { .isEqualTo("snapshot"); } + @Test + void selectedAssignmentResponseReservesUnsupportedAssignmentReceiptSlots() { + Descriptor response = CanonicalGameplayRosterSelectedAssignmentResponse.getDescriptor(); + + assertThat(response.findFieldByNumber(5)).isNull(); + assertThat(response.findFieldByNumber(6)).isNull(); + for (int fieldNumber : new int[] {5, 6}) { + assertThat(response.toProto().getReservedRangeList()) + .anySatisfy( + range -> { + assertThat(range.getStart()).isLessThanOrEqualTo(fieldNumber); + assertThat(range.getEnd()).isGreaterThan(fieldNumber); + }); + } + assertThat(response.toProto().getReservedNameList()) + .contains("assignment_uuid", "intent_digest"); + } + private static void assertErrorSlotReserved(Descriptor descriptor, int fieldNumber) { assertThat(descriptor.toProto().getReservedRangeList()) .anySatisfy(range -> assertThat(range.getStart()).isEqualTo(fieldNumber)); From 32924d7160732a2fd17bab7305584bb077ddf150 Mon Sep 17 00:00:00 2001 From: Ben Hook <5009589+benhook1013@users.noreply.github.com> Date: Fri, 9 Oct 2026 09:25:36 +1300 Subject: [PATCH 5/5] Define roster selection as original persisted Entity assignment evidence --- .../api-contracts.md | 4 +++- .../game-session-service/api-contracts.md | 2 +- .../system-architecture-transactions.md | 14 ++++++++++-- .../v1/entity_management_service.proto | 14 +++++++----- ...icalGameplayRosterProtoDescriptorTest.java | 22 ++++++++----------- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/design/architecture/microservices/entity-management-service/api-contracts.md b/design/architecture/microservices/entity-management-service/api-contracts.md index dea1eea61b..170937331c 100644 --- a/design/architecture/microservices/entity-management-service/api-contracts.md +++ b/design/architecture/microservices/entity-management-service/api-contracts.md @@ -6,7 +6,9 @@ The authoritative REST schema source lives in [../../../../services/entity-manag ## Implementation Status -The separate `CanonicalGameplayRosterService` proto is a wire contract only; it has no handler or activation in the current stage. Its two methods define pre-admission, non-admitting reads restricted to `PRESEEDED_ONLY`; any other policy value is non-authorizing and returns `FAILED_PRECONDITION`. `ListPreseededRoster` may successfully return zero actors and binds the exact target to its snapshot UUID and digest. `ReadSelectedPreseededAssignment` requires that same typed snapshot reference, echoes the exact request/account/selected-character/target/snapshot discovery bindings, and returns `FAILED_PRECONDITION` if the snapshot is stale or the selected actor is absent from it. Its response does not mint an assignment receipt or prove admission; any later assignment/admission write and authoritative readback remain with the owning downstream operation. Both methods require a server-derived typed `PlayerExecutionContext`, the exact same-namespace Game Session mTLS caller allowlist, and equality between context and request/target fields. Context `playable_state_scope` is exactly the text `SHARED` or `ISOLATED` matching the target enum, never numeric enum text. The initial roster read has no selected actor and requires no admitted-character or current-binding proof; the selection read requires `context.character_id` to equal `selected_character_uuid`. The context is unsigned scope data, not a credential, and does not authorize an additional Account lookup solely for the read. Malformed input is `INVALID_ARGUMENT`; authorization failures are `UNAUTHENTICATED` or `PERMISSION_DENIED` as applicable; unavailable dependencies are `UNAVAILABLE`. Failures use non-OK gRPC status with no partial response, not response-level `ErrorDetail`. These semantics do not authorize the legacy numeric `ListCharactersByAccount` RPC for canonical gameplay. +The separate `CanonicalGameplayRosterService` proto is a wire contract only; it has no handler or activation in the current stage. Its two methods define pre-admission, non-admitting reads restricted to `PRESEEDED_ONLY`; any other policy value is non-authorizing and returns `FAILED_PRECONDITION`. `ListPreseededRoster` may successfully return zero actors and binds the exact target to its snapshot UUID and digest. `ReadSelectedPreseededAssignment` requires that same typed snapshot reference, echoes the exact request/account/selected-character/target/snapshot bindings, and returns `FAILED_PRECONDITION` if the snapshot is stale or the selected actor is absent from it. It also returns the original non-nil assignment operation UUID and immutable intent digest from the unique matching committed `ASSIGNED` `PRESEEDED_ONLY` `PLAYER` receipt. Entity resolves that receipt only for the exact account, selected actor, complete expected target, current owner counters, and published owner-proof digest; zero or multiple matches disclose no reference, and readback must match the same receipt. The response is persisted owner evidence, not a newly minted identity, an admission grant, or proof that Account eligibility remains current. Both methods require a server-derived typed `PlayerExecutionContext`, the exact same-namespace Game Session mTLS caller allowlist, and equality between context and request/target fields. Context `playable_state_scope` is exactly the text `SHARED` or `ISOLATED` matching the target enum, never numeric enum text. The initial roster read has no selected actor and requires no admitted-character or current-binding proof; the selection read requires `context.character_id` to equal `selected_character_uuid`. The context is unsigned scope data, not a credential, and does not authorize an additional Account lookup solely for the read. Malformed input is `INVALID_ARGUMENT`; authorization failures are `UNAUTHENTICATED` or `PERMISSION_DENIED` as applicable; unavailable dependencies are `UNAVAILABLE`. Failures use non-OK gRPC status with no partial response, not response-level `ErrorDetail`. These semantics do not authorize the legacy numeric `ListCharactersByAccount` RPC for canonical gameplay. + +The `ReadSelectedPreseededAssignment` `intent_digest` is the lowercase hexadecimal SHA-256 of Entity's immutable assignment-intent preimage. Entity serializes these UTF-8 string values in this exact order: domain `firemud.entity.preseeded-actor-assignment.v4`; original `assignmentUuid`; `canonicalAccountUuid`; core `actorKind`; core `displayName`; target `canonicalTenantUuid`; `realmUuid`; `worldSlug`; `realmSlug`; `gameInstanceId`; base-10 `catalogRevision`; `canonicalVersionUuid`; `frozenPolicyDigest`; `playableStateNamespaceId`; `publishedReleaseBundleRef`; `playableStateScope`; and `entryPolicy`. UUIDs use canonical `UUID.toString()` form, counters use base-10 decimal text, and scope/policy values use their canonical enum names. Each value is encoded as UTF-8 and prefixed by its byte length as a four-byte big-endian integer; SHA-256 covers the concatenated length-prefixed values. The digest is the original persisted operation-intent digest, not a digest of current owner evidence or current Account state. The live crafting REST surface is runtime-reachable but is not a tenant-authorized gameplay or design-time boundary: `POST /crafting/recipes` accepts a caller-supplied `tenantId` in `CraftingRecipeDto`, and `GET /crafting/recipes/{id}` accepts only a globally-shaped recipe id. The ping-only authoritative OpenAPI document declares root `security: []`; the crafting handlers and schemas are omitted from that contract. The deployed Entity HTTP interceptor currently requires only an `AUTHENTICATED` bearer (crafting is not in the public-route list), while the controllers do not apply `SessionContext` tenant authorization and the service/repository do not bind either operation to the authenticated caller. The create path can therefore persist a caller-selected tenant (and an existing DTO id can update by id), while the read path performs an ID-only recipe lookup. `CraftingControllerTest` and `CraftingServiceImplTest` cover request/recipe validation and happy-path persistence only; they do not prove unauthenticated denial, tenant-qualified lookup/update, or cross-tenant item ownership. The handlers must remain unsupported/fenced or gain the target caller-bound authorization before they can be treated as a supported route. diff --git a/design/architecture/microservices/game-session-service/api-contracts.md b/design/architecture/microservices/game-session-service/api-contracts.md index 5ac122863b..2e13bb6f0d 100644 --- a/design/architecture/microservices/game-session-service/api-contracts.md +++ b/design/architecture/microservices/game-session-service/api-contracts.md @@ -30,7 +30,7 @@ For script transitions, the live boundary includes the exact `scriptPinEpoch` an Game Session communicates with other platform services exclusively via gRPC for gameplay-domain work. Player-delegated calls carry the typed unsigned `PlayerExecutionContext` defined in the authentication architecture, including the required gameplay scope for admission. Downstream services authenticate the concrete mTLS caller, enforce an exact RPC caller allowlist, validate context/request equality and domain scope, and reject client-supplied identity metadata. Routine gameplay calls do not use signed per-action attestations or a generic replay cache; mutations retain their owning command/effect/request idempotency. -The Entity `CanonicalGameplayRosterService` calls for `PRESEEDED_ONLY` are pre-admission discovery reads, not already-admitted player actions. Game Session supplies a server-derived `PlayerExecutionContext` containing authenticated account, session, request, and the prospective tenant/realm/namespace/scope/instance target, and calls under the exact same-namespace Game Session mTLS identity allowlisted for each method. Entity requires exact context/request/target equality; context `playable_state_scope` is the exact text `SHARED` or `ISOLATED` matching the target enum, never numeric enum text. The initial roster request has no selected actor or admitted-character/current-binding requirement; for `ReadSelectedPreseededAssignment`, `context.character_id` equals `selected_character_uuid`. Its response echoes discovery bindings only and mints no assignment receipt or admission proof. Any later assignment/admission write and authoritative readback remain with the owning downstream operation. The unsigned context is scope data, not a credential, and these reads add no Account lookup solely for authorization. This wire currently has no handler or activation, and its policy does not authorize other roster branches or actor admission. +The Entity `CanonicalGameplayRosterService` calls for `PRESEEDED_ONLY` are pre-admission discovery reads, not already-admitted player actions. Game Session supplies a server-derived `PlayerExecutionContext` containing authenticated account, session, request, and the prospective tenant/realm/namespace/scope/instance target, and calls under the exact same-namespace Game Session mTLS identity allowlisted for each method. Entity requires exact context/request/target equality; context `playable_state_scope` is the exact text `SHARED` or `ISOLATED` matching the target enum, never numeric enum text. The initial roster request has no selected actor or admitted-character/current-binding requirement; for `ReadSelectedPreseededAssignment`, `context.character_id` equals `selected_character_uuid`. Its response echoes discovery bindings and returns the original assignment operation UUID and immutable intent digest from Entity's unique matching committed receipt. Game Session binds and reuses that original reference for later owner revalidation; it does not mint an assignment identity or treat the reference as admission proof or current Account eligibility. The unsigned context is scope data, not a credential, and these reads add no Account lookup solely for authorization. This wire currently has no handler or activation, and its policy does not authorize other roster branches or actor admission. For target gameplay forwarding, `PlayerExecutionContext` carries the server-resolved `{tenantId, playableStateNamespaceId, playableStateScope, gameInstanceId}` binding and, for region-scoped work, its `{regionId, regionEpoch}` fence as one context. Game Session forwards the namespace and scope unchanged and validates exact context/request equality on every downstream response or mutation result; it never accepts a caller-selected namespace or substitutes a current one after admission. The current context/forwarding wire is narrower in places and does not yet carry or prove this complete namespace-plus-fence tuple, so that path remains an implementation/proof gap and must fail closed on missing authority. diff --git a/design/architecture/system-architecture-transactions.md b/design/architecture/system-architecture-transactions.md index 9b6b1d981c..e91fecf781 100644 --- a/design/architecture/system-architecture-transactions.md +++ b/design/architecture/system-architecture-transactions.md @@ -252,7 +252,7 @@ These workflows: For `explicitRealmEntry`, the accepted policy outcomes are exactly `PLAYER_CREATED`, `AUTO_PROVISIONED`, and `PRESEEDED_ONLY`; the immutable discovered-entry request may carry an optional `selectedCharacterId`, and its digest covers that selection without duplicating policy semantics. For any branch that reads a roster, the durable saga step binds the selected policy branch, Entity-returned roster snapshot identity/digest, and resolved selected character when one exists; retries reuse those applicable values rather than silently following a changed roster. The saga branches on that unchanged bound outcome: `PLAYER_CREATED` first uses its later-owned policy-aware Entity roster contract against the unchanged bound target, then evaluates any supplied creation input against that roster. An exactly-one roster auto-selects its actor; if the request supplies `selectedCharacterId`, it must equal that one actor. A multiple-actor roster requires an explicit `selectedCharacterId` that belongs to the unchanged roster/snapshot; missing or invalid selection fails before binding. Any supplied creation input is valid only for a zero-roster `PLAYER_CREATED` branch; after the roster lookup, a nonempty `PLAYER_CREATED` roster rejects its presence before selection, binding, or mutation, while `AUTO_PROVISIONED` and `PRESEEDED_ONLY` reject it before their branch-specific lookup or mutation. A zero roster with no creation input offers/requires creation without mutation, and zero-roster creation never accepts a caller-selected character ID. A submitted creation input with absent required fields, malformed data, or failure to validate against the exact realm-published descriptor and version bound in the discovered-entry object fails closed; and only valid submitted input calls `CreateCharacter` with the unchanged discovered-entry object/digest plus that input. The preliminary roster read is discovery and selection evidence, not concurrency authority; the Entity-owned `CreateCharacter` contract serializes and rereads the zero-roster boundary before allocation. If a durable saga step has already entered `CreateCharacter`, a retry calls Entity with the stored request identity, digest, and canonical input before any fresh roster rejection so a committed operation with a lost response replays its original result. Each mutating branch carries a caller-stable operation request identity derived from its durable forward saga-step identity (`createCharacterRequestId` for `PLAYER_CREATED`, `autoProvisionRequestId` for `AUTO_PROVISIONED`) and a `mutationDigest` over the trusted target, exact descriptor or template identity/version, and canonical `creationInput`; the auto-provision branch uses the explicit absent-input marker defined by [ADR 0140](./decisions/adr-0140-realm-authored-controllable-actor-entry.md). Entity recomputes and binds the digest and operation identity, while `discoveredEntryDigest` remains admission/discovery evidence rather than actor-write identity. A retry reuses the same operation identity, digest, and canonical input and replays the original result; changed target, descriptor/template/version, or input fails closed as an idempotency conflict. The separate `CanonicalGameplayRosterService.ListPreseededRoster` wire implements only the pre-admission `PRESEEDED_ONLY` lookup; `PLAYER_CREATED` remains a later-owned target branch, and neither it nor `AUTO_PROVISIONED` may fall back to the legacy numeric `ListCharactersByAccount` RPC for canonical gameplay. -`AUTO_PROVISIONED` requires `selectedCharacterId` to be absent; any supplied selection fails closed before the provisioning call. It calls `AutoProvisionCharacter` with the same immutable discovered-entry inputs plus its stable `autoProvisionRequestId`, `mutationDigest`, and canonical absent-input marker after explicit entry, allowing its owner-defined idempotent existing-actor result. `PRESEEDED_ONLY` calls `CanonicalGameplayRosterService.ListPreseededRoster` as a lookup: zero actors returns the pre-seeded-only denial, while a nonzero roster applies the same exact-one-versus-many selection rule without actor mutation. Its durable selection step binds the returned roster snapshot identity/digest and selected character; a retry calls `ReadSelectedPreseededAssignment` with that exact snapshot and selection and fails closed if the roster changed rather than silently selecting another actor. The response echoes request/account/selected-character/target/snapshot discovery bindings only: it mints no assignment receipt and proves no admission. Any later assignment/admission write and authoritative readback remain with the owning downstream operation. The separate wire accepts only `PRESEEDED_ONLY`; other policy values fail with `FAILED_PRECONDITION`. `PLAYER_CREATED` remains a later-owned policy-aware roster branch, and `AUTO_PROVISIONED` remains its owner-defined idempotent existing-actor operation; neither branch may use the legacy numeric `ListCharactersByAccount` RPC as canonical gameplay authority. No branch re-resolves policy or substitutes a different descriptor/template, namespace, scope, roster, or digest. Catalog and admission-pointer identity/semantics remain in [Multi-Tenancy](./system-architecture-multi-tenancy.md), while Game Session owns realm/pointer resolution, selection, and serving orchestration and Entity Management owns descriptor/template consumption and actor allocation/persistence. [ADR 0140](./decisions/adr-0140-realm-authored-controllable-actor-entry.md) remains decision rationale for this boundary; its canonical presence encoding is retained by the auto-provision request above. The Entity API contract names these target surfaces, but the current proto, implementation, and focused proof do not establish this saga. +`AUTO_PROVISIONED` requires `selectedCharacterId` to be absent; any supplied selection fails closed before the provisioning call. It calls `AutoProvisionCharacter` with the same immutable discovered-entry inputs plus its stable `autoProvisionRequestId`, `mutationDigest`, and canonical absent-input marker after explicit entry, allowing its owner-defined idempotent existing-actor result. `PRESEEDED_ONLY` calls `CanonicalGameplayRosterService.ListPreseededRoster` as a lookup: zero actors returns the pre-seeded-only denial, while a nonzero roster applies the same exact-one-versus-many selection rule without actor mutation. Its durable selection step binds the returned roster snapshot identity/digest and selected character; `ReadSelectedPreseededAssignment` requires that exact snapshot and selection and fails closed if the roster changed rather than silently selecting another actor. The response echoes request/account/selected-character/target/snapshot bindings and returns Entity's original assignment operation UUID and immutable intent digest from the unique matching committed receipt. The saga binds and retries with that unchanged reference so the later placement owner can revalidate the original assignment; the reference is neither minted by this read nor evidence of admission or current Account eligibility. The separate wire accepts only `PRESEEDED_ONLY`; other policy values fail with `FAILED_PRECONDITION`. `PLAYER_CREATED` remains a later-owned policy-aware roster branch, and `AUTO_PROVISIONED` remains its owner-defined idempotent existing-actor operation; neither branch may use the legacy numeric `ListCharactersByAccount` RPC as canonical gameplay authority. No branch re-resolves policy or substitutes a different descriptor/template, namespace, scope, roster, or digest. Catalog and admission-pointer identity/semantics remain in [Multi-Tenancy](./system-architecture-multi-tenancy.md), while Game Session owns realm/pointer resolution, selection, and serving orchestration and Entity Management owns descriptor/template consumption and actor allocation/persistence. [ADR 0140](./decisions/adr-0140-realm-authored-controllable-actor-entry.md) remains decision rationale for this boundary; its canonical presence encoding is retained by the auto-provision request above. The Entity API contract names these target surfaces, but the current proto, implementation, and focused proof do not establish this saga. If a workflow needs restart-safe continuation, durable waits/timers, or operator-visible in-flight state that survives one service lifetime, it should use the shared Temporal substrate described in [Temporal Control-Plane Workflows](./system-architecture-temporal-workflows.md) instead of extending `SagaRunner` toward durable workflow behavior. @@ -403,7 +403,9 @@ explicitRealmEntry(discoveredEntry, discoveredEntryDigest): require selectionReadback.selected_character_uuid == selectedCharacterId require selectionReadback.target == boundRequest.expected_target require selectionReadback.snapshot == boundRosterSnapshot.reference - # discovery binding only; assignment/admission write and readback are downstream + require selectionReadback.assignment_uuid == boundAssignmentUuid + require selectionReadback.intent_digest == boundIntentDigest + # original persisted reference only; placement owner must revalidate it rosterSnapshot = boundRosterSnapshot else: rosterSnapshot = Entity.CanonicalGameplayRosterService.ListPreseededRoster(discoveredEntry, discoveredEntryDigest) @@ -419,6 +421,14 @@ explicitRealmEntry(discoveredEntry, discoveredEntryDigest): resolvedSelectedCharacter = require actor matching selectedCharacterId in unchanged roster/snapshot bind resolvedSelectedCharacter.characterId to sagaStep select resolvedSelectedCharacter # lookup/selection only; no actor mutation + if not retrying selection step: + selectionReadback = Entity.CanonicalGameplayRosterService.ReadSelectedPreseededAssignment(discoveredEntry, rosterSnapshot.reference, selectedCharacterId) + require selectionReadback.request_uuid == boundRequest.request_uuid + require selectionReadback.canonical_account_uuid == boundRequest.canonical_account_uuid + require selectionReadback.selected_character_uuid == selectedCharacterId + require selectionReadback.target == boundRequest.expected_target + require selectionReadback.snapshot == rosterSnapshot.reference + bind selectionReadback.assignment_uuid and selectionReadback.intent_digest to sagaStep retries reuse the same discoveredEntry, discoveredEntryDigest, branch, applicable roster snapshot identity/digest, and resolved selectedCharacterId; an entered PLAYER_CREATED create step replays Entity before any fresh roster rejection, and each actor mutation reuses its operation request identity, mutationDigest, and canonicalCreationInput, while a changed input or roster snapshot fails closed ``` diff --git a/protos/entity-management/v1/entity_management_service.proto b/protos/entity-management/v1/entity_management_service.proto index 69a7bb6fd1..eda2eb2236 100644 --- a/protos/entity-management/v1/entity_management_service.proto +++ b/protos/entity-management/v1/entity_management_service.proto @@ -142,13 +142,17 @@ message CanonicalGameplayRosterSelectedAssignmentResponse { string canonical_account_uuid = 2; string selected_character_uuid = 3; CanonicalGameplayRosterTarget target = 4; - reserved 5, 6; + // Original non-nil operation identity and immutable intent digest from the unique committed + // ASSIGNED PRESEEDED PLAYER receipt matching this exact account, actor, target, and owner proof. + // This read returns persisted owner evidence; it never mints an assignment identity or digest. + string assignment_uuid = 5; + string intent_digest = 6; reserved 7; - reserved "assignment_uuid", "intent_digest", "error"; + reserved "error"; // Exact snapshot reference supplied by the caller and validated by this operation. The - // response echoes discovery bindings only; it does not mint an assignment receipt or prove - // admission. Any later assignment/admission write and its authoritative readback belong to - // the owning downstream operation. + // response echoes that binding alongside the original persisted assignment reference. The + // reference does not prove admission or current Account eligibility; placement must revalidate + // it with its owning Entity write/readback contract. CanonicalGameplayRosterSnapshotReference snapshot = 8; } diff --git a/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java b/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java index 780b51b380..f1222d4ef0 100644 --- a/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java +++ b/services/common-platform-core/src/test/java/net/firedevops/firemud/common/entity/CanonicalGameplayRosterProtoDescriptorTest.java @@ -52,21 +52,17 @@ void canonicalRosterResponsesHaveNoInResponseErrorAndReserveItsSlot() { } @Test - void selectedAssignmentResponseReservesUnsupportedAssignmentReceiptSlots() { + void selectedAssignmentResponseCarriesTheOriginalAssignmentReference() { Descriptor response = CanonicalGameplayRosterSelectedAssignmentResponse.getDescriptor(); - assertThat(response.findFieldByNumber(5)).isNull(); - assertThat(response.findFieldByNumber(6)).isNull(); - for (int fieldNumber : new int[] {5, 6}) { - assertThat(response.toProto().getReservedRangeList()) - .anySatisfy( - range -> { - assertThat(range.getStart()).isLessThanOrEqualTo(fieldNumber); - assertThat(range.getEnd()).isGreaterThan(fieldNumber); - }); - } - assertThat(response.toProto().getReservedNameList()) - .contains("assignment_uuid", "intent_digest"); + assertThat(response.findFieldByNumber(5).getName()).isEqualTo("assignment_uuid"); + assertThat(response.findFieldByNumber(5).getType()).isEqualTo(FieldDescriptor.Type.STRING); + assertThat(response.findFieldByNumber(6).getName()).isEqualTo("intent_digest"); + assertThat(response.findFieldByNumber(6).getType()).isEqualTo(FieldDescriptor.Type.STRING); + assertThat(response.findFieldByNumber(7)).isNull(); + assertThat(response.toProto().getReservedRangeList()) + .anySatisfy(range -> assertThat(range.getStart()).isEqualTo(7)); + assertThat(response.toProto().getReservedNameList()).contains("error"); } private static void assertErrorSlotReserved(Descriptor descriptor, int fieldNumber) {