Skip to content

High-Risk Business Operation Execution Contract Design ​

Date: 2026-10-17. Status: pending design review. This page completes §3 of the game console business design backlog. Until the review passes, this page defines the contract and acceptance only — it modifies no TaskRun, approval, execution-log, or function-invocation wire, and forces no business function to become a high-risk operation.

1. Goal and Scope ​

High-risk business operations are controlled writes whose errors, duplication, privilege escalation, or scope drift would irreversibly affect assets, accounts, orders, mail, activities, etc. Queries, read-only probes, and page-draft saves are out of scope; releases, config changes, and batch tasks may reuse the same execution identity model, with their specific flows refined separately.

Design goals:

  1. One business intent has a stable, queryable, auditable identity across the whole chain.
  2. Approvals freeze the actual parameters, targets, budget, and validity; they are never quietly replaced before execution.
  3. The game side is durably idempotent, so platform retries never double-grant.
  4. Success, failure, cancellation, and unknown outcome are distinguishable — unknown is never auto-rewritten as success or failure.
  5. Compensation, undo, and rollback are modeled explicitly; universal rollback of consumed game assets is never promised.

2. IDs and Record Responsibilities ​

Identity/recordGenerator and responsibilityRelationships and invariants
operationIdGenerated by the platform when the business intent is created, representing one concrete business operation. Globally non-empty and immutable; recommended (gameId, env, domain, intentUUID) or an equivalent canonical encoding; when player-visible, shown as a short code, never the internal auto-increment IDThe actual targets, parameters, budget digest, and function contract fingerprint of one operationId must agree; changing any of them requires a new operationId and re-approval
taskId / TaskRun.TaskIDThe task execution instance ID, owning progress, events, cancellation, scheduling, and recovery1:1 is allowed for single-object operations; in a batch, one task contains many per-object operationIds. A task restart never changes the operationId
requestIdOne underlying transport/function-call attempt ID, for network and plugin troubleshootingOne operationId may have many requestIds; a requestId failing or timing out does not mean business failure
traceIdThe cross-service distributed tracing IDPropagated from initiation, approval, and task to the game call where possible; kept in task/execution logs even with OTel off
IdempotencyKeyThe idempotency key the platform passes to the function/task layerFor high-risk business operations it must equal operationId; page-refresh keys, task-restart keys, or random retry keys are forbidden
Approval recordStores the requester, approver, status, scope, function, payload, task linkage, and timesThe approval payload must include the operationId and request digest; an approval does not equal game execution success
ExecutionLogStores payload-level request/response review data, linked to scope, function, page, operator, status, and traceLog retention may be shorter than business credentials; the audit hash chain plus task/game credentials serve long-term traceability
Game execution credentialReturned by the game function after durable idempotency, in a form defined by the function contractCredential, operationId, and game-side outcome must be mutually queryable; a missing credential means only "outcome unknown" — success is never fabricated

The existing TaskRun, approval model, and ExecutionLog already carry task IDs, idempotency keys, approval payloads, traces, request/response payloads, and scope. Whether implementation adds columns, adds a credential table, or uses structured response mapping is a review choice; but regardless of storage form, the responsibilities above are never merged or omitted.

3. Operation Request Contract ​

When creating a high-risk operation, the platform must generate and persist the following snapshot:

text
BusinessOperationRequest:
  operationId
  gameId / env
  actor              # initiator
  businessDomain     # asset/mail/ban/payment/activity/...
  operationType      # grant/deduct/send/ban/unban/...
  target             # player identity and business target (referencing item 5's identity model)
  parameters         # actual execution parameters: currency/item/quantity/duration/reason/copy etc.
  budget             # headcount, item count, amount, rate, budget cap, and currency
  preconditions      # version, balance floor, state, activity window, server, etc.
  functionRef        # functionId, contract version/fingerprint, SDK/plugin version
  approvalRef        # approval flow, approval snapshot digest, and validity
  idempotency        # operationId, allowed retry window, expiry policy
  compensation       # whether undo/reversal/compensation is supported, and the game-side capability declaration

The snapshot is generated before approval submission. The approver sees the snapshot's digest; after approval the platform must never replace the snapshot with re-entered frontend form values. Execution follows the snapshot — page versions, menu labels, and form defaults changing never alters the business request.

3.1 Parameter and Target Digests ​

  • The parameter digest includes at least the canonicalized JSON, the field schema version, and the sensitive-field masking rules; hashes are for fast comparison and never substitute for the raw snapshot.
  • The target digest includes account, character, server, channel/platform, external ID, and display name. Lists or filter conditions are never written as bare SQL/filters — the executed object set or its fingerprint must be materialized (batch semantics in item 4's design).
  • The budget digest must state the counting basis and cap, e.g. "100 targets × 100 gold each, total cap 10000 gold"; digests without a cap or currency must not pass approval.
  • The approval page shows both the PageSpec/contract digest and the business snapshot digest, both versioned.

3.2 Contract Version and Preconditions ​

Before execution, re-check:

  1. The operator still holds the function permission and has not been disabled or moved out of the approver role.
  2. The functionId, function contract version/fingerprint, and SDK/plugin version still satisfy the approval's declaration; otherwise block.
  3. The scope is still the same (gameId, env).
  4. The approval has not expired or been withdrawn, and the workflow state is still approved.
  5. Preconditions — target version, state, balance, duration — still hold; changes require re-approval.
  6. Budget, rate, and concurrency quotas are not exceeded.

The PageSpec published snapshot owns "which function and form the page was bound to at publish"; the business approval snapshot owns "what this approval executes". The two reference each other's versions but never substitute for each other.

4. Game-Side Durable Idempotency ​

Game functions must durably store (scope, operationId, requestFingerprint) and deduplicate before executing any business side effect:

  1. First execution: persist the request fingerprint, then execute; success returns a success state and the game credential; failure returns a final or retryable failure; when no answer is possible, the platform sets outcome unknown.
  2. Replay with the same ID and fingerprint: whether the game succeeded or failed, return the first result and the original credential directly — side effects never execute again.
  3. Same ID with changed parameters/targets/budget: return a conflict — the original request is never overwritten; the platform shows the original snapshot and forbids reusing the operationId.
  4. Same ID past retention: return an expired conflict; the platform must generate a new operationId and re-approve — the old ID is never treated as still executable.
  5. Partial writes: when the game transaction cannot cover all side effects, return outcome unknown with a queryable position — never wrap a local partial success as success.

The minimum return contract:

text
GameOperationResult:
  operationId
  requestFingerprint
  outcome           # succeeded | failed | retryable_failed | unknown | conflict
  gameReceipt       # the game-side durable credential; may be completed later by query per contract
  result            # the actual change result: balances/versions/delivery batches etc.
  retryableAfter    # provided only for retryable_failed/unknown
  queryHint         # query function/position/window

The game-side idempotency store must live in the same reliable storage as the business side effects — never only in process memory, an agent offline cache, or platform execution logs. When an external function plugin proxies an HTTP interface, the plugin must declare that the interface implements durable idempotency; otherwise it must not register as a high-risk write function.

5. Execution State Machine ​

text
draft → pending_approval → approved → ready → dispatching
      → running → succeeded | failed | retryable_failed | unknown
                 \→ cancel_requested → canceled | cancel_failed

expired / rejected / blocked can be entered from waiting or pre-execution states;
succeeded / failed / unknown are business terminal states, correctable only by game query results —
never changed by platform restarts, log cleanup, or task cancellation.
StateSemanticsAllowed actions
succeededThe game returned success with a traceable credential, or an unknown outcome was confirmed successful by queryRead-only queries; changes go through compensation/undo operations
failedThe game returned a final failure with no business side effectsFix the cause and resubmit a new operationId for approval
retryable_failedThe game declared a retryable failure with no side effectsRetry with the same operationId within the admission window
unknownTimeout, disconnect, incomplete game response, or partial writesOnly same-operationId queries/controlled retries; substitute rewards are forbidden
cancel_requestedThe platform requested cancellation; no game terminal state yetThe game confirms; until then "reversed" is never claimed
cancel_failedThe game refused cancellation or side effects already startedKeep the original operation result; go through compensation/undo separately
canceledThe game confirmed no side effects and terminatedThe operationId is never reused; re-execution requires a new approval

ExecutionLog.Status currently holds only ok/error, fitting payload request results; business terminal states must live in the task/business-operation records or structured responses — unknown is never simplified to error.

6. Retry, Cancel, Undo, and Compensation ​

6.1 Retry Admission ​

  • Only retryable_failed or unknown may be auto-retried by the platform, always reusing the operationId and the original snapshot.
  • Auto-retry is forbidden when the game explicitly returned failed/conflict, the approval expired, the function contract changed, the target version changed, or the budget was exceeded.
  • Retries are bounded by exponential backoff, a maximum count, a concurrency cap, and game health; at the limit the state stays unknown with an alert — never re-judged as failed.
  • Retries after a lost response rely on the game's durable dedup; the platform must never mark failure first and then issue substitute rewards under a new operationId.

6.2 Cancellation Boundary ​

  • Platform cancellation is possible before dispatch; after dispatch a game cancellation request must be sent and confirmed.
  • When the game does not support cancellation, side effects have begun, or the batch partially executed, cancellation fails and per-object original results are kept.
  • The cancellation operation itself carries a cancellation credential; "task state canceled" is never interpreted as assets rolled back.

6.3 Undo, Rollback, and Compensation ​

ActionSemanticsPrerequisite
UndoThe game natively reverses the original operation and restores the original stateThe function declares support and the game verifies the target was not consumed
Reversal/rollbackA ledger-contrary entry that never erases historyThe game ledger supports it; not for already-consumed items
CompensationA new business operation referencing the original operationId and failure reasonRequires a new approval and a new operationId, with the linkage reason recorded
Human handlingThe game side disposes, then the result is backfilledTicket/approval/game credentials kept; the original execution state is never edited directly

The platform provides no universal "one-click rollback". Whether undo is possible is declared by the game function's capability, and the game makes the final call at execution.

7. Permissions and Approval Freezing ​

  1. High-risk function contracts must declare resource, operation type, approval requirement, budget fields, sensitivity, and compensation capability; registration without the minimum declaration is refused entry into the high-risk execution catalog.
  2. The approval context includes: operator, approval workflow version, operationId, request snapshot hash, PageSpec/contract version, validity, and retry window.
  3. Approvers must be segregated from initiators and hold the target scope's permission; delegated approvals keep the delegation relationship.
  4. After approval, the request snapshot hash, target-set fingerprint, budget cap, contract fingerprint, and validity enter the execution context; any mismatch is blocked.
  5. Adding targets, changing quantities or copy, changing servers, or switching function/plugin versions after approval all require re-approval; reducing targets or budget also requires re-approval — "shrinking" never masks an intent change.
  6. Audit must record initiation, approval, execution, retry, cancellation, compensation, and outcome convergence, linking at least operationId, taskID, approval ID, traceId, and game credentials.

8. Credential Queries and Outcome Convergence ​

  • Function contracts must provide read-only result queries by operationId/game credential, or declare how game event callbacks complete the credential.
  • The platform may query periodically after unknown; a successful, failed, or conflicting query converges per the game result, and no result within retention never implies failure.
  • Event callbacks must be signature-verified, deduplicated, scope-limited, and matched to operationId/credential; the absence of an event never alone decides failure.
  • Credential display is masked, but operators and auditors must have a controlled query path to the full credential.
  • Log cleanup is never the reason an outcome becomes unknown; long-term business results and credentials must live in business task/audit storage with proper retention.

9. Acceptance Scenarios ​

  1. Lost response never double-grants: the game credited but the HTTP response was lost; the task is unknown; a same-operationId retry is deduplicated by the game returning the original credential, converging to success with exactly one grant.
  2. Same ID, changed parameters, refused: modifying amount, target, budget, or function version under the same (gameId, env, operationId) returns a conflict from both game and platform; the original snapshot is unchanged.
  3. Post-approval scope change intercepted: after approval, a change in target-set fingerprint, balance version, activity window, or contract fingerprint puts execution into blocked pre-execution; resubmission and re-approval are required.
  4. Unknown is never misjudged: timeouts and partial writes both stay unknown; beyond the auto-retry cap there are only alerts and queries — no substitute rewards.
  5. Cancellation fabricates no rollback: canceling after the game granted returns cancel_failed, keeping the game's result; recovery goes only through explicit undo/compensation with re-approval.
  6. The trace chain is complete: page, approval, task, execution log, audit, and game credentials chain by operationId; with OTel off, persistent IDs and credential audit still suffice.
  7. Expired is never resurrected: replaying past the game's retention returns an expired conflict; re-execution generates a new operationId and a new approval.

10. Decisions Pending Review ​

  1. The concrete operationId encoding, maximum length, prefix rules, and cross-game uniqueness standard.
  2. The storage form of game credentials: extending TaskRun/ExecutionLog, a new business-operation table, or a unified structured ResultPayload.
  3. Whether each game function SDK ships a built-in GameOperationResult envelope, and how external function plugins declare compatibility.
  4. The default auto-query frequency, retry cap, retention, and alert level for unknown.
  5. Whether the cancellation protocol is a minimum integration capability or offered only to functions supporting cancellation.