C#: SubmitDocumentAsync and the shard write forwarder complete on the result frame
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) Failing after 6m41s
CultMesh QUIC native / Verify committed binaries match SHA256SUMS (pull_request) Successful in 32s

CultNetWriteCompletion.SendAndAwaitResultAsync registers a refusal handler before
the send, then waits a result window (default 500 ms; CultMeshClientOptions.
SubmitResultWindow, CultNetSchemaWriteForwarderOptions.ResultWindow). A
cultnet.error.v0 inside it rejects with the new CultNetWriteRefusedException
(Code: write_not_authorized, message_invalid, ...) whatever its order against the
send or transport ack; a send returning no longer completes the write. The
forwarder's refusal now throws on the same path as an unreachable primary, so
CultNetDatabaseServer.TryForwardPutAsync/DeleteAsync no longer report a refused
forward as done. Raw send primitives (C# schema client/session, Python, Kotlin)
carry the doc line: fire-and-forget, an ack or a return is not admission, read the
result frame.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Libby 2026-11-08 13:24:27 +00:00
commit 09e6a528b8
10 changed files with 232 additions and 6 deletions

View file

@ -68,6 +68,12 @@ namespace GameCult.Networking
/// rudp:// endpoints use the C# RUDP schema client and cultnet:// endpoints use LiteNetLib.
/// </summary>
public Func<ICultNetSchemaClient>? CreateClient { get; set; }
/// <summary>
/// Gets or sets how long after a forwarded write the primary's refusal may still arrive; a refusal fails the
/// forward with <see cref="CultNetWriteRefusedException"/>. Defaults to <see cref="CultNetWriteCompletion.DefaultResultWindow"/>.
/// </summary>
public TimeSpan ResultWindow { get; set; } = CultNetWriteCompletion.DefaultResultWindow;
}
/// <summary>
@ -85,7 +91,10 @@ namespace GameCult.Networking
_options = options ?? new CultNetSchemaWriteForwarderOptions();
}
/// <inheritdoc />
/// <summary>
/// Forwards a put and completes on the primary's result frame: a refusal throws
/// <see cref="CultNetWriteRefusedException"/>, the same failure path as an unreachable primary.
/// </summary>
public async Task ForwardPutAsync(CultNetShardDescriptor shard, CultNetDocumentPutRawMessage message)
{
if (message == null) throw new ArgumentNullException(nameof(message));
@ -95,7 +104,10 @@ namespace GameCult.Networking
await SendAsync(endpoint, message).ConfigureAwait(false);
}
/// <inheritdoc />
/// <summary>
/// Forwards a delete and completes on the primary's result frame: a refusal throws
/// <see cref="CultNetWriteRefusedException"/>.
/// </summary>
public async Task ForwardDeleteAsync(CultNetShardDescriptor shard, CultNetDocumentDeleteMessage message)
{
if (message == null) throw new ArgumentNullException(nameof(message));
@ -132,7 +144,14 @@ namespace GameCult.Networking
using var client = CreateClient(endpoint);
client.Connect(host, port);
await WaitForConnectionAsync(client, endpoint).ConfigureAwait(false);
client.SendCultNet(message);
await CultNetWriteCompletion.SendAndAwaitResultAsync(
refuse =>
{
client.OnCultNet(refuse);
return null;
},
() => client.SendCultNet(message),
_options.ResultWindow).ConfigureAwait(false);
}
private ICultNetSchemaClient CreateClient(string endpoint)