{
  "schemaVersion": 1,
  "id": "agent-streaming-resume",
  "function": "resume_stream",
  "starter": "def resume_stream(payload):\n    \"\"\"Implement the public contract; disclose assistance used.\"\"\"\n    raise NotImplementedError(\"agent-streaming-resume\")\n",
  "checks": [
    {
      "id": "contiguous-complete",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 3,
            "kind": "done",
            "text": ""
          },
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": "queued"
          }
        ]
      },
      "expected": {
        "text": "Refund queued",
        "last_seq": 3,
        "status": "complete",
        "need_seq": null,
        "applied": [
          2,
          3
        ]
      },
      "error": null
    },
    {
      "id": "duplicate-delivery",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": "queued"
          },
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": "queued"
          },
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 3,
            "kind": "done",
            "text": ""
          }
        ]
      },
      "expected": {
        "text": "Refund queued",
        "last_seq": 3,
        "status": "complete",
        "need_seq": null,
        "applied": [
          2,
          3
        ]
      },
      "error": null
    },
    {
      "id": "history-ignored",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 1,
            "kind": "delta",
            "text": "old replay"
          },
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": "queued"
          }
        ]
      },
      "expected": {
        "text": "Refund queued",
        "last_seq": 2,
        "status": "streaming",
        "need_seq": 3,
        "applied": [
          2
        ]
      },
      "error": null
    },
    {
      "id": "gap-does-not-advance",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 3,
            "kind": "delta",
            "text": "late"
          }
        ]
      },
      "expected": {
        "text": "Refund ",
        "last_seq": 1,
        "status": "waiting",
        "need_seq": 2,
        "applied": []
      },
      "error": null
    },
    {
      "id": "empty-poll",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": false
        },
        "chunks": []
      },
      "expected": {
        "text": "Refund ",
        "last_seq": 1,
        "status": "streaming",
        "need_seq": 2,
        "applied": []
      },
      "error": null
    },
    {
      "id": "cursor-zero-unicode",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 0,
          "text": "",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 1,
            "kind": "delta",
            "text": "退款"
          },
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": "待处理"
          }
        ]
      },
      "expected": {
        "text": "退款待处理",
        "last_seq": 2,
        "status": "streaming",
        "need_seq": 3,
        "applied": [
          1,
          2
        ]
      },
      "error": null
    },
    {
      "id": "conflicting-sequence",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": "queued"
          },
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": "different"
          }
        ]
      },
      "expected": null,
      "error": "ValueError:chunk_conflict"
    },
    {
      "id": "foreign-trace",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-2",
            "seq": 3,
            "kind": "done",
            "text": ""
          },
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": "queued"
          }
        ]
      },
      "expected": null,
      "error": "ValueError:stream_identity"
    },
    {
      "id": "foreign-tenant",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "B",
            "trace": "stream-1",
            "seq": 3,
            "kind": "done",
            "text": ""
          },
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": "queued"
          }
        ]
      },
      "expected": null,
      "error": "ValueError:stream_identity"
    },
    {
      "id": "data-after-done",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "done",
            "text": ""
          },
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 3,
            "kind": "delta",
            "text": "late"
          }
        ]
      },
      "expected": null,
      "error": "ValueError:after_done"
    },
    {
      "id": "finished-checkpoint-new-data",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": true
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": "late"
          }
        ]
      },
      "expected": null,
      "error": "ValueError:after_done"
    },
    {
      "id": "bool-cursor",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": true,
          "text": "Refund ",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 3,
            "kind": "done",
            "text": ""
          },
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": "queued"
          }
        ]
      },
      "expected": null,
      "error": "ValueError:input_shape"
    },
    {
      "id": "done-with-text",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "done",
            "text": "not empty"
          }
        ]
      },
      "expected": null,
      "error": "ValueError:input_shape"
    },
    {
      "id": "empty-delta-advances",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": false
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 2,
            "kind": "delta",
            "text": ""
          }
        ]
      },
      "expected": {
        "text": "Refund ",
        "last_seq": 2,
        "status": "streaming",
        "need_seq": 3,
        "applied": [
          2
        ]
      },
      "error": null
    },
    {
      "id": "already-complete-no-new",
      "input": {
        "checkpoint": {
          "tenant": "A",
          "trace": "stream-1",
          "last_seq": 1,
          "text": "Refund ",
          "complete": true
        },
        "chunks": [
          {
            "tenant": "A",
            "trace": "stream-1",
            "seq": 1,
            "kind": "delta",
            "text": "old replay"
          }
        ]
      },
      "expected": {
        "text": "Refund ",
        "last_seq": 1,
        "status": "complete",
        "need_seq": null,
        "applied": []
      },
      "error": null
    }
  ]
}
