Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions design/architecture/system-architecture-grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ Gameplay command streams from clients into Game Session are intentionally **diff
- Accepted command execution as durably tracked and idempotent, with automatic replay only for explicitly safe command classes.
- Internal event/notification streams as at‑least‑once with required idempotency keys.

## Keepalive Requirements

Shared gRPC clients with keepalive enabled use a 30-second keepalive interval, a 5-second timeout, and permit pings while no calls are active. Internal gRPC servers use the same 30-second interval and 5-second timeout, permit pings without active calls, and accept client keepalives no more frequently than every 30 seconds. Every service configuration states all four server values explicitly, including `spring.grpc.server.keep-alive.permit-time: 30s`; the Spring gRPC 1.0.3 default permit interval is longer and is incompatible with the shared client interval. Manually composed clients and servers use the shared keepalive policy so they follow the same transport contract. Explicit server builder customizers may override the defaults when a supported caller requires different values, provided the paired client interval and idle-ping behavior remain compatible.

## TLS Requirements

All internal gRPC calls use **mutual TLS**. FireMUD services now express the server-side TLS contract with Spring gRPC SSL bundles:
Expand Down
4 changes: 2 additions & 2 deletions design/developer-workflows/pr-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ FireMUD owns the project authority and safety requirements below. Follow the act
- Verify the exact committed candidate, live PR head/base, effective parent, provider-observed diff base, ancestry, and unique patch before relying on review evidence. Refresh after identity or topology changes and distinguish historical coverage from current-code proof. Reconciliation must preserve the owned patch, evidence, findings, and actual configured controls. Never describe an expected parent as the provider’s actual diff base when they differ.
- Preserve actual human stops and allocations independently of candidate preparation and merge readiness. Reaching a configured discovery limit or stopping a channel does not erase findings, grant coverage, or establish readiness. Do not reopen, replace, reset, or approximate controls without the required authority. Deliberate queue removal requires explicit User authorization and an audited reason; merging or closing a PR does not grant it.
- Adjudicate findings as accepted, routed, or rejected with a concrete outcome and evidence. Accepted findings remain source-owned correction obligations until verified fixed. Routed observations identify another owner without claiming that owner’s acceptance or fix. Target owners independently disposition incoming routes and verify resolutions; retargeting preserves the open obligation and prior ownership, including honest unassigned work. Open outgoing routes do not hold the source’s merge readiness. Preserve source linkage and original evidence when correcting a disposition; newly accepted findings still require fixes.
- Summary-only and outside-diff findings require verification and disposition as well as inline findings. Historical accepted-fixed evidence does not replace current verification. Resolve a thread only after its exact finding is fixed at the current published head; do not conceal unresolved work through thread resolution or record edits.
- Routine bot findings do not need public replies or reflexive `@coderabbit` exchanges. Record the assessment, decision, and any fix and verification proof in FireController; resolve verified-fixed threads without extra chat under the current-published-head rule above. Reply only when genuine clarification or reconsideration is needed, or to provide necessary context for human reviewers, and only within applicable communication authorization.
- Summary-only and outside-diff findings require verification and disposition as well as inline findings. Historical accepted-fixed evidence does not replace current verification. Resolve a thread after verifying at the current published head that its exact finding is fixed, or that it was rejected or withdrawn and no actionable work remains. Record the concrete reason and current-head evidence in FireController and preserve the original finding and disposition. Record fix evidence only for a verified correction. Do not conceal unresolved work through thread resolution or record edits.
- Routine bot findings do not need public replies or reflexive `@coderabbit` exchanges. Record the assessment, decision, and any fix and verification proof in FireController; resolve eligible threads without extra chat under the current-published-head rule above. Reply only when genuine clarification or reconsideration is needed, or to provide necessary context for human reviewers, and only within applicable communication authorization.
- Keep private captures, review history, findings, and uncertain publication intents intact. Recover only through the installed release’s supported guarded operations within existing authority. Recording, recovery, imports, or publication alone grant no provider credit, fix proof, CI result, or merge authority. Do not blind-repost an uncertain checkpoint, invent attribution, or infer delivery failure from public absence. Unsupported or ambiguous recovery remains a reported hold for FireController Worker.
- Follow the configured admission, provider-exclusion, quota, and cooldown controls; do not request against an active or rate-limited target or enable paid capacity. Use included quota only. Supported operations and recorded allowances do not themselves grant authority or clear unrelated holds.
- For CI observation using a shared GitHub credential budget, coordinate one observer across relevant workers and runs. Prefer the supported native batched CI wait and existing inbox notices for followed PR merges, closures, and review completions; other workers consume those results and continue independent work. Add review-activity or known-operation waits when a relevant review hold or retained operation needs observation. Do not fan out simultaneous per-run watchers or duplicate an active observer. Use narrow run-list or run-view reads at least 60 seconds apart only when a supported wait cannot supply the required evidence, and check status at meaningful readiness transitions. Honor evidenced reset/retry-after times; report a hold when no time is available.
Expand Down
13 changes: 7 additions & 6 deletions dev-tools/deploy/preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -1715,12 +1715,13 @@ def validate_recovery_freshness(
"fail",
f"Recovery compatibility baseline {disposition} freshness must advance the existing timestamp: {class_name}",
)
elif disposition in {"rebound", "verified_not_restored"}:
if field != previous_field or value_timestamp != previous_value:
return (
"fail",
f"Recovery compatibility baseline {disposition} freshness must preserve the existing field/value: {class_name}",
)
elif disposition in {"rebound", "verified_not_restored"} and (
field != previous_field or value_timestamp != previous_value
):
return (
"fail",
f"Recovery compatibility baseline {disposition} freshness must preserve the existing field/value: {class_name}",
)
return ("pass", "")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spring:
time: 30s
timeout: 5s
permit-without-calls: true
permit-time: 30s
ssl:
enabled: ${GRPC_SERVER_TLS_ENABLED:true}
bundle: firemud-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spring:
time: 30s
timeout: 5s
permit-without-calls: true
permit-time: 30s
ssl:
enabled: ${GRPC_SERVER_TLS_ENABLED:true}
bundle: firemud-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected void configureServices(

@Override
protected void configure(NettyServerBuilder builder, List<ServerServiceDefinition> services) {
GrpcKeepAlivePolicy.configureServer(builder);
super.configure(builder, services);
// Customizers cannot leave an alternate mutable lookup or widen the finite ceiling.
builder.fallbackHandlerRegistry(CLOSED_FALLBACK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
import java.io.File;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLException;

/** Builds outbound gRPC channels with FireMUD's standard TLS and keepalive behavior. */
Expand Down Expand Up @@ -89,9 +88,6 @@ private void configureKeepAlive(ManagedChannelBuilder<?> builder, boolean keepAl
if (!keepAlive) {
return;
}
builder
.keepAliveTime(30, TimeUnit.SECONDS)
.keepAliveTimeout(5, TimeUnit.SECONDS)
.keepAliveWithoutCalls(true);
GrpcKeepAlivePolicy.configureClient(builder);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.firedevops.firemud.common.grpc;

import io.grpc.ManagedChannelBuilder;
import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
import java.util.concurrent.TimeUnit;

/** Shared client and server gRPC keepalive settings. */
public final class GrpcKeepAlivePolicy {
private static final long KEEP_ALIVE_INTERVAL_SECONDS = 30;
private static final long KEEP_ALIVE_TIMEOUT_SECONDS = 5;
private static final long SERVER_MINIMUM_PERMIT_INTERVAL_SECONDS = 30;

private GrpcKeepAlivePolicy() {}

/** Applies the shared ping interval, timeout, and idle-ping policy to a client builder. */
public static void configureClient(ManagedChannelBuilder<?> builder) {
builder
.keepAliveTime(KEEP_ALIVE_INTERVAL_SECONDS, TimeUnit.SECONDS)
.keepAliveTimeout(KEEP_ALIVE_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.keepAliveWithoutCalls(true);
}

/** Applies server ping settings and admits the shared client's idle-ping interval. */
public static void configureServer(NettyServerBuilder builder) {
builder
.keepAliveTime(KEEP_ALIVE_INTERVAL_SECONDS, TimeUnit.SECONDS)
.keepAliveTimeout(KEEP_ALIVE_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.permitKeepAliveWithoutCalls(true)
.permitKeepAliveTime(SERVER_MINIMUM_PERMIT_INTERVAL_SECONDS, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.spy;

import io.grpc.CallOptions;
import io.grpc.HandlerRegistry;
Expand All @@ -14,8 +16,10 @@
import io.grpc.TlsServerCredentials;
import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
import io.grpc.stub.ClientCalls;
import io.grpc.stub.ServerCalls;
import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -24,10 +28,43 @@
import net.firedevops.firemud.test.LoopbackMtlsTestPki.IdentitySpec;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.InOrder;

class BoundedGrpcServerFactoryTest {
private static final int ORDINARY = GrpcRequestBytePolicy.ORDINARY_MAXIMUM_BYTES;

@Test
void canonicalServerKeepAliveDefaultsPrecedeSupportedCustomizers() {
var builder = spy(NettyServerBuilder.forAddress(new InetSocketAddress("127.0.0.1", 0)));
var factory =
new BoundedGrpcServerFactory(
"127.0.0.1:0",
List.of(
customizer ->
customizer
.keepAliveTime(45, TimeUnit.SECONDS)
.keepAliveTimeout(7, TimeUnit.SECONDS)
.permitKeepAliveWithoutCalls(false)
.permitKeepAliveTime(60, TimeUnit.SECONDS)),
null,
null,
TlsServerCredentials.ClientAuth.NONE,
new GrpcRequestBytePolicy(List.of()),
ORDINARY);

factory.configure(builder, List.of());

InOrder calls = inOrder(builder);
calls.verify(builder).keepAliveTime(30, TimeUnit.SECONDS);
calls.verify(builder).keepAliveTimeout(5, TimeUnit.SECONDS);
calls.verify(builder).permitKeepAliveWithoutCalls(true);
calls.verify(builder).permitKeepAliveTime(30, TimeUnit.SECONDS);
calls.verify(builder).keepAliveTime(45, TimeUnit.SECONDS);
calls.verify(builder).keepAliveTimeout(7, TimeUnit.SECONDS);
calls.verify(builder).permitKeepAliveWithoutCalls(false);
calls.verify(builder).permitKeepAliveTime(60, TimeUnit.SECONDS);
}

@Test
void rejectsDuplicateUnknownAndNonidenticalDescriptorConfiguration() {
var method = method("test.Owner/Read", new AtomicInteger());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import io.grpc.protobuf.ProtoUtils;
import io.grpc.stub.ClientCalls;
import io.grpc.stub.ServerCalls;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -36,6 +38,8 @@
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
import org.springframework.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration;
import org.springframework.boot.grpc.server.autoconfigure.GrpcServerFactoryAutoConfiguration;
import org.springframework.boot.grpc.server.autoconfigure.GrpcServerFactoryCustomizer;
Expand Down Expand Up @@ -74,6 +78,18 @@ class CommonGrpcRequestBoundsAutoConfigurationTest {
.withPropertyValues("spring.grpc.server.port=0", "spring.grpc.server.ssl.enabled=false")
.withUserConfiguration(DiscoveredServiceConfiguration.class);

@Test
void explicitServerPermitIntervalBindsFromConfiguration() {
var properties =
new Binder(
new MapConfigurationPropertySource(
Map.of("spring.grpc.server.keep-alive.permit-time", "30s")))
.bind("spring.grpc.server", GrpcServerProperties.class)
.get();

assertThat(properties.getKeepAlive().getPermitTime()).isEqualTo(Duration.ofSeconds(30));
}

@Test
void productionAutoConfigurationDiscoversRegistersAndCallsRealServiceWithOrderedInterceptors() {
runner.run(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.firedevops.firemud.common.grpc;

import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.spy;

import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;

class GrpcKeepAlivePolicyTest {
@Test
void configuresClientIntervalTimeoutAndIdlePings() {
var builder = spy(NettyChannelBuilder.forAddress("127.0.0.1", 6565));

GrpcKeepAlivePolicy.configureClient(builder);

InOrder calls = inOrder(builder);
calls.verify(builder).keepAliveTime(30, TimeUnit.SECONDS);
calls.verify(builder).keepAliveTimeout(5, TimeUnit.SECONDS);
calls.verify(builder).keepAliveWithoutCalls(true);
}

@Test
void configuresServerIntervalTimeoutAndAllowedIdlePings() {
var builder = spy(NettyServerBuilder.forAddress(new InetSocketAddress("127.0.0.1", 6565)));

GrpcKeepAlivePolicy.configureServer(builder);

InOrder calls = inOrder(builder);
calls.verify(builder).keepAliveTime(30, TimeUnit.SECONDS);
calls.verify(builder).keepAliveTimeout(5, TimeUnit.SECONDS);
calls.verify(builder).permitKeepAliveWithoutCalls(true);
calls.verify(builder).permitKeepAliveTime(30, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ spring:
time: 30s
timeout: 5s
permit-without-calls: true
permit-time: 30s
ssl:
enabled: ${GRPC_SERVER_TLS_ENABLED:true}
bundle: firemud-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spring:
time: 30s
timeout: 5s
permit-without-calls: true
permit-time: 30s
ssl:
enabled: ${GRPC_SERVER_TLS_ENABLED:true}
bundle: firemud-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spring:
time: 30s
timeout: 5s
permit-without-calls: true
permit-time: 30s
ssl:
enabled: ${GRPC_SERVER_TLS_ENABLED:true}
bundle: firemud-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ spring:
time: 30s
timeout: 5s
permit-without-calls: true
permit-time: 30s
ssl:
enabled: ${GRPC_SERVER_TLS_ENABLED:true}
bundle: firemud-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spring:
time: 30s
timeout: 5s
permit-without-calls: true
permit-time: 30s
ssl:
enabled: ${GRPC_SERVER_TLS_ENABLED:true}
bundle: firemud-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spring:
time: 30s
timeout: 5s
permit-without-calls: true
permit-time: 30s
ssl:
enabled: ${GRPC_SERVER_TLS_ENABLED:true}
bundle: firemud-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ spring:
time: 30s
timeout: 5s
permit-without-calls: true
permit-time: 30s
ssl:
enabled: ${GRPC_SERVER_TLS_ENABLED:true}
bundle: firemud-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spring:
time: 30s
timeout: 5s
permit-without-calls: true
permit-time: 30s
ssl:
enabled: ${GRPC_SERVER_TLS_ENABLED:true}
bundle: firemud-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spring:
time: 30s
timeout: 5s
permit-without-calls: true
permit-time: 30s
ssl:
enabled: ${GRPC_SERVER_TLS_ENABLED:true}
bundle: firemud-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
import net.firedevops.firemud.common.gamesession.HistoricalOriginalStartSessionOwnerEvidenceReadClient;
import net.firedevops.firemud.common.grpc.BoundedGrpcServerFactory;
import net.firedevops.firemud.common.grpc.GrpcChannelFactory;
import net.firedevops.firemud.common.grpc.GrpcKeepAlivePolicy;
import net.firedevops.firemud.common.grpc.GrpcPeerIdentity;
import net.firedevops.firemud.common.grpc.GrpcPeerIdentityInterceptor;
import net.firedevops.firemud.common.grpc.GrpcRequestBytePolicy;
Expand Down Expand Up @@ -4713,6 +4714,7 @@ private static Server buildServer(
.trustManager(pki.ca().toFile())
.clientAuth(ClientAuth.REQUIRE)
.build());
GrpcKeepAlivePolicy.configureServer(builder);
if (deferredServices != null) builder.fallbackHandlerRegistry(deferredServices);
if (Arrays.stream(receivers)
.anyMatch(AccountInitialAdmissionSettlementReadGrpcService.class::isInstance)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.firedevops.firemud.common.gamesession.CanonicalGameplayAdmissionDecisionReadGrpcCodec.RetainedTargetSelector;
import net.firedevops.firemud.common.grpc.CommonGrpcClientProperties;
import net.firedevops.firemud.common.grpc.GrpcChannelFactory;
import net.firedevops.firemud.common.grpc.GrpcKeepAlivePolicy;
import net.firedevops.firemud.common.grpc.GrpcPeerIdentity;
import net.firedevops.firemud.common.grpc.GrpcPeerIdentityInterceptor;
import net.firedevops.firemud.common.publication.PublishedRealmEntryPolicyEvidence;
Expand Down Expand Up @@ -253,7 +254,9 @@ private static String peer(String namespace, String service) {

private static Server server(
LoopbackMtlsTestPki.Pki pki, String identity, BindableService receiver) throws Exception {
return NettyServerBuilder.forAddress(new InetSocketAddress("127.0.0.1", 0))
var builder = NettyServerBuilder.forAddress(new InetSocketAddress("127.0.0.1", 0));
GrpcKeepAlivePolicy.configureServer(builder);
return builder
.sslContext(
GrpcSslContexts.configure(
io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder.forServer(
Expand Down
Loading