{
  "schemaVersion": 1,
  "id": "agent-state-reducers",
  "function": "reduce_state",
  "starter": "def reduce_state(payload):\n    \"\"\"Implement the public contract; disclose assistance used.\"\"\"\n    raise NotImplementedError(\"agent-state-reducers\")\n",
  "checks": [
    {
      "id": "merge-two-writers",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "retriever",
            "seq": 1,
            "patch": {
              "notes": [
                {
                  "id": "n2",
                  "text": "policy found"
                }
              ]
            }
          },
          {
            "writer": "executor",
            "seq": 1,
            "patch": {
              "status": "ready",
              "notes": [
                {
                  "id": "n1",
                  "text": "validated"
                }
              ]
            }
          }
        ]
      },
      "expected": {
        "task_id": "ticket-1",
        "tenant": "A",
        "status": "ready",
        "notes": [
          {
            "id": "n0",
            "text": "opened"
          },
          {
            "id": "n1",
            "text": "validated"
          },
          {
            "id": "n2",
            "text": "policy found"
          }
        ]
      },
      "error": null
    },
    {
      "id": "arrival-order-permutation",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "executor",
            "seq": 1,
            "patch": {
              "status": "ready",
              "notes": [
                {
                  "id": "n1",
                  "text": "validated"
                }
              ]
            }
          },
          {
            "writer": "retriever",
            "seq": 1,
            "patch": {
              "notes": [
                {
                  "id": "n2",
                  "text": "policy found"
                }
              ]
            }
          }
        ]
      },
      "expected": {
        "task_id": "ticket-1",
        "tenant": "A",
        "status": "ready",
        "notes": [
          {
            "id": "n0",
            "text": "opened"
          },
          {
            "id": "n1",
            "text": "validated"
          },
          {
            "id": "n2",
            "text": "policy found"
          }
        ]
      },
      "error": null
    },
    {
      "id": "duplicate-event-once",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "retriever",
            "seq": 1,
            "patch": {
              "notes": [
                {
                  "id": "n2",
                  "text": "policy found"
                }
              ]
            }
          },
          {
            "writer": "executor",
            "seq": 1,
            "patch": {
              "status": "ready",
              "notes": [
                {
                  "id": "n1",
                  "text": "validated"
                }
              ]
            }
          },
          {
            "writer": "retriever",
            "seq": 1,
            "patch": {
              "notes": [
                {
                  "id": "n2",
                  "text": "policy found"
                }
              ]
            }
          }
        ]
      },
      "expected": {
        "task_id": "ticket-1",
        "tenant": "A",
        "status": "ready",
        "notes": [
          {
            "id": "n0",
            "text": "opened"
          },
          {
            "id": "n1",
            "text": "validated"
          },
          {
            "id": "n2",
            "text": "policy found"
          }
        ]
      },
      "error": null
    },
    {
      "id": "empty-updates",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": []
      },
      "expected": {
        "task_id": "ticket-1",
        "tenant": "A",
        "status": "waiting",
        "notes": [
          {
            "id": "n0",
            "text": "opened"
          }
        ]
      },
      "error": null
    },
    {
      "id": "executor-progress",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "executor",
            "seq": 2,
            "patch": {
              "status": "running"
            }
          },
          {
            "writer": "executor",
            "seq": 1,
            "patch": {
              "status": "ready",
              "notes": [
                {
                  "id": "n1",
                  "text": "validated"
                }
              ]
            }
          }
        ]
      },
      "expected": {
        "task_id": "ticket-1",
        "tenant": "A",
        "status": "running",
        "notes": [
          {
            "id": "n0",
            "text": "opened"
          },
          {
            "id": "n1",
            "text": "validated"
          }
        ]
      },
      "error": null
    },
    {
      "id": "event-conflict",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "retriever",
            "seq": 1,
            "patch": {
              "notes": [
                {
                  "id": "n2",
                  "text": "policy found"
                }
              ]
            }
          },
          {
            "writer": "retriever",
            "seq": 1,
            "patch": {
              "notes": [
                {
                  "id": "changed",
                  "text": "other"
                }
              ]
            }
          }
        ]
      },
      "expected": null,
      "error": "ValueError:event_conflict"
    },
    {
      "id": "note-conflict",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "retriever",
            "seq": 1,
            "patch": {
              "notes": [
                {
                  "id": "n0",
                  "text": "changed"
                }
              ]
            }
          }
        ]
      },
      "expected": null,
      "error": "ValueError:note_conflict"
    },
    {
      "id": "nonowner-status",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "retriever",
            "seq": 1,
            "patch": {
              "status": "ready"
            }
          }
        ]
      },
      "expected": null,
      "error": "ValueError:status_writer"
    },
    {
      "id": "skip-status",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "executor",
            "seq": 1,
            "patch": {
              "status": "completed"
            }
          }
        ]
      },
      "expected": null,
      "error": "ValueError:status_transition"
    },
    {
      "id": "bool-sequence",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "retriever",
            "seq": true,
            "patch": {
              "notes": [
                {
                  "id": "n2",
                  "text": "policy found"
                }
              ]
            }
          },
          {
            "writer": "executor",
            "seq": 1,
            "patch": {
              "status": "ready",
              "notes": [
                {
                  "id": "n1",
                  "text": "validated"
                }
              ]
            }
          }
        ]
      },
      "expected": null,
      "error": "ValueError:input_shape"
    },
    {
      "id": "unexpected-field",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "retriever",
            "seq": 1,
            "patch": {
              "notes": [
                {
                  "id": "n2",
                  "text": "policy found"
                }
              ]
            }
          },
          {
            "writer": "executor",
            "seq": 1,
            "patch": {
              "status": "ready",
              "notes": [
                {
                  "id": "n1",
                  "text": "validated"
                }
              ]
            }
          }
        ],
        "claimed_passed": true
      },
      "expected": null,
      "error": "ValueError:input_shape"
    },
    {
      "id": "same-note-dedup",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "waiting",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "retriever",
            "seq": 2,
            "patch": {
              "notes": [
                {
                  "id": "n0",
                  "text": "opened"
                },
                {
                  "id": "n0",
                  "text": "opened"
                }
              ]
            }
          }
        ]
      },
      "expected": {
        "task_id": "ticket-1",
        "tenant": "A",
        "status": "waiting",
        "notes": [
          {
            "id": "n0",
            "text": "opened"
          }
        ]
      },
      "error": null
    },
    {
      "id": "backward-status",
      "input": {
        "base": {
          "task_id": "ticket-1",
          "tenant": "A",
          "status": "running",
          "notes": [
            {
              "id": "n0",
              "text": "opened"
            }
          ]
        },
        "updates": [
          {
            "writer": "executor",
            "seq": 1,
            "patch": {
              "status": "ready",
              "notes": [
                {
                  "id": "n1",
                  "text": "validated"
                }
              ]
            }
          }
        ]
      },
      "expected": null,
      "error": "ValueError:status_transition"
    }
  ]
}
