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:
- One business intent has a stable, queryable, auditable identity across the whole chain.
- Approvals freeze the actual parameters, targets, budget, and validity; they are never quietly replaced before execution.
- The game side is durably idempotent, so platform retries never double-grant.
- Success, failure, cancellation, and unknown outcome are distinguishable — unknown is never auto-rewritten as success or failure.
- Compensation, undo, and rollback are modeled explicitly; universal rollback of consumed game assets is never promised.
2. IDs and Record Responsibilities
| Identity/record | Generator and responsibility | Relationships and invariants |
|---|---|---|
operationId | Generated 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 ID | The 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.TaskID | The task execution instance ID, owning progress, events, cancellation, scheduling, and recovery | 1:1 is allowed for single-object operations; in a batch, one task contains many per-object operationIds. A task restart never changes the operationId |
requestId | One underlying transport/function-call attempt ID, for network and plugin troubleshooting | One operationId may have many requestIds; a requestId failing or timing out does not mean business failure |
traceId | The cross-service distributed tracing ID | Propagated from initiation, approval, and task to the game call where possible; kept in task/execution logs even with OTel off |
IdempotencyKey | The idempotency key the platform passes to the function/task layer | For high-risk business operations it must equal operationId; page-refresh keys, task-restart keys, or random retry keys are forbidden |
| Approval record | Stores the requester, approver, status, scope, function, payload, task linkage, and times | The approval payload must include the operationId and request digest; an approval does not equal game execution success |
ExecutionLog | Stores payload-level request/response review data, linked to scope, function, page, operator, status, and trace | Log retention may be shorter than business credentials; the audit hash chain plus task/game credentials serve long-term traceability |
| Game execution credential | Returned by the game function after durable idempotency, in a form defined by the function contract | Credential, 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:
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 declarationThe 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:
- The operator still holds the function permission and has not been disabled or moved out of the approver role.
- The
functionId, function contract version/fingerprint, and SDK/plugin version still satisfy the approval's declaration; otherwise block. - The scope is still the same
(gameId, env). - The approval has not expired or been withdrawn, and the workflow state is still approved.
- Preconditions — target version, state, balance, duration — still hold; changes require re-approval.
- 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:
- 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.
- 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.
- 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.
- 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.
- 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:
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/windowThe 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
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.| State | Semantics | Allowed actions |
|---|---|---|
succeeded | The game returned success with a traceable credential, or an unknown outcome was confirmed successful by query | Read-only queries; changes go through compensation/undo operations |
failed | The game returned a final failure with no business side effects | Fix the cause and resubmit a new operationId for approval |
retryable_failed | The game declared a retryable failure with no side effects | Retry with the same operationId within the admission window |
unknown | Timeout, disconnect, incomplete game response, or partial writes | Only same-operationId queries/controlled retries; substitute rewards are forbidden |
cancel_requested | The platform requested cancellation; no game terminal state yet | The game confirms; until then "reversed" is never claimed |
cancel_failed | The game refused cancellation or side effects already started | Keep the original operation result; go through compensation/undo separately |
canceled | The game confirmed no side effects and terminated | The 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_failedorunknownmay 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
unknownwith 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
| Action | Semantics | Prerequisite |
|---|---|---|
| Undo | The game natively reverses the original operation and restores the original state | The function declares support and the game verifies the target was not consumed |
| Reversal/rollback | A ledger-contrary entry that never erases history | The game ledger supports it; not for already-consumed items |
| Compensation | A new business operation referencing the original operationId and failure reason | Requires a new approval and a new operationId, with the linkage reason recorded |
| Human handling | The game side disposes, then the result is backfilled | Ticket/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
- 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.
- The approval context includes: operator, approval workflow version, operationId, request snapshot hash, PageSpec/contract version, validity, and retry window.
- Approvers must be segregated from initiators and hold the target scope's permission; delegated approvals keep the delegation relationship.
- After approval, the request snapshot hash, target-set fingerprint, budget cap, contract fingerprint, and validity enter the execution context; any mismatch is
blocked. - 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.
- 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
- 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. - 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. - Post-approval scope change intercepted: after approval, a change in target-set fingerprint, balance version, activity window, or contract fingerprint puts execution into
blockedpre-execution; resubmission and re-approval are required. - 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. - 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. - 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.
- 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
- The concrete operationId encoding, maximum length, prefix rules, and cross-game uniqueness standard.
- The storage form of game credentials: extending
TaskRun/ExecutionLog, a new business-operation table, or a unified structuredResultPayload. - Whether each game function SDK ships a built-in
GameOperationResultenvelope, and how external function plugins declare compatibility. - The default auto-query frequency, retry cap, retention, and alert level for
unknown. - Whether the cancellation protocol is a minimum integration capability or offered only to functions supporting cancellation.
