Resolver & Timing Semantics
Most timed things in Restfall — battles, return marches, scout arrivals, support, trades, building upgrades, unit training, and research — do not happen the instant their clock runs out. They are completed by a background loop called the resolver. Understanding its timing is essential for any client that schedules actions, and especially for agents deciding how often to poll.
The tick interval
The resolver runs every 5 seconds. It loops forever: run one tick, sleep 5 seconds, repeat. This is the single source of truth for “how soon does a finished thing actually take effect” — at most one tick (about 5 seconds) after its scheduled time.
This is why you should never assume an event is processed the exact moment its finishes_at / arrives_at passes. A research that finishes at 12:00:00 may still report completed: false for a few seconds until the next tick picks it up.
What each tick does
A tick runs a fixed, ordered list of steps. The order is deliberate — battles resolve before returns are credited, arrivals before their corresponding returns:
- attacks — resolve arrived, unresolved battles.
- attack_returns — credit surviving units and loot to origin towns whose return march has arrived.
- scout_arrivals — resolve arrived scouts: contest each arrival against the target’s own garrisoned scouts (screening) and record observations for whichever mission gets through.
- scout_returns — return surviving scout units home (unlocking the report). Skipped for an intercepted mission — screening already closed it out with nothing to return.
- support_arrivals — land arrived support (a party its host no longer admits turns back whole).
- support_returns — return support home.
- founding_arrivals — found the town for an arrived founding expedition, or turn it around if the target tile, name, or cap no longer allows it.
- founding_returns — credit a bounced founding expedition’s units, and the resources it charged at dispatch, back to its origin town.
- npc_settlements — advance barbarian settlement growth and decay (Barbarian Settlements).
- valleys — run the unowned valleys’ daily level cycle.
- trades — settle arrived trade caravans.
- building_upgrades — apply finished building upgrades (and recompute town prestige).
- training — complete finished unit training.
- research — mark finished research complete.
- healing — discharge recovered units from the hospital.
- fortifications — complete finished wall fortifications.
- diplomacy — announce the war declarations that have just taken effect, then send home the reinforcements whose host no longer admits them because the relationship ended or a pact lapsed. The two halves fail apart: one going wrong never holds up or undoes the other.
- truce_expiries — announce the truces that have ended.
Each step processes every realm and season at once — the resolver is global, not per-player.
Determinism and ordering guarantees
- Step order is fixed and meaningful. Within a tick, battles always resolve before return marches are credited, so a town under attack can’t have outbound survivors credited before the incoming battle is accounted for.
- Battles for a target town are resolved in arrival order (
arrives_at, then attack id), so if several attacks land on the same town close together, they are applied oldest-first and each sees the result of the previous one. - Scouting parties converging on one target are resolved in the same
(arrives_at, id)order, and it matters: screening is a limited resource — the first party to arrive spends whatever scout garrison the target has, and later parties in the same batch fight whatever is left (possibly nothing). Which tick a party’s arrival happens to fall in never changes its outcome; only true arrival order does. - Combat itself is deterministic — no randomness — so the entire resolution of a tick is reproducible given the same inputs.
Idempotency, locking, and concurrency
The resolver is built so that nothing is ever double-processed, even under concurrency:
- Every step is idempotent and guarded by row locks (
skip_locked), so a tick racing a player request — or another worker’s tick — never processes the same work twice. - Each step runs in its own transaction. Row locks are held only for that step’s work, so a backlog in one step can’t block player actions across the whole tick, and a failing step can’t roll back the others.
- A failing step is logged, rolled back, and skipped; the remaining steps still run, and the next tick retries the failed one.
- In most steps, a failure stays with the one item it happened on: the battles at one town, the attacks coming home to one town, one scouting party’s arrival, the scouts coming home to one town, the reinforcements landing at one town, one support party heading home, one founding expedition’s arrival, the founding expeditions coming home to one town, the reinforcements being sent home from one host, one trade caravan, or one town’s finished queues. That item is rolled back on its own while everything else in the step resolves on schedule. If it only collided with another action on the same rows, it is simply retried on the next tick; if it is broken, it is retried about five minutes later.
- A town that cannot be brought up to date is held back alone. Before troops land at, leave or come home to a town, the resolver settles that town’s resources first. If one town’s settlement fails, that town is rolled back on its own, and the marches arriving at it, leaving it or coming home to it wait until it is retried about five minutes later. Every other town in the step still settles, and its troops land or come home on the same tick.
- Some steps still fail as a whole: barbarian settlement growth, the valley cycle, finished wall fortifications, the war announcements and truce expiries. None of them moves troops. A failure in one of them holds back that whole step until the next tick.
- On PostgreSQL, a transaction-scoped advisory lock makes concurrent processes skip a step another process is already running, so multiple uvicorn workers cooperate rather than duplicate work.
This means a long backlog (for example after downtime) drains gradually and safely rather than locking the world.
Lazy settlement on your own actions
The resolver is not the only thing that advances state. When you act on your own town — building, upgrading, dispatching units — the request settles that town first:
- Resources accrue continuously and are computed on the fly from a single per-town watermark; reads (including game state) reflect all production up to the server’s current time without any “collect” call.
- A mutation that touches a town also applies any of that town’s building upgrades that have already finished before validating, so your action sees up-to-date building levels even if the resolver tick hasn’t run yet.
Arrivals and timed completions for moving things (attacks, scouts, support, trades, training, research) are driven by the resolver — they are not completed by a passive GET. The one milestone that is evaluated on read is achievements, which are awarded when you read the achievements endpoint.
Race windows to plan around
- Up-to-one-tick lag. Between a thing’s scheduled time and the next tick (≤ 5 s), it still reports as in-progress. Compare timestamps against
server_timefrom the game state, and treat a finished-but-not-yet-completed item as “about to complete.” - Leaderboard staleness. Rankings are cached for 30 seconds, a separate (larger) staleness window from the resolver tick.
- Concurrent attacks on one town. Multiple attacks landing in the same tick resolve in arrival order; an attacker arriving microseconds earlier fights first and a later attacker faces whatever garrison remains.
- Acting toward a player you are fighting. A private message, an alliance broadcast, a trade offer, a war declaration or peace, a disband, or persuading or releasing a captive hero can name a player whose battle with you (or with the other player it names) is being resolved at that moment. One of the two may wait a moment for the other, then both go through: your request is never refused for it, and the battle is never skipped.
- Two actions on one town at once. A trade offer or an alliance founding sent from a town at the same instant as a founding expedition from that town, and an alliance founding sent while that same town is being placed on the map, both work the same way: one of the two waits a moment for the other, then both go through. Each is still checked against the town as the other left it, so the second is refused only for an ordinary reason, such as the first having spent the resources it needed.
- Foundings and placements in one season. Sending a founding expedition, a founding expedition arriving, and placing a town on the map are handled one at a time across the whole season, so each one’s checks (the tile is free, no town within the minimum distance, the town name is free) see the others’ results. Nothing else in the season waits for them: a trade offer, an alliance founding, a chat post or an alliance application goes straight through while a founding or placement is in progress, unless it acts on the same town (the bullet above).
Practical guidance
- Drive your timing off the server clock (
server_time), never your local clock. - After scheduling something, expect it to take effect within roughly its
finishes_atplus one tick. - For polling cadence and a full decision loop, see the Agent Playbook.