spec: cultnet write receipt (write_admitted.v0, error.v1 id echo, three-outcome clients)
Some checks failed
CultMesh QUIC native / Build win32-x64 (pull_request) Has been skipped
CultMesh QUIC native / Build linux-x64 (pull_request) Has been skipped
CultMesh QUIC native / Release native binaries (pull_request) Has been skipped
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Has been cancelled
CultMesh QUIC native / Verify committed binaries match SHA256SUMS (pull_request) Has been cancelled
Some checks failed
CultMesh QUIC native / Build win32-x64 (pull_request) Has been skipped
CultMesh QUIC native / Build linux-x64 (pull_request) Has been skipped
CultMesh QUIC native / Release native binaries (pull_request) Has been skipped
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Has been cancelled
CultMesh QUIC native / Verify committed binaries match SHA256SUMS (pull_request) Has been cancelled
Specification and shared vectors only, no runtime code. A write is answered exactly once with cultnet.write_admitted.v0 or cultnet.error.v1 carrying its messageId; the new frames go only to connections whose hello lists them (today's TS decoder rejects unknown keys and versions, so "old clients ignore it" is false). Clients settle admitted | refused | unconfirmed; the result window is the pre-receipt fallback and ends unconfirmed. Wire vectors, schema-invalid cases and 16 replay scenarios in write-receipt-vectors.json. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
dc5abedffc
commit
662ae048d8
4 changed files with 921 additions and 0 deletions
121
contracts/cultnet/interop/cultnet.error.v1.schema.json
Normal file
121
contracts/cultnet/interop/cultnet.error.v1.schema.json
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://github.com/GameCult/CultLib/contracts/cultnet/interop/cultnet.error.v1.schema.json",
|
||||
"title": "CultNet Error Message v1",
|
||||
"description": "cultnet.error.v0 plus messageId (write-receipt.md). Sent in place of cultnet.error.v0 only to a connection that declared the write-receipt capability. v0 is unchanged: its schema is closed (additionalProperties false), so an extra key would make a v0 peer reject the frame instead of ignoring it. Map-mode: every key is written, messageId nil when the error answers no readable message. The code enum is the v0 enum.",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"schemaVersion",
|
||||
"error",
|
||||
"routingHint",
|
||||
"code",
|
||||
"details",
|
||||
"messageId"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"schemaVersion": {
|
||||
"const": "cultnet.error.v1"
|
||||
},
|
||||
"error": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"routingHint": {
|
||||
"description": "Optional shard routing detail for an authority failure. Null for every selection/cursor refusal code (R-N).",
|
||||
"type": [
|
||||
"object",
|
||||
"null"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"shard",
|
||||
"reason"
|
||||
],
|
||||
"properties": {
|
||||
"shard": {
|
||||
"type": [
|
||||
"object",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"reason": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"code": {
|
||||
"description": "Machine-readable refusal code (R-N). Additive: a v0 peer that does not know this field ignores it. The set is a closed enum: Rust and TypeScript refuse a message whose code is not listed, so adding a code is one coordinated change across every runtime (this schema, the C# factory, the Rust CultNetErrorCode, and a captured-bytes case for each).",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
],
|
||||
"enum": [
|
||||
null,
|
||||
"selection_invalid",
|
||||
"cursor_stale",
|
||||
"cursor_invalid",
|
||||
"reference_outside_target",
|
||||
"variant_unsupported",
|
||||
"unowned_schema",
|
||||
"write_not_authorized",
|
||||
"unsupported_schema_version",
|
||||
"message_invalid"
|
||||
]
|
||||
},
|
||||
"details": {
|
||||
"description": "Code-specific structured detail (R-N). Every field is populated only for the code that defines it; the others are null, not omitted.",
|
||||
"type": [
|
||||
"object",
|
||||
"null"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"field",
|
||||
"value",
|
||||
"asOf",
|
||||
"current"
|
||||
],
|
||||
"properties": {
|
||||
"field": {
|
||||
"description": "selection_invalid: the selection field that failed. variant_unsupported: \"subscriptionId\", when a subscription was ended. unowned_schema: \"schemaId\". write_not_authorized: \"recordKey\". unsupported_schema_version: \"schemaVersion\". message_invalid: the request field that is missing or ill-typed (\"message\" when the whole frame cannot be read).",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
"description": "selection_invalid: the offending value, when there is one string worth naming. variant_unsupported: the id of the subscription that ended. unowned_schema: the schema id no shard owns. write_not_authorized: the key of the refused write. unsupported_schema_version: the schemaVersion the peer does not speak.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"asOf": {
|
||||
"description": "cursor_stale: the cursor's own minted asOf.",
|
||||
"type": [
|
||||
"integer",
|
||||
"null"
|
||||
],
|
||||
"minimum": 0
|
||||
},
|
||||
"current": {
|
||||
"description": "cursor_stale: the answering server's current asOf.",
|
||||
"type": [
|
||||
"integer",
|
||||
"null"
|
||||
],
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
"messageId": {
|
||||
"description": "The messageId of the write (or other request) this error answers, echoed byte for byte. Null only when the frame was unreadable or carried no messageId.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
],
|
||||
"minLength": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
16
contracts/cultnet/interop/cultnet.write-admitted.schema.json
Normal file
16
contracts/cultnet/interop/cultnet.write-admitted.schema.json
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://github.com/GameCult/CultLib/contracts/cultnet/interop/cultnet.write-admitted.schema.json",
|
||||
"title": "CultNet Write Admitted",
|
||||
"description": "The receipt for one admitted document put or delete (write-receipt.md). Sent only after the write's commit point, only to a connection that declared the write-receipt capability, once per messageId. Map-mode: every key is written, none is nil. A receipt never carries an error, and an error.v1 never carries admission.",
|
||||
"type": "object",
|
||||
"required": ["schemaVersion", "messageId", "operation", "schemaId", "recordKey"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"schemaVersion": { "const": "cultnet.write_admitted.v0" },
|
||||
"messageId": { "description": "The messageId of the put or delete this admits, echoed byte for byte.", "type": "string", "minLength": 1 },
|
||||
"operation": { "enum": ["put", "delete"] },
|
||||
"schemaId": { "description": "The schemaId of the admitted write, echoed.", "type": "string", "minLength": 1 },
|
||||
"recordKey": { "description": "The recordKey of the admitted write, echoed.", "type": "string", "minLength": 1 }
|
||||
}
|
||||
}
|
||||
727
contracts/cultnet/interop/write-receipt-vectors.json
Normal file
727
contracts/cultnet/interop/write-receipt-vectors.json
Normal file
|
|
@ -0,0 +1,727 @@
|
|||
{
|
||||
"provenance": "Spec-authored with msgpack-python 1.2.4 (str keys in schema order, use_bin_type). Not yet a C# capture: the first conformance PR for each runtime re-captures these with its own encoder and the bytes must match, as error-vectors.json does. Every schema case is checked against cultnet.write-admitted.schema.json / cultnet.error.v1.schema.json in this directory.",
|
||||
"specification": "write-receipt.md",
|
||||
"wire": [
|
||||
{
|
||||
"name": "write_admitted_put",
|
||||
"messagePackHex": "85AD736368656D6156657273696F6EB963756C746E65742E77726974655F61646D69747465642E7630A96D6573736167654964A57075742D31A96F7065726174696F6EA3707574A8736368656D614964A76E6F74652E7630A97265636F72644B6579A66E6F74653A31",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "put-1",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "write_admitted_delete",
|
||||
"messagePackHex": "85AD736368656D6156657273696F6EB963756C746E65742E77726974655F61646D69747465642E7630A96D6573736167654964A564656C2D31A96F7065726174696F6EA664656C657465A8736368656D614964A76E6F74652E7630A97265636F72644B6579A66E6F74653A31",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "del-1",
|
||||
"operation": "delete",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "error_v1_write_not_authorized_echoes_id",
|
||||
"messagePackHex": "86AD736368656D6156657273696F6EB063756C746E65742E6572726F722E7631A56572726F72D93677726974655F6E6F745F617574686F72697A65643A2074686520636174616C6F6720726566757365642074686520646F63756D656E74AB726F7574696E6748696E74C0A4636F6465B477726974655F6E6F745F617574686F72697A6564A764657461696C7384A56669656C64A97265636F72644B6579A576616C7565A66E6F74653A32A461734F66C0A763757272656E74C0A96D6573736167654964A57075742D32",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.error.v1",
|
||||
"error": "write_not_authorized: the catalog refused the document",
|
||||
"routingHint": null,
|
||||
"code": "write_not_authorized",
|
||||
"details": {
|
||||
"field": "recordKey",
|
||||
"value": "note:2",
|
||||
"asOf": null,
|
||||
"current": null
|
||||
},
|
||||
"messageId": "put-2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "error_v1_message_invalid_names_member_of_a_batch",
|
||||
"messagePackHex": "86AD736368656D6156657273696F6EB063756C746E65742E6572726F722E7631A56572726F72D9256D6573736167655F696E76616C69643A207265636F72644B6579206973206D697373696E67AB726F7574696E6748696E74C0A4636F6465AF6D6573736167655F696E76616C6964A764657461696C7384A56669656C64A97265636F72644B6579A576616C7565C0A461734F66C0A763757272656E74C0A96D6573736167654964B062617463682D312D6D656D6265722D33",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.error.v1",
|
||||
"error": "message_invalid: recordKey is missing",
|
||||
"routingHint": null,
|
||||
"code": "message_invalid",
|
||||
"details": {
|
||||
"field": "recordKey",
|
||||
"value": null,
|
||||
"asOf": null,
|
||||
"current": null
|
||||
},
|
||||
"messageId": "batch-1-member-3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "error_v1_unreadable_frame_has_null_message_id",
|
||||
"messagePackHex": "86AD736368656D6156657273696F6EB063756C746E65742E6572726F722E7631A56572726F72D9216D6573736167655F696E76616C69643A20756E7265616461626C65206672616D65AB726F7574696E6748696E74C0A4636F6465AF6D6573736167655F696E76616C6964A764657461696C7384A56669656C64A76D657373616765A576616C7565C0A461734F66C0A763757272656E74C0A96D6573736167654964C0",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.error.v1",
|
||||
"error": "message_invalid: unreadable frame",
|
||||
"routingHint": null,
|
||||
"code": "message_invalid",
|
||||
"details": {
|
||||
"field": "message",
|
||||
"value": null,
|
||||
"asOf": null,
|
||||
"current": null
|
||||
},
|
||||
"messageId": null
|
||||
}
|
||||
}
|
||||
],
|
||||
"schemaInvalid": [
|
||||
{
|
||||
"name": "write_admitted_with_an_error_key",
|
||||
"messagePackHex": "86AD736368656D6156657273696F6EB963756C746E65742E77726974655F61646D69747465642E7630A96D6573736167654964A57075742D31A96F7065726174696F6EA3707574A8736368656D614964A76E6F74652E7630A97265636F72644B6579A66E6F74653A31A56572726F72A46E6F7065",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "put-1",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1",
|
||||
"error": "nope"
|
||||
},
|
||||
"why": "admission must not carry an error"
|
||||
},
|
||||
{
|
||||
"name": "write_admitted_empty_message_id",
|
||||
"messagePackHex": "85AD736368656D6156657273696F6EB963756C746E65742E77726974655F61646D69747465642E7630A96D6573736167654964A0A96F7065726174696F6EA3707574A8736368656D614964A76E6F74652E7630A97265636F72644B6579A66E6F74653A31",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
},
|
||||
"why": "messageId is non-empty"
|
||||
},
|
||||
{
|
||||
"name": "write_admitted_unknown_operation",
|
||||
"messagePackHex": "85AD736368656D6156657273696F6EB963756C746E65742E77726974655F61646D69747465642E7630A96D6573736167654964A57075742D31A96F7065726174696F6EA6757073657274A8736368656D614964A76E6F74652E7630A97265636F72644B6579A66E6F74653A31",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "put-1",
|
||||
"operation": "upsert",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
},
|
||||
"why": "operation is put or delete"
|
||||
},
|
||||
{
|
||||
"name": "write_admitted_null_record_key",
|
||||
"messagePackHex": "85AD736368656D6156657273696F6EB963756C746E65742E77726974655F61646D69747465642E7630A96D6573736167654964A57075742D31A96F7065726174696F6EA3707574A8736368656D614964A76E6F74652E7630A97265636F72644B6579C0",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "put-1",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": null
|
||||
},
|
||||
"why": "map-mode keys are never nil"
|
||||
},
|
||||
{
|
||||
"name": "error_v1_without_message_id",
|
||||
"messagePackHex": "85AD736368656D6156657273696F6EB063756C746E65742E6572726F722E7631A56572726F72AF6D6573736167655F696E76616C6964AB726F7574696E6748696E74C0A4636F6465AF6D6573736167655F696E76616C6964A764657461696C7384A56669656C64A76D657373616765A576616C7565C0A461734F66C0A763757272656E74C0",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.error.v1",
|
||||
"error": "message_invalid",
|
||||
"routingHint": null,
|
||||
"code": "message_invalid",
|
||||
"details": {
|
||||
"field": "message",
|
||||
"value": null,
|
||||
"asOf": null,
|
||||
"current": null
|
||||
}
|
||||
},
|
||||
"why": "messageId is required (null when unknown), never omitted"
|
||||
},
|
||||
{
|
||||
"name": "error_v1_empty_message_id",
|
||||
"messagePackHex": "86AD736368656D6156657273696F6EB063756C746E65742E6572726F722E7631A56572726F72AF6D6573736167655F696E76616C6964AB726F7574696E6748696E74C0A4636F6465AF6D6573736167655F696E76616C6964A764657461696C7384A56669656C64A76D657373616765A576616C7565C0A461734F66C0A763757272656E74C0A96D6573736167654964A0",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.error.v1",
|
||||
"error": "message_invalid",
|
||||
"routingHint": null,
|
||||
"code": "message_invalid",
|
||||
"details": {
|
||||
"field": "message",
|
||||
"value": null,
|
||||
"asOf": null,
|
||||
"current": null
|
||||
},
|
||||
"messageId": ""
|
||||
},
|
||||
"why": "null, not empty string, means unknown"
|
||||
},
|
||||
{
|
||||
"name": "error_v0_is_not_error_v1",
|
||||
"messagePackHex": "86AD736368656D6156657273696F6EB063756C746E65742E6572726F722E7630A56572726F72B477726974655F6E6F745F617574686F72697A6564AB726F7574696E6748696E74C0A4636F6465B477726974655F6E6F745F617574686F72697A6564A764657461696C7384A56669656C64A97265636F72644B6579A576616C7565A16BA461734F66C0A763757272656E74C0A96D6573736167654964A57075742D32",
|
||||
"message": {
|
||||
"schemaVersion": "cultnet.error.v0",
|
||||
"error": "write_not_authorized",
|
||||
"routingHint": null,
|
||||
"code": "write_not_authorized",
|
||||
"details": {
|
||||
"field": "recordKey",
|
||||
"value": "k",
|
||||
"asOf": null,
|
||||
"current": null
|
||||
},
|
||||
"messageId": "put-2"
|
||||
},
|
||||
"why": "v0 stays closed: a messageId key makes it invalid, which is why v1 exists"
|
||||
}
|
||||
],
|
||||
"scenarios": {
|
||||
"windowMs": 500,
|
||||
"semantics": "Each scenario replays events in atMs order against a client that sent each write at its send event; a tick advances the clock without a frame. expect gives the settled outcome per write id. admitted/refused/unconfirmed are three distinct results; no scenario may settle admitted without a write_admitted frame carrying the write's id.",
|
||||
"cases": [
|
||||
{
|
||||
"name": "receipt_admits",
|
||||
"description": "A receipt with the id completes the write as admitted.",
|
||||
"server": "receipt",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 5,
|
||||
"transportAck": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 20,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "w1",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
}
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "admitted"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "receipt_before_transport_ack",
|
||||
"description": "Order against the transport ack is irrelevant.",
|
||||
"server": "receipt",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 5,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "w1",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"atMs": 9,
|
||||
"transportAck": "w1"
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "admitted"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "refusal_after_ack",
|
||||
"description": "A typed refusal after the transport ack refuses; the ack was not admission.",
|
||||
"server": "receipt",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 5,
|
||||
"transportAck": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 120,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.error.v1",
|
||||
"error": "write_not_authorized",
|
||||
"routingHint": null,
|
||||
"code": "write_not_authorized",
|
||||
"details": null,
|
||||
"messageId": "w1"
|
||||
}
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "refused",
|
||||
"code": "write_not_authorized"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "refusal_before_ack",
|
||||
"description": "A typed refusal before the transport ack refuses.",
|
||||
"server": "receipt",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 5,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.error.v1",
|
||||
"error": "message_invalid",
|
||||
"routingHint": null,
|
||||
"code": "message_invalid",
|
||||
"details": null,
|
||||
"messageId": "w1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"atMs": 9,
|
||||
"transportAck": "w1"
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "refused",
|
||||
"code": "message_invalid"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ack_only_window_ends_unconfirmed",
|
||||
"description": "The legacy fallback: an acked write that nothing answered ends unconfirmed, never admitted.",
|
||||
"server": "legacy",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 5,
|
||||
"transportAck": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 500,
|
||||
"tick": true
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "unconfirmed",
|
||||
"reason": "window_elapsed"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "window_runs_from_send_not_from_ack",
|
||||
"description": "A late transport ack does not extend the window.",
|
||||
"server": "legacy",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 450,
|
||||
"transportAck": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 500,
|
||||
"tick": true
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "unconfirmed",
|
||||
"reason": "window_elapsed"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "silent_receipt_capable_server_is_unconfirmed_too",
|
||||
"description": "A server that advertised receipts and stayed silent is still only unconfirmed, and the client reports the fault.",
|
||||
"server": "receipt",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 5,
|
||||
"transportAck": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 5000,
|
||||
"tick": true
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "unconfirmed",
|
||||
"reason": "window_elapsed"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "legacy_error_with_one_write_in_flight_refuses",
|
||||
"description": "A pre-receipt server answers with error.v0 and no id: attributable only because one write is unanswered.",
|
||||
"server": "legacy",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 30,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.error.v0",
|
||||
"error": "write_not_authorized",
|
||||
"routingHint": null,
|
||||
"code": "write_not_authorized",
|
||||
"details": null
|
||||
}
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "refused",
|
||||
"code": "write_not_authorized"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "legacy_error_with_two_writes_in_flight_is_unattributed",
|
||||
"description": "An id-less error with two unanswered writes names neither: both stay pending and end unconfirmed.",
|
||||
"server": "legacy",
|
||||
"writes": [
|
||||
"w1",
|
||||
"w2"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 1,
|
||||
"send": "w2"
|
||||
},
|
||||
{
|
||||
"atMs": 30,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.error.v0",
|
||||
"error": "write_not_authorized",
|
||||
"routingHint": null,
|
||||
"code": "write_not_authorized",
|
||||
"details": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"atMs": 501,
|
||||
"tick": true
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "unconfirmed",
|
||||
"reason": "window_elapsed"
|
||||
},
|
||||
"w2": {
|
||||
"outcome": "unconfirmed",
|
||||
"reason": "window_elapsed"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "batch_names_the_refused_member",
|
||||
"description": "A batch is independent writes. The refusal names its member; the others keep their own outcomes.",
|
||||
"server": "receipt",
|
||||
"writes": [
|
||||
"b1",
|
||||
"b2",
|
||||
"b3"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "b1"
|
||||
},
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "b2"
|
||||
},
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "b3"
|
||||
},
|
||||
{
|
||||
"atMs": 10,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "b1",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"atMs": 11,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.error.v1",
|
||||
"error": "write_not_authorized",
|
||||
"routingHint": null,
|
||||
"code": "write_not_authorized",
|
||||
"details": null,
|
||||
"messageId": "b2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"atMs": 12,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "b3",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
}
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"b1": {
|
||||
"outcome": "admitted"
|
||||
},
|
||||
"b2": {
|
||||
"outcome": "refused",
|
||||
"code": "write_not_authorized"
|
||||
},
|
||||
"b3": {
|
||||
"outcome": "admitted"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "batch_with_one_member_unanswered",
|
||||
"description": "A member nothing answered is unconfirmed; the batch as a whole is admitted only if every member is.",
|
||||
"server": "receipt",
|
||||
"writes": [
|
||||
"b1",
|
||||
"b2"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "b1"
|
||||
},
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "b2"
|
||||
},
|
||||
{
|
||||
"atMs": 10,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "b1",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"atMs": 5000,
|
||||
"tick": true
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"b1": {
|
||||
"outcome": "admitted"
|
||||
},
|
||||
"b2": {
|
||||
"outcome": "unconfirmed",
|
||||
"reason": "window_elapsed"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "session_ends_before_an_answer",
|
||||
"description": "A lost session leaves unanswered writes unconfirmed, not failed and not admitted.",
|
||||
"server": "receipt",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 5,
|
||||
"transportAck": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 40,
|
||||
"sessionEnd": true
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "unconfirmed",
|
||||
"reason": "session_ended"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "late_refusal_does_not_rewrite_the_outcome",
|
||||
"description": "An answer after the window changes nothing the caller already got; it is logged.",
|
||||
"server": "legacy",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 500,
|
||||
"tick": true
|
||||
},
|
||||
{
|
||||
"atMs": 700,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.error.v1",
|
||||
"error": "write_not_authorized",
|
||||
"routingHint": null,
|
||||
"code": "write_not_authorized",
|
||||
"details": null,
|
||||
"messageId": "w1"
|
||||
}
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "unconfirmed",
|
||||
"reason": "window_elapsed"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "duplicate_resend_of_an_admitted_write_is_admitted_again",
|
||||
"description": "The server answers a re-sent admitted messageId with the receipt again, never an error.",
|
||||
"server": "receipt",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 20,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "w1",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"atMs": 30,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "w1",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
}
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "admitted"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "an_answer_for_an_unknown_id_is_ignored",
|
||||
"description": "A frame naming no write in flight settles nothing.",
|
||||
"server": "receipt",
|
||||
"writes": [
|
||||
"w1"
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"atMs": 0,
|
||||
"send": "w1"
|
||||
},
|
||||
{
|
||||
"atMs": 10,
|
||||
"frame": {
|
||||
"schemaVersion": "cultnet.write_admitted.v0",
|
||||
"messageId": "other",
|
||||
"operation": "put",
|
||||
"schemaId": "note.v0",
|
||||
"recordKey": "note:1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"atMs": 500,
|
||||
"tick": true
|
||||
}
|
||||
],
|
||||
"expect": {
|
||||
"w1": {
|
||||
"outcome": "unconfirmed",
|
||||
"reason": "window_elapsed"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
57
contracts/cultnet/interop/write-receipt.md
Normal file
57
contracts/cultnet/interop/write-receipt.md
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# CultNet write receipt (specification)
|
||||
|
||||
Status: specification. No runtime implements it yet; the conformance follow-ups below do.
|
||||
Rules: Heimdall's ruling of 2026-11-08 (a write completes on its result frame; an ack or a return is not admission).
|
||||
Files here: `cultnet.write-admitted.schema.json`, `cultnet.error.v1.schema.json`, `write-receipt-vectors.json`. They move to `contracts/cultnet/` when the first runtime implements them.
|
||||
|
||||
## The problem
|
||||
|
||||
A put or delete today has two answers on the wire: nothing (admitted, or the server never read it) and `cultnet.error.v0` (refused, with no id saying which write). A transport ack proves delivery. Clients that completed on the ack, or on a window with no refusal, reported refused writes as done (CultLib #55 to #58 bound this with a result window; this spec replaces the window with an answer).
|
||||
|
||||
## Frames
|
||||
|
||||
**`cultnet.write_admitted.v0`**: `{ schemaVersion, messageId, operation: "put"|"delete", schemaId, recordKey }`, every key written, none nil. Sent once a put or delete is admitted. The id echoes the write's `messageId` byte for byte; `operation`, `schemaId`, `recordKey` echo the write.
|
||||
|
||||
**`cultnet.error.v1`**: `cultnet.error.v0` plus a required `messageId` (string or nil). The code enum is v0's. Sent in place of `error.v0` to a receipt-capable connection. `messageId` is the id of the request the error answers; nil only when the frame was unreadable or carried no id.
|
||||
|
||||
Why a new error version and not an extra key on v0: the v0 schema is closed (`additionalProperties: false`) and the TypeScript decoder (Ajv over the closed schemas) rejects unknown keys and unknown `schemaVersion`s, and `parseCultNetMessage` throws on an unknown version; Rust's decoder errors on an unknown version too. Unknown-key tolerance of the Rust, Python and Kotlin error decoders was not checked, so none is assumed, so a surprise key or frame breaks an old client's whole receive path. Old clients are therefore never sent either new frame. This reverses the "old clients ignore it" assumption, which is false for today's decoders.
|
||||
|
||||
## Capability: opting in
|
||||
|
||||
A connection is receipt-capable when its `cultnet.hello.v0` (sent before its first write; the schema channel is reliable and ordered) lists both `cultnet.write_admitted.v0` and `cultnet.error.v1` in `supportedMessageVersions`. A server MUST NOT send either new frame to any other connection, and answers it exactly as before (no receipt, `error.v0`). A receipt-capable server lists both in its own hello, so a client can tell silence from a legacy server from a receipt server's fault. A client that sends no hello gets legacy behaviour.
|
||||
|
||||
## Server rules
|
||||
|
||||
1. **One answer.** For every put or delete on a receipt-capable connection the server sends exactly one of `write_admitted` or `error.v1`, carrying that write's `messageId`. Never both, never two different answers.
|
||||
2. **After the commit point.** `write_admitted` is sent only after the write is committed by the same rule that makes it visible to readers. Receipt of the bytes, parse, or authorisation alone is not admission.
|
||||
3. **Id on every refusal.** Every refusal of a write, whatever its code (`write_not_authorized`, `message_invalid`, `unowned_schema`, `unsupported_schema_version`, shard authority errors, ...), is an `error.v1` whose `messageId` is the write's id. When the frame is readable enough to find the id, it is found; `message_invalid` for a missing or ill-typed field still carries the id. Nil only when no id can be read.
|
||||
4. **Batches.** There is no batch frame; a batch is N writes, each with its own `messageId`, each answered under rules 1 to 3. A failed batch names its member by that id. A server may not collapse a batch into one answer.
|
||||
5. **Idempotent resend.** A resend of the `messageId` of an already admitted write is answered with `write_admitted` again, never with an error. A resend of a refused write is answered with the same refusal.
|
||||
6. **Forwarded writes.** A server that forwards a non-primary write answers the original peer only with what the primary answered: the primary's receipt becomes `write_admitted` with the original id, its refusal becomes `error.v1` with the original id. If the forward gets no answer the server sends nothing; the client's own rule below settles it as unconfirmed. A forwarder that cannot tell admitted from refused is a fault, never an admission.
|
||||
7. **Looks alike.** An admitted and a refused write differ in `schemaVersion`; a receipt has no `error`, an `error.v1` has no admission. A transport ack is neither.
|
||||
|
||||
## Client rules: three outcomes
|
||||
|
||||
A write settles as exactly one of:
|
||||
|
||||
- **admitted**: a `write_admitted` whose `messageId` is the write's.
|
||||
- **refused**: an `error.v1` whose `messageId` is the write's, carrying its `code` and `details` as the typed error.
|
||||
- **unconfirmed**: nothing settled it. Reasons: `window_elapsed` (the result window ran from the *send*, default 500 ms, passed with no answer) and `session_ended` (the session ended first). Unconfirmed is not success and not refusal. APIs that return a value return the tri-state; APIs that throw throw a distinct refused error and a distinct unconfirmed error and return normally only for admitted. A caller that needs admission treats unconfirmed as not admitted and decides whether to read the record back or resend (resend is safe under server rule 5).
|
||||
|
||||
The result window is the *fallback* for a server that predates receipts. Against a receipt-capable server (its hello lists the frames) clients SHOULD wait longer than 500 ms (5 s suggested) and SHOULD report a silent receipt-capable server as a server fault; the outcome is still unconfirmed.
|
||||
|
||||
**Legacy answers.** An `error.v0`, or an `error.v1` with nil `messageId`, names no write. It is attributed to a write only when exactly one write on the connection is unanswered; it then refuses that write. With two or more unanswered writes it settles none of them and each ends unconfirmed at its window. Late answers (after a write settled) never rewrite the outcome; log them. A frame naming a `messageId` that is not in flight settles nothing.
|
||||
|
||||
A batch is the set of its members' outcomes: admitted only if every member is admitted, refused if any member is refused (naming the members), otherwise unconfirmed (naming the unanswered members).
|
||||
|
||||
## Changes to what #55 to #58 shipped
|
||||
|
||||
Those clients complete *successfully* when the window ends with no refusal. Under this spec that case is `unconfirmed`. The conformance work changes it; until then the window-success is the interim, and callers must not read it as admission.
|
||||
|
||||
## Vectors
|
||||
|
||||
`write-receipt-vectors.json`: `wire` (MessagePack hex plus the decoded message for each new frame; the bytes are spec-authored with msgpack-python and every runtime's first conformance PR re-captures them with its own encoder and must match), `schemaInvalid` (frames that must be refused by a validator, each with why), and `scenarios` (event replays with the outcome each write must settle as; the clock is abstract, `windowMs` is 500). A conformant client passes every scenario; a conformant server's answers for the same inputs satisfy server rules 1 to 7.
|
||||
|
||||
## Conformance follow-ups (not in this PR)
|
||||
|
||||
C# server and client, Rust, TypeScript, Python, Kotlin: emit and parse the two frames; hello capability; tri-state client outcome; replace the #55 to #58 window-success; re-capture the wire vectors in each runtime. Server write paths include the shard write forwarder (rule 6) and the Odin catalog.
|
||||
Loading…
Reference in a new issue