# Workflows and retained containers

Each named workflow contains a complete Workflow XML document as decoded inline
text, usually CDATA. Use the Workflow XML vocabulary for its nodes and connections.
Embedded integration_action nodes use instanceId self and a declared Action name.
A workflow uses the instance version it started with, including during an upgrade.

```xml
<integration id="com.example.workflow" version="1.0.0" sdk-version="2.0">
  <actor><actions><action name="echo" label="Echo"><source>return ...</source></action></actions></actor>
  <workflows><workflow name="echo"><![CDATA[
<workflow>
  <nodes><node id="call" type="integration_action"><config>
    <value name="instanceId">self</value><value name="actionName">echo</value>
  </config></node></nodes><edges/>
</workflow>
]]></workflow></workflows>
</integration>
```

Named data-container schemas describe retained instance records. Writes validate
real JSON, ownership, tag types, byte limits and per-instance counts. Omitted tag
types allow no attachments. job and customer tags are supported and tenant scoped.

```xml
<integration id="com.example.containers" version="1.0.0" sdk-version="2.0">
  <data-container-schemas><schema name="orders" max-per-instance="20">
    <description>Retained order records</description><taggable-type>job</taggable-type>
    <json-schema>
      <schema type="object" xmlns="urn:cococo:json-schema:1">
        <additional-properties boolean="false"/>
        <property name="orderId" type="string"/>
        <required name="orderId"/>
      </schema>
    </json-schema>
  </schema></data-container-schemas>
</integration>
```

Use ctx.store.get, ctx.store.put, ctx.store.delete, ctx.store.list and
ctx.store.query. Put takes a name, data and declared schemaName. List accepts bounded
pagination; query applies its declared schema and tag predicates. Async functions
return a success flag and value. Container values and results are bounded to 2 MiB of encoded JSON.

An upgrade checks retained records against destination schemas and limits. Its
hook may explicitly migrate or remove old records. Removed schemas, incompatible
data/tags and reduced counts cannot silently discard retained state.

An upgrade hook may delete obsolete retained containers before the instance
moves to the new definition version. This access exists only while the instance
is upgrading. The remaining containers must meet the destination schema and
count limits before the upgrade completes. Ordinary handlers remain pinned to
the installed version.