Version: 1.0.0
Category: Pattern
Status: Stable
State synchronization patterns for keeping AI agent state synchronized with game state.
Use Case: Simple bots, low-frequency updates
Strategy:
{
"pattern": "polling",
"frequency": 10000,
"queries": [
"GET /blockheight",
"GET /structs/player/{playerId}",
"GET /structs/planet_by_player/{playerId}"
],
"updateState": "on change"
}
Implementation:
{
"syncLoop": {
"interval": 10000,
"steps": [
"1. Query block height",
"2. Compare with last known block height",
"3. If changed, query relevant entities",
"4. Update local state",
"5. Trigger state change handlers"
]
}
}
Use Case: Real-time bots, high-frequency updates
Strategy:
{
"pattern": "event-driven",
"method": "GRASS streaming",
"channels": [
"player.{playerId}",
"planet.{planetId}",
"struct.{structId}"
],
"updateState": "on event"
}
Implementation:
{
"streaming": {
"connect": "ws://localhost:1443/ws",
"subscribe": [
"player.1",
"planet.1-1",
"struct.1-1"
],
"onEvent": {
"action": "update local state",
"trigger": "state change handlers"
}
}
}
Use Case: Most bots, balance of efficiency and accuracy
Strategy:
{
"pattern": "hybrid",
"initial": "polling (full state)",
"updates": "streaming (incremental)",
"fallback": "polling (if streaming fails)"
}
Implementation:
{
"syncStrategy": {
"startup": {
"method": "polling",
"queries": "full state",
"frequency": "once"
},
"runtime": {
"method": "streaming",
"channels": "relevant entities",
"fallback": "polling if disconnected"
},
"recovery": {
"method": "polling",
"queries": "changed entities only",
"frequency": "until streaming restored"
}
}
}
Use Case: Large state, minimize queries
Strategy:
{
"pattern": "incremental",
"track": "last synced block height",
"query": "only entities changed since last sync",
"update": "incremental updates only"
}
Implementation:
{
"incrementalSync": {
"track": {
"lastBlockHeight": 0,
"lastSyncTime": 0
},
"sync": {
"query": "GET /blockheight",
"compare": "if blockHeight > lastBlockHeight",
"then": {
"query": "entities changed since lastBlockHeight",
"update": "local state",
"update": "lastBlockHeight"
}
}
}
}
{
"localState": {
"blockHeight": 0,
"lastSyncTime": 0,
"players": {},
"planets": {},
"structs": {},
"fleets": {},
"guilds": {},
"reactors": {},
"substations": {},
"providers": {},
"agreements": {},
"allocations": {}
}
}
{
"updateRules": {
"blockHeight": {
"always": "update",
"trigger": "state change handlers"
},
"players": {
"update": "on change",
"merge": true,
"preserve": "local metadata"
},
"planets": {
"update": "on change",
"merge": true,
"preserve": "local metadata"
}
}
}
{
"conflictResolution": "server-wins",
"rule": "always use server state",
"action": "overwrite local state"
}
{
"conflictResolution": "timestamp-wins",
"rule": "use state with newer timestamp",
"action": "compare timestamps, use newer"
}
{
"conflictResolution": "merge",
"rule": "merge server and local state",
"action": "merge non-conflicting fields, resolve conflicts"
}
{
"optimization": "selective",
"strategy": "only sync entities needed for current task",
"benefit": "reduced queries, faster sync"
}
{
"optimization": "batch",
"strategy": "batch related queries",
"benefit": "reduced network overhead"
}
{
"optimization": "cached",
"strategy": "cache static data, sync dynamic data",
"benefit": "reduced queries for static data"
}
Last Updated: January 2025