Skip to content

Migrating from 0.1 to 0.2

Start with the .rkg source and keep your 0.1 binary, recordings and reference traces. Change the spellings first. Then run rastok check: some diagnostics ask you to make a decision, such as when a keyed instance should stop or what to do when a list is empty. The authoring rules pair these refusals with working 0.2 code.

In 0.1In 0.2What to keep in mind
Type textstringChange declarations, type tests and casts. Do not edit the text inside string literals. You can declare type text = string in your own unit; it covers type positions only.
Verbatim block text! { received }string! { received }Change only the reader name. The spaces inside the braces are part of the value.
codec = textcodec = stringApplies to HttpClient, HttpServer, WebSocketClient and WebSocketServer. The wire encoding stays the same. The codec word is part of the plan’s identity.
Process overflow reason budget or capacityBudget or CapacityThese are enum symbols. Update matches, mocks and JSON consumers: JSON carries the exact spelling.
@sensitive(level = confidential)@sensitive(level = Confidential)Use Internal, Confidential or Restricted. The protection level keeps its identity. Configuration words such as codec = json and kind = age stay lowercase.

The old type without an alias, and the old reader with or without one, produce E-RESOLVE-UNKNOWN. The old network codec produces E-CONTRACT-ATTR.

Give every var an initial value. Write var last: string = "" for an empty string, or var last: string? = null if it starts absent. If you omit the initializer, check points to the declaration and suggests a fix.

In 0.1, inside lifetimeIn 0.2When the instance closes
kind = fixed; after = Dkind = age; max = DAfter the elapsed time measured from creation.
kind = tumbling; every = Dkind = slot; max = DAt the end of its processing-time slot.
kind = single_passkind = onceAfter one admission.
kind = idle; after = Dkind = idle; max = DAfter no admissions for the specified duration.

Here D stands for a positive duration such as duration("5m"). The old kinds and fields produce E-INSTANCE. Do not rename every on a Timer or change a Retry delay.

A Graph, Operator or Connector that declares an instance key must also declare a lifetime (E-LIFETIME-REQUIRED). Add lifetime = { kind = persistent } to keep the old behavior and hash. That also keeps every key alive until explicitly stopped. If a keyed Operator can finish its first reaction without retaining state or stopping, check warns with W-EMPTY-INSTANCE: that empty instance has no deadline. For a session that should expire after two hours of silence, use lifetime = { kind = idle; max = duration("2h") } instead. Without a key, omitting the lifetime still gives a persistent singleton. See Instances, state and time for closure budgets: every finite owner containing an outbound Connector has to declare both budgets, including the App. This is not specific to Process.

In 0.1In 0.2
xs[i] with no proof the index existsUse xs[?i]; an out-of-range index gives null.
m[k] or m.name with no proof the key existsUse m[?k] or m.?name. Mark each step that can be absent.
x as T when the conversion can failTest x is T before using it, or use x as? T and handle null.
timestamp(s), duration(s) or decimal(s) on runtime textThe same call yields an optional value. For example, sending timestamp(s) straight to a timestamp port gives E-PORT-TYPE. Test the value, match it or supply a meaningful default with .orValue(default).
A malformed constant such as timestamp("not a date")Correct the literal: check rejects it with E-EXPR, including inside a reaction.
meta.app.id when some incoming routes write id and others do notWrite it on every route, or use meta.app.?id and handle absence. The required read reports E-META-ZONE and names the route’s origin. If the graph never writes id, even the optional read is refused.

Plain lookups and casts still work when the type, a constant or a type test in scope proves they succeed. Otherwise they report E-EXPR. A test such as size(xs) > 0 is not an index proof. If the result type is variant, it already includes null: for a string fallback on a variant map, write (m[?k] as? string).orValue("unknown").

Here an empty list really does mean “unassigned”. Save this as labels.rkg and run rastok simulate labels.rkg to check both paths:

graph labels : App {
input in: array<string>
output out: string
operator first {
input in: array<string>
output out: string
on in { out = data[?0].orValue("unassigned") }
}
in -> first -> out
}
lab labels {
scenario has_label {
app.in = ["blue"]
expect app.out == "blue"
}
scenario no_label {
app.in = []
expect app.out == "unassigned"
}
}

The Lab prints:

PASS labels.has_label
PASS labels.no_label
2 scenario(s), 0 failed

If absence should reject a request instead, keep the optional value and route that case explicitly. The ternary, scenario, mock and expectation syntax has not changed. See Expressions and dispatch.

In 0.1In 0.2
uint for an unsigned 64-bit fieldUse ulong to preserve its range. Keep uint only if 32 bits are intended. The suffix u chooses the first width that fits: 7u is a uint, 4294967296u a ulong.
number for an exact valueUse decimal for an exact value with free scale, or keep decimal(p,s) for a declared scale. For a binary floating result from a variant, use as? double and handle null.
bytes or bytes(n) as a typeUse array<byte> or array<byte, n>. The compact encoding and the bytes codec stay the same. JSON does not implicitly convert bytes to base64.
media_type or media_type(s)Use string and the string value itself. The reserved meta.ext.content_type is a string(255): the entire value, including parameters, must still be a valid MIME Content-Type. Other strings have no MIME requirement.
HttpClient DecodeFailed {} in a mock or exact expectationDecodeFailed { message = "…" }

A numeric literal can take the expected type if it fits. A calculated value widens implicitly only if its whole type fits. For example, an int and a uint can meet at long. A long does not always fit a double: use as? double when the conversion depends on the value. Schemaless JSON reads a number as long, ulong or double, in that order, and rejects it if none preserves its value. Declare an exact decimal at the boundary when that is what the protocol requires. See Types and schemas.

HttpClient. For http://, the default works with an HTTP/1.1 server. Select only "http/2" when the server expects cleartext HTTP/2. For a response with status 204 or 205, handle Completed on exit. Do not wait for a body on out or supply one in the corresponding mock. For a typed JSON response, declare a timestamp field to read an RFC 3339 UTC string ending in Z. If a declared field cannot be read, the Call ends with DecodeFailed and delivers nothing on out. The message names the declared field and the expected type. If the body is not JSON, it names out instead. For a request that cannot be encoded, it names in and the expected representation; no request is sent. Neither message includes a rejected value or a key supplied by the peer.

Keep a case test such as data is DecodeFailed. In that branch you can read data.message. Supply a message when constructing the case: in a mock, exit = DecodeFailed {} now gives this diagnostic:

error[E-PORT-TYPE]: `DecodeFailed` requires field `message: string`

The HttpClient contract stays at @1. This change does not affect WebSocket cases or make timestamps writable as JSON.

A schemaless JSON codec delivers an object as a map, including when a mock writes a record. If all sources of an input deliver schemaless JSON, replace data is Receipt with val receipt = data as? Receipt and handle null. The mock still receives the graph’s typed request.

The format 2 plan reader rejects a format 1 .rkp: recompile the ported .rkg source. Diagnostic recordings (.rkr) keep format 1, but replay also checks the plan embedded in the recording. Keep the 0.1 binary to replay recordings with a format 1 plan.

Run rastok check and then rastok simulate before using real Drivers. Compare against the existing .rkc references first. For example, from the repository root:

Terminal window
rastok check examples/echo.rkg
rastok simulate examples/echo.rkg --compare examples/traces/echo

A different plan hash is not by itself a different delivery. Review the first differing record, including whether only a recorded Retry plan hash changed. If you intend to change the reference, use --save in a separate directory and review the differences before replacing the old files.

Diagram