Change windows

A deployment pipeline asks if it can deploy a change now. A standard change needs the change window in London and no freeze. An emergency change needs an approver. The policy reads the time with time.now_ns, a provided value: a signed decision records it.

Bundle change-windows, revision 2026-12-03, decision data.changes.window.decision

Examples

Input: emergency-change

{
  "change": {
    "approved_by": "carol",
    "kind": "emergency",
    "service": "checkout"
  }
}

Ask the decision serverOpen in the debugger

Files

Show tree shaking for the decision

1# The change windows of a deployment pipeline. The policy reads the time of the query with `time.now_ns`, and
2# the time zone data with `time.clock` and `time.weekday`. These builtins are provided: the result of the query
3# depends on them, so a signed decision records their values.
4package changes.window
5
6now := time.now_ns()
7
8# The day and the time in the zone of the change window, for example "Thursday" and [14, 5, 0].
9weekday := time.weekday([now, data.changes.zone])
10
11clock := time.clock([now, data.changes.zone])
12
13default allow := false
14
15# A standard change needs the change window and no freeze.
16allow if {
17 input.change.kind == "standard"
18 in_window
19 count(freezes) == 0
20}
21
22# An emergency change can go at any time, if somebody approved it.
23allow if {
24 input.change.kind == "emergency"
25 input.change.approved_by != ""
26}
27
28in_window if {
29 weekday in data.changes.window.days
30 data.changes.window.from_hour <= clock[0]
31 clock[0] < data.changes.window.to_hour
32}
33
34# The freezes now.
35freezes contains freeze.reason if {
36 some freeze in data.changes.freezes
37 time.parse_rfc3339_ns(freeze.from) <= now
38 now < time.parse_rfc3339_ns(freeze.to)
39}
40
41reasons contains "outside the change window" if not in_window
42
43reasons contains reason if some reason in freezes
44
45decision := {
46 "allow": allow,
47 "local_time": sprintf("%s %02d:%02d %s", [weekday, clock[0], clock[1], data.changes.zone]),
48 "reasons": reasons,
49}
50