Looping parallax: contract

Checked by: tests/contract/test_workflow_contract_docs.py.

Turn supplied layer images into repeating PNGs, portable placement metadata, and a scrolling preview. Each layer is prepared independently; changing offsets, order, or parallax factors reruns composition while reusing its images.

The workflow is an FX workflow file, workflow.yaml, over its own node types in nodes/ and FX's built-in types; uv run python -m grida.fx plan|run looping-parallax plans and runs it. The checkout's root fx.yaml finds it by id; with an installed wheel, list the installed fx_games/workflows folder under workflows: in your own fx.yaml. Its inputs are a canvas (width, height) and a list of layers, each a picture file with its layer_id, order, parallax, offset_x, offset_y, repeat_x, repeat_y, loop_construction and optional description; uv run python -m grida.fx schema looping-parallax prints them as JSON Schema. The workflow does not extract hidden layers from a finished reference. By default, requested repeating axes use deterministic reflection (fx/image.mirror_repeat@1), preserving an exact repeat at the boundary. Reflection doubles the period and shows every landmark twice, facing itself, so it can be unsuitable for some artwork; the manifest explicitly carries semantic_review: not_performed.

A horizontally repeating layer can instead set loop_construction: seam_repaint. The workflow first checks whether the supplied layer already loops (loops_already), and passes it on untouched if it does. Otherwise seam_repaint shows the provider one 1536-pixel canvas made of the layer's end placed against its own beginning, and asks for the middle 384 pixels to be repainted so the art flows through the cut; the brief is prompts/seam.md. The return is registered against what was sent and cut back into the layer along the columns where the two agree best (see loop construction below). The seam_ok judge then holds the loop to the layer's size and to the repeat gate, wrap and stitches included. A rejected repaint is drawn once more; when the second take is rejected too, the layer falls back to the reflection. An fx/select@1 step takes the first of the repaint, the reflection and the untouched layer that exists and was not rejected. A repainted layer keeps the width it was drawn at.

Seam repaint needs a layer at least 1536 pixels wide, which the plan checks before any spend, and a height the configured image route accepts for a 1536-pixel-wide edit, which the route checks before it sends anything. The optional description says what the layer is made of; it goes into the brief, never into the composition. The brief, the input picture and the node type's locked version are each step's identity, while placement and parallax are only the compose step's.

from grida.fx import run

result = run("looping-parallax", input_files=["layers/inputs.yaml"])
manifest = result.outputs["manifest"].path
result.deliver({"layers": "out/layers/{key}.png", "preview": "out/preview.png"})

A seam layer's repaint is one image.edit call on the image.edit route the workflow's fx.yaml names by default; the routes: of the fx.yaml you run from may choose another, and the plan refuses one without masks and transparency (requires: [mask, alpha]). The plan prices it at its worst case, two takes per layer that does not already loop, and a run makes it only with --live (live=True in Python) and your provider keys. A layer that already loops, or a mirrored one, costs nothing.

inputs/supplied_layers/make_inputs.py <directory> draws two original geometric PNGs and writes the inputs.yaml that places them, without a provider; uv run python -m grida.fx run looping-parallax --inputs <directory>/inputs.yaml runs them. No game definition or Godot project is needed.

Outputs, under the run folder's outputs/:

A seam layer's repaint step also places, under the run folder's files/, the provider's return (edit) and the loop report (report) with the cut and its stitches; the seam_ok judge's verdict is a fact in the run's record. The compose step's preview.png shows the composed frame. A consumer computes position as offset - scroll * parallax and repeats each declared axis. The caller supplies scroll input; no player, physics, level, camera controller, or gameplay state is prescribed.

Graph

FX plans the committed supplied-layers sample offline; this is the shape of that plan. scripts/write_workflow_contracts.py --write regenerates the block, and the check above fails when it drifts:

{
  "graph_kind": "fx-graph-v1",
  "topology_sha256": "ed1fd34140f786953a7894ab7fc62ce0bebf9c00f8a22c292a8a76c7b6eb8649",
  "node_count": 5,
  "operation_counts": {
    "local": 5
  },
  "outputs": [
    "outputs/layers/",
    "outputs/manifest.json",
    "outputs/preview.png"
  ],
  "type_ids": [
    "looping_parallax/compose",
    "looping_parallax/layer/loop",
    "looping_parallax/layer/mirror"
  ]
}

Loop construction

Contract maturity: exact-current producer and consumer contract.

This section is the canonical description of how a scrolling layer is made to repeat on its horizontal axis, for this workflow and for the example games' map layers. The deterministic constructions live in media/loop_construction.py. This workflow applies the admission, seam_repaint construction and mirror fallback per supplied layer, without a game. A game's map graph applies the same constructions to its generated layers, authored as continuity.loop_construction in its maps/<map_id>.toml.

Implementation status is not an acceptance claim. A constructed loop still has to pass the map's semantic review before it is treated as usable art.

The contract

one generated layer in, one raster proven to repeat on x out

A side-scrolling map advances the camera indefinitely across a finite painted strip. Every background and foreground layer therefore has to be a repeat unit: tiling it must produce no visible join. continuity.seamless_axis = "x" declares that requirement. continuity.loop_construction declares how it is satisfied when the generated raster does not already satisfy it.

This is a producer concern end to end. The consumer receives a raster whose period is a published fact and tiles it; it never inspects pixels, repairs seams, or infers a period.

Where it sits

Loop construction in the map branch

The loop node sits between layer generation and layer validation. Its operation kind follows the selected construction's own is_generative declaration rather than a comparison against a construction name: a generative construction exposes an image operation because it may need one, a deterministic construction exposes a local operation because it never calls a provider.

Admission comes first

Whatever construction a map declares, the node first asks the deterministic validator whether the generated raster already repeats. When it does, the raster is published untouched and the node spends nothing.

The image model does sometimes return a genuinely wrapping strip when asked for one. Of Bellweather's eight current layers, Crowncrag's route does: its canopy, rocks and water run straight through the wrap, and admission publishes it untouched. Both sky plates do not, although the previous gate let them through: each carries a faint vertical line at its wrap, about six times the steps between its own interior columns. Constructing over a layer that already loops would add artefacts for no benefit, so admission is checked before anything else runs.

A construction is therefore only ever a response to a measured failure, and the provider cost of the whole feature is proportional to how often the model misses.

Two axes, and why the second one matters

Constructions differ on two axes. The first decides what a layer costs; the second decides how much its loop can be trusted, and they are not the same question.

Agent — whether the construction needs a provider operation. This is a structural property the execution graph reads directly, not a note about cost.

Guarantee — where the loop's continuity actually comes from.

TierThe wrap join is continuous because...Constructions
reflectionit is a mirror, so it is continuous by geometry and cannot fail.mirror_repeat, fold_repaint
interiorthe wrap sits inside the canvas the provider sees, so the model paints through it as ordinary interior.seam_repaint
anchoredits boundary columns were forced equal after the fact.generated_bridge

The tiers are ordered by how much they assume. reflection assumes nothing. interior assumes the provider can paint continuous content through a region it can see both sides of — which is the ordinary thing an image model is good at. anchored assumes the provider can meet two frozen ends at the edge of its own canvas, which is the thing it is worst at, and then papers over the difference.

That last tier carries a consequence worth stating on its own: anchoring assigns the very join that admission then measures, so a bridged unit's join metric is 0.0 by construction and proves nothing. See validation.

The constructions

ConstructionAgentGuaranteePeriodMutates source
direct admission—source already loopsWno
mirror_repeatdeterministicreflection2Wno
generated_bridgegenerativeanchoredW + bridge_spanno
seam_repaintgenerativeinteriorWyes
fold_repaintgenerativereflection2Wyes

Source mutability is per-construction

mirror_repeat and generated_bridge only ever append, so the generated layer stays recoverable from the result. The repaint constructions replace pixels around the join and it does not. Every loop record carries mutates_source so no consumer has to infer it from a construction name.

mirror_repeat — the baseline

mirror_repeat

Append a horizontal mirror of the source. The period becomes [ A | mirror(A) ].

Both joins are continuous by construction, and for the same reason:

There is nothing to measure and nothing to validate — a reflection cannot be discontinuous. This is why it is the baseline: it needs no provider, cannot fail, and works identically on opaque plates and cut-out alpha layers.

The price is paid in composition rather than correctness. The period doubles, so the same authored content covers half the travel; and the strip visibly reads back on itself, with each landmark appearing twice per period, once reflected. That is acceptable for distant, low-salience layers and conspicuous on any layer carrying a recognisable subject.

generated_bridge — one painted span

generated_bridge

Append a single generated span B that carries the layer's tail into its own head. The period becomes [ A | B ], tiled as A, B, A, B, …. Because B's left neighbour is always A's end and its right neighbour is always A's start, one generated span makes the whole strip loop.

The provider is shown [ A tail | editable bridge | A head ] with the bridge masked, and asked to paint only the bridge.

Why the mask is not sufficient on its own

The image endpoints available here treat a mask as a strong hint, not as a protected region. Asked to leave the contexts untouched, the model repaints the entire canvas — on both the OpenRouter image-reference route and OpenAI's /images/edits with a real mask field. Neither is a latent-inpainting model.

Repainting is not the same as ruining, and the difference is what the rest of this section is about. Once the canvas-wide shift is undone, a texture context comes back within about 20 levels per channel — the same fence, redrawn. A composed context can come back at 90 or more, which is not a redraw but a different arrangement: objects moved, invented, or placed across the cut.

Masked edit: conditioning sent above, provider return below

OpenAI /images/edits with a real mask and background=transparent, on a neutral checkerboard. Top is the conditioning sent: two immutable context bands with a transparent gap between them, cyan rules marking the bridge span. Bottom is what came back. Read it twice.

What works: the empty sky stays genuinely transparent, and the gap is filled with real cloud and mountain silhouette rather than a blended approximation. This is why the provider owns the bridge's alpha.

What does not: the left context's cloud mass and the right context's ridgeline are both repainted, measured at 40.60 and 38.70 mean levels against an expected 0. Much of that figure is the canvas shift rather than new invention — which is precisely why the shift has to be measured and undone rather than assumed away.

Not one content pixel of the contexts survives byte for byte — measured across every layer, both bands, the identical fraction is 0.000%. The endpoint has no preservation primitive: it returns a freshly generated image every time. Nothing in the prompt or the mask changes that.

Three consequences follow, and all are load-bearing:

  1. The contexts are measured before they are discarded. They are the only instrument that reveals where the return landed, so they are read first; see registration. Discarding them unexamined was the original design and it was exactly wrong: it threw away the evidence that the bridge was unusable.
  2. Only the bridge span is kept. The context pixels themselves never reach the artifact, so the source survives byte for byte.
  3. The bridge is anchored. Its outermost column is forced to its exact neighbour and the correction decays to zero across a short band. Anchoring makes both joins exact — but note that it makes them exact by assignment, which is why the join metric alone proves nothing about a bridged unit. See validation.

Registration: landing the bridge in the source frame

The endpoint regenerates the whole canvas at its own vertical registration. Across every bridge run measured so far it shifts the entire strip by roughly 20 to 50 pixels, and it does so under every prompt tried — including one that says, in as many words, to keep the same vertical alignment and not to move or shift anything. No prompt fixes this. It is the producer's job.

The span it paints is coherent with the picture it drew. Cropping at fixed pixel coordinates and pasting into the source therefore lands correct art at the wrong height, and anchoring then hides the evidence by forcing the boundary columns to agree.

So the contexts are read before they are thrown away. We sent known pixels; measuring where they came back recovers the translation directly, and each band yields an independent estimate of the same number:

Agreement is therefore both the correction and the trust signal, from one measurement and no extra provider call. The record carries the offset, each band's estimate, the residual after correction, and the residual without it, so a reviewer can see how far the provider drifted and how well the correction explains it.

Registration cannot be measured by looking for preserved pixels, because there are none. It matches content, on alpha-premultiplied luma so that empty regions cannot pass as agreement.

The bridge brief is not the layer brief

The bridge request deliberately does not send the layer's generation brief. That brief asks for a composition — landmarks, a windmill, broad trees, a centred rhythm — and a model given it will compose, which is how an invented object ends up straddling the cut and being guillotined when the span is extracted.

What the provider gets instead is a join brief: reproduce the two contexts exactly, paint only the middle span, and keep everything painted strictly inside it. The layer's own text survives only as a demoted material reference — what the layer is made of, not how to arrange it — because a texture layer still needs to know it is drawing fence and flowers.

The brief is versioned as LOOP_BRIDGE_BRIEF_VERSION and bound into the loop node's cache identity, so changing it re-runs the bridges without re-billing layer generation. The repaint constructions carry their own LOOP_REPAINT_BRIEF_VERSION for the same reason and a stronger one: a repaint asks the provider to carry existing content through a region it can see both sides of, which is a materially different request from inventing a span between two ends it cannot see across. Sending one brief for the other describes a canvas the provider is not looking at.

Both families also carry a framing constant. join is what ships. restoration, which frames the request as restoring a mistakenly removed region, replicated better at n=7 — median residual 12.73 to 8.17, join step 1.0 to 0.0, drift outliers eliminated — and is carried alongside so the choice is bound and reviewable rather than an untracked prompt edit. Selecting it is a separate decision from promoting the constructions.

The provider owns the bridge's alpha

For a cut-out layer — clouds, foliage, a village silhouette — the bridge's alpha must be real silhouette, so it is taken from the provider along with the RGB.

The alternative, reconstructing alpha by interpolating between the two endpoint alpha profiles, was measured and rejected. An interpolation between two profiles cannot invent an edge that is in neither, so on a cloud layer it produces a rectangular blend with hard horizontal banding instead of cloud edges — while passing every join metric, because the joins are not where the defect is. Layers of this kind are the majority of a map's background, so this is the common case rather than an edge case.

seam_repaint — repaint the wrap where the provider can see it

Show the provider the wrap itself, centred: [ A tail | A head ], a window of continuous artwork whose middle is the hard cut a player would see. Mask that middle and ask for it to be repainted. Nothing is appended; the returned span is written back over the source's tail and head, so the period stays exactly W.

The returned span straddles the wrap, and that is the whole mechanism. Its left half belongs to the end of the strip and its right half to the beginning, but on the provider's canvas those halves were adjacent pixels. Whatever it painted across them is continuous because it was painting one region, not matching two ends. This is the interior guarantee, and it is why the construction does not inherit the bridge's hardest problem.

Two properties follow that no other generative construction has:

The price is that the source is no longer recoverable: pixels near the join are replaced.

Cutting the repaint back in

Moving the wrap into the provider's canvas does not remove every join; it creates two new ones, where the repaint meets the source again on either side. The endpoint redraws every pixel it is sent, so at those places the source and the return never match exactly.

The first version kept only the painted span and eased it onto one fixed source column over 24 columns, as the bridge does. Every village repaint came back with a clean wrap and a smear at both inner joins: a melted wall, a ghost of a roof, a tree streaked sideways. The wrap gate never looked there, and each step inside the smear was small, so no join metric could have seen it either.

The construction now registers the whole return and cuts it into the source along the cheapest top-to-bottom path through a search band on each side of the wrap: the path, moving at most one column per row, where the return and the source agree most, in premultiplied RGBA. It is the minimum-error boundary cut of image quilting. Each band runs from LOOP_REPAINT_CUT_REACH_PX columns into the context to LOOP_REPAINT_CUT_GUARD_PX columns short of the wrap, so the wrap always stays inside painted art, and the cut is feathered over LOOP_REPAINT_CUT_FEATHER_PX columns either side. Pixels outside the feathered cuts are the source's own bytes and pixels inside are the return's; only the feather is blended.

On the three village returns the smeared version rejected, the cut leaves no visible join: the two pictures disagree by 0.009 to 0.014 across the cut, against 0.045 to 0.095 at the old fixed columns.

The record carries both cuts as stitches, in the unit's own coordinates: where each landed on every row, and how far the two pictures disagreed across it. Admission judges them with the wrap; see validation.

fold_repaint — break the mirror without breaking the loop

Build [ A | mirror(A) ] as mirror_repeat does, then repaint only the reflection axis so the content stops reading back on itself. The wrap fold is left untouched, so the join the loop actually depends on is still a reflection and still cannot fail.

This is the narrow option: it costs a provider operation and keeps the doubled period, buying only the removal of the visible symmetry. It earns its place for a layer that must not read as mirrored and where seam_repaint has been rejected.

Geometry and period consequences

ConstructionPeriodProvider opsMirrored content
direct admissionunchanged0none
mirror_repeat2W0half the period
generated_bridgeW + bridge_span1none
seam_repaintW1none
fold_repaint2W1half the period, repainted

Layers within one map therefore end up on different periods, and every downstream consumer has to treat the period as a per-layer fact:

Vertical placement is unaffected. Loop construction only ever appends horizontally, and the vertical trim and placement measurement described in the map-generation contract run afterwards on the constructed unit.

Authored surface

[continuity]
seamless_axis = "x"
loop_construction = "mirror_repeat"   # map default, required
loop_fallback = "mirror_repeat"       # optional; must be deterministic

[[layer]]
layer_id = "village"
loop_construction = "seam_repaint"    # optional per-layer override

The map field is required: there is no safe default, because the constructions trade correctness cost against composition cost in opposite directions and the right answer depends on what the map's layers depict.

The per-layer field is optional and wins over the map's when present. Layers within one map do not share a difficulty. A layer whose own ends already agree loops under any construction; a layer whose ends disagree in the source art fails under all of them. A single map-wide choice cannot say so, which is why the override exists.

loop_fallback is what runs when a generative construction cannot be completed. It is validated to be deterministic: a fallback that can itself fail is not a fallback.

Everything else — context spans, repaint window and span, anchor band, seam cut reach, guard and feather, brief version and framing — belongs to the construction and is versioned. It is not authored, because it describes how the provider is conditioned rather than a creative choice.

Cache identity

loop_construction is excluded from layer-generation cache identity — at both the map and the layer level — and from the shared map direction digest. Changing a construction re-runs the loop node and everything downstream of it, and never re-bills a layer image that would return byte-identical.

The loop node's own identity is scoped to the construction that layer actually selected: its version, its guarantee, its mutability, and only the constants that construction consumes. seam_repaint binds its cut version and cut constants; the bridge and the fold bind the anchor band they still use. Deterministic constructions bind no registration or anchor version at all, because they have no provider return to register. Every construction binds the admission gate's version, because admission runs first and decides whether the construction runs at all.

This scoping is the point rather than an optimisation. The identity previously bound every construction's version at once, so revising any one of them re-ran the loop node for every layer in every map regardless of what it had selected — a cost that would grow with each construction added.

Validation and evidence

Each loop node writes <layer>.loop.png and <layer>.loop.json. The record carries the construction that ran, the resulting period, the provider operation count, and the admission report for the constructed unit.

Every construction is re-admitted before it is accepted, and the layer's published artifact is re-admitted again after the vertical trim — the bytes that ship must be the bytes that passed, and trimming empty rows can change a raster's edge statistics.

Admission holds every join to the picture it sits in: the mean colour, gradient and alpha steps across the join against the same steps at the layer's own interior columns (single-axis-continuity-v3). A seam_repaint unit is judged on three joins, not one: its wrap and its two stitches. A stitch fails on its step like any join, and also when the two stitched pictures disagreed across it by more than the layer's own interior steps, because that is a ghost however smooth the blend. Either failure sends the layer to its fallback with the rejected report recorded.

A bridged unit's join metric is vacuous on its own. Anchoring assigns the boundary columns to equal their neighbours, and admission then measures those same columns, so color_mae is exactly 0.0 by construction and carries no information. What actually evidences a bridge is the registration record: agreement between the two bands, and the residual after correction. Read those, not the join.

Deterministic admission is also not a quality verdict. It cannot see that a bridge is tonally mismatched with the strip it joins, that a mirrored period reads as a reflection, or that a cut-out layer came back with an opaque matte where the source is transparent. Those are the map review's business, and its looping_continuity check is the gate that speaks to them.

Failure modes

SymptomCauseWhere it surfaces
Loop node failsConstructed unit did not pass re-admissionNode error, run summary
A generative construction silently produced the fallbackContext bands disagreed, so the return was rejectedrejected_construction and rejection in the loop record
Content steps vertically at both joinsRegistration not applied, or applied from a stale offsetLoop record registration; visible in the composite
An object is cut in half at a joinProvider composed across the cut line; the brief invited a compositionMap review looping_continuity
Bridge span reads as a tonal blockProvider painted the span in a different key from the stripMap review looping_continuity
Opaque fill where the source is transparentCut-out alpha clause not honoured on a transparent layerLayer validation, review board
Landmark appears twice per period, reflectedmirror_repeat on a high-salience layerMap review looping_continuity
A join reads correctly but the layer lost contentA repaint construction replaced pixels; the source is not recoverableLoop record mutates_source
Smear or ghost a short way either side of the wrapA repaint forced onto the source at a fixed column; the pictures disagree thereStitch join clipped_or_disconnected_form; the layer falls back and rejected_repeat records it
Composite crops a layerA consumer assumed one shared periodComposite geometry, review board

Related