Add bounded avatar rejection fields and task music ASR audit

This commit is contained in:
zenord
2026-10-13 06:19:54 +08:00
parent 33b552473a
commit c4ddf8964f
10 changed files with 386 additions and 13 deletions
@@ -37,8 +37,12 @@ object BodyTimeline {
/** This parser admits only coordinator-selected debug runtime data; no production graph. */
object ContinuousAvatarManifest {
@Suppress("UNCHECKED_CAST")
fun read(root: Map<String,Any?>,sha: String,expectedSha: String,debug: Boolean,pathRoot: String): ContinuousAvatarPack? {
if(!debug || !expectedSha.matches(Regex("[0-9a-f]{64}")) || sha!=expectedSha) return null
fun read(root: Map<String,Any?>,sha: String,expectedSha: String,debug: Boolean,pathRoot: String,
onReject: ((String)->Unit)? = null): ContinuousAvatarPack? {
if(!debug || !expectedSha.matches(Regex("[0-9a-f]{64}")) || sha!=expectedSha) {
onReject?.invoke("externalPin");return null
}
var field="schemaVersion"
return try {
fun obj(v: Any?)=v as Map<String,Any?>
fun integer(v: Any?): Long { val n=v as Number; val l=n.toLong(); require(n.toDouble()==l.toDouble()); return l }
@@ -49,7 +53,9 @@ object ContinuousAvatarManifest {
val apertureMode=root["packId"]=="a01-neutral-graph-v1-runtime-04" || dynamic
require(integer(root["schemaVersion"])==(if(dynamic) 2L else 1L) && root["identityId"]=="a01" &&
(apertureMode || root["packId"]=="a01-neutral-graph-v1-runtime-03"))
field="publishApproval/runtimeReady"
require(root["publishApproval"]==false && root["runtimeReady"]==true)
field="body"
val b=obj(root["body"])
val count=smallInt(b["frameCount"]);require(count in 2..BodyTimeline.MAX_TALK_FRAMES)
val fpsN=smallInt(b["fpsNumerator"]);val fpsD=smallInt(b["fpsDenominator"])
@@ -62,6 +68,7 @@ object ContinuousAvatarManifest {
require(count==97 && kotlin.math.abs(body.durationUs-4_041_667)<=2 && fpsN==24 && fpsD==1)
require(integer(b["frameDurationUsNumerator"])==1_000_000L && integer(b["frameDurationUsDenominator"])==24L)
}
field="patchFormat"
val patchFormat=obj(root["patchFormat"])
require(patchFormat["alphaEncoding"]=="straight_unassociated" && patchFormat["format"]=="PNG RGBA 8bit")
if(dynamic) require(hash(patchFormat["bodySha256"])==body.sha256)
@@ -69,8 +76,10 @@ object ContinuousAvatarManifest {
require((patchFormat["apertureLevels"] as List<*>).map(::finite)==listOf(0f,.25f,.5f,.75f,1f))
require(patchFormat["requiresRendererExtension"]==true)
}
field="patches"
val rows=root["patches"] as List<Map<String,Any?>>; require(rows.size==count)
val patches=rows.mapIndexed { index,p ->
field="patches[$index]"
val patch=RegisteredMouthPatch(smallInt(p["frameIndex"]),integer(p["ptsUs"]),p["path"] as String,hash(p["sha256"]),
finite(p["x"]),finite(p["y"]),smallInt(p["width"]),smallInt(p["height"]))
require(patch.frameIndex==index && if(dynamic) patch.ptsUs==pts[index] else kotlin.math.abs(patch.ptsUs-pts[index])<=2)
@@ -78,7 +87,9 @@ object ContinuousAvatarManifest {
require(patch.width in 1..128 && patch.height in 1..128 && patch.x>=0 && patch.y>=0 &&
patch.x+patch.width<=480 && patch.y+patch.height<=848)
if(apertureMode) {
field="patches[$index].levels"
val levels=(p["levels"] as List<Map<String,Any?>>).also { require(it.size==5) }.mapIndexed { level,row ->
field="patches[$index].levels[$level]"
require(level in 0..4 && smallInt(row["levelIndex"])==level && finite(row["aperture"])==level/4f)
MouthPatchLevel(level,level/4f,row["path"] as String,hash(row["sha256"])).also {
require(it.path.matches(Regex("patches/[a-zA-Z0-9_.-]+\\.png")))
@@ -91,19 +102,27 @@ object ContinuousAvatarManifest {
patch
}
}
field="patches.uniquePaths/cacheBytes"
val paths=patches.flatMap { if(apertureMode) it.levels.map { l -> l.path } else listOf(it.path) }
require(paths.distinct().size==count*(if(apertureMode) 5 else 1))
require(patches.sumOf { it.width*it.height*4L*(if(apertureMode) 5 else 1) }<=BodyTimeline.MAX_RGBA_BYTES)
field="mouthStates"
val states=root["mouthStates"] as List<Map<String,Any?>>
require(states.size==5)
val c=states.associateBy { it["id"] as String }
require(c.keys==setOf("idle","opening","talk1","talk2","end-talk"))
val curves=c.mapValues { (id,v) ->
val stateField="mouthStates[${states.indexOf(v)}]"
field="$stateField.durationMs"
val row=obj(v); val duration=integer(row["durationMs"])
field="$stateField.globalAlphaByFrame"
val alpha=(row["globalAlphaByFrame"] as List<*>).also { require(it.size in 2..60) }.map(::finite)
val bridge=id in setOf("opening","end-talk")
field="$stateField.frameCount"
require(integer(row["frameCount"])==alpha.size.toLong())
field="$stateField.ptsUs"
val curvePts=if(dynamic) (row["ptsUs"] as List<*>).also { require(it.size==alpha.size) }.map(::integer) else alpha.indices.map { it*1_000_000L/24 }
field="$stateField.timeline"
if(dynamic) {
require(duration in 100..1_000 && BodyTimeline.valid(curvePts,alpha.size,duration*1000,
smallInt(row["fpsNumerator"]),smallInt(row["fpsDenominator"]),60,1_000_000))
@@ -112,9 +131,13 @@ object ContinuousAvatarManifest {
require(alpha.size==if(bridge) 6 else 12)
require(integer(row["fpsNumerator"])==24L && integer(row["fpsDenominator"])==1L)
}
field="$stateField.globalAlphaByFrame"
require(alpha.all { it in 0f..1f })
field="$stateField.entryMouthAnchor"
require(row["entryMouthAnchor"]==if(id in setOf("idle","opening")) "A" else "B")
field="$stateField.exitMouthAnchor"
require(row["exitMouthAnchor"]==if(id in setOf("idle","end-talk")) "A" else "B")
field="$stateField.globalAlphaByFrame"
when(id) {
"idle" -> require(alpha.all { it==0f })
"opening" -> require(alpha.first()==0f && alpha.last()==1f)
@@ -123,14 +146,16 @@ object ContinuousAvatarManifest {
}
MouthCurve(id,duration,alpha,curvePts)
}
field="stateRouting"
val routing=obj(root["stateRouting"])
val required=mapOf("idle" to setOf("idle","opening"),"opening" to setOf("talk1","talk2","end-talk"),
"talk1" to setOf("talk1","talk2","end-talk"),"talk2" to setOf("talk1","talk2","end-talk"),"end-talk" to setOf("idle"))
require(routing.keys==required.keys)
required.forEach { (id,targets) ->
field="stateRouting.$id"
val list=routing[id] as List<*>;require(list.size==targets.size && list.toSet()==targets)
}
ContinuousAvatarPack(body,patches,curves,pathRoot,sha,apertureMode)
} catch(_: Exception) { null }
} catch(_: Exception) { onReject?.invoke(field);null }
}
}
@@ -14,8 +14,12 @@ data class ConversationEdge(val id: String,val from: String,val to: String,val f
object EmotionActionManifest {
@Suppress("UNCHECKED_CAST")
fun read(root: Map<String,Any?>, actualSha: String, piPinnedSha: String,pathRoot: String="",
loadRuntime: (String,String)->ContinuousAvatarPack?): EmotionActionIndex? = try {
onReject: ((String)->Unit)? = null,
loadRuntime: (String,String)->ContinuousAvatarPack?): EmotionActionIndex? {
var field="externalPin"
return try {
require(piPinnedSha.matches(Regex("[0-9a-f]{64}")) && actualSha==piPinnedSha)
field="schemaVersion/identityId/packId"
require(root["schemaVersion"]==2L || root["schemaVersion"]==2)
require(root["identityId"]=="a01" && root["packId"]=="a01-expression-action-v1")
fun obj(value: Any?)=value as Map<String,Any?>
@@ -26,16 +30,20 @@ object EmotionActionManifest {
fun integer(value: Any?): Long { val n=value as Number;require(n.toDouble()==n.toLong().toDouble());return n.toLong() }
fun boundedInt(value: Any?, maximum: Int): Int = integer(value).also { require(it in 1..maximum.toLong()) }.toInt()
val fallback=root["fallbackPackageId"] as String
field="conversationPackages"
val rows=root["conversationPackages"] as List<Map<String,Any?>>
require(rows.isNotEmpty() && rows.size<=12 && rows.map { it["id"] }.distinct().size==rows.size)
val packages=linkedMapOf<String,ContinuousAvatarPack>()
val visuals=rows.map { row ->
val visuals=rows.mapIndexed { index,row ->
field="conversationPackages[$index]"
val id=row["id"] as String;require(id.matches(Regex("[a-z0-9_-]{1,48}")))
val emotion=RoleEmotion.entries.single { it.wire==row["emotion"] }
require(emotion in setOf(RoleEmotion.NEUTRAL,RoleEmotion.HAPPY,RoleEmotion.SAD) &&
integer(row["visualIntensity"])==if(emotion==RoleEmotion.NEUTRAL) 0L else 1L)
field="conversationPackages[$index].runtimeManifest"
val reference=obj(row["runtimeManifest"])
val runtime=checkNotNull(loadRuntime(path(reference["path"]),hash(reference["sha256"])))
field="conversationPackages[$index].mouthBodySha256"
require(runtime.apertureMode && runtime.body.sha256==hash(row["mouthBodySha256"]))
require(runtime.patches.size==runtime.body.frameCount && runtime.patches.all { it.levels.size==5 })
require(runtime.body.ptsUs==runtime.patches.map { it.ptsUs } &&
@@ -45,16 +53,23 @@ object EmotionActionManifest {
val pts=runtime.patches.map { it.ptsUs }
TalkPackage(id,emotion,runtime.body.sha256,hash(row["mouthBodySha256"]),runtime.body.ptsUs,pts,false)
}
field="conversationPackages.cacheBytes/fallbackPackageId"
require(packages.values.sumOf { it.rgbaBytes }<=BodyTimeline.MAX_PACK_CACHE_BYTES)
require(visuals.single { it.id==fallback }.emotion==RoleEmotion.NEUTRAL)
field="edges"
val edges=root["edges"] as List<Map<String,Any?>>
require(edges.size<=100 && edges.map { it["id"] }.distinct().size==edges.size)
val admittedEdges=edges.map { edge ->
val admittedEdges=edges.mapIndexed { index,edge ->
val edgeField="edges[$index]"
field="$edgeField.from/to"
require(edge["from"] in packages && edge["to"] in packages)
val from=checkNotNull(packages[edge["from"]]);val to=checkNotNull(packages[edge["to"]])
field="$edgeField.fromFrame"
require(integer(edge["fromFrame"]) in 0 until from.body.frameCount.toLong())
field="$edgeField.toFrame"
require(integer(edge["toFrame"]) in 0 until to.body.frameCount.toLong())
require(edge["fromAnchor"]=="A" && edge["toAnchor"]=="A")
field="$edgeField.clip"
val clip=obj(edge["clip"]);path(clip["path"]);hash(clip["sha256"])
require(clip["hasAudio"]==false && integer(clip["width"])==480L && integer(clip["height"])==848L)
val count=boundedInt(clip["frameCount"],BodyTimeline.MAX_TALK_FRAMES)
@@ -62,15 +77,20 @@ object EmotionActionManifest {
require(BodyTimeline.valid(pts,count,integer(clip["durationUs"]),
boundedInt(clip["fpsNumerator"],120_000),boundedInt(clip["fpsDenominator"],10_000)))
val source=rows.single { it["id"]==edge["from"] }
field="$edgeField.fromFrame/legalExitFrames"
require(integer(edge["fromFrame"]) in (source["legalExitFrames"] as List<*>).map(::integer))
field="$edgeField.fromPtsUs"
require(integer(edge["fromPtsUs"])==from.body.ptsUs[integer(edge["fromFrame"]).toInt()])
field="$edgeField.toPtsUs"
require(integer(edge["toPtsUs"])==to.body.ptsUs[integer(edge["toFrame"]).toInt()])
field="$edgeField.nativeLoop"
require(edge["nativeLoop"]==null || edge["nativeLoop"] is Boolean)
val nativeLoop=edge["nativeLoop"]==true
if(nativeLoop) require(edge["from"]==edge["to"] && integer(edge["fromFrame"])==from.body.frameCount-1L &&
integer(edge["toFrame"])==0L && hash(clip["sha256"])==from.body.sha256 && pts==from.body.ptsUs &&
integer(clip["durationUs"])==from.body.durationUs)
val mouthRuntime=edge["mouthRuntimeManifest"]?.let { value ->
field="$edgeField.mouthRuntimeManifest"
require(!nativeLoop) // Native loops already use their exact package layer.
val reference=obj(value)
val runtime=checkNotNull(loadRuntime(path(reference["path"]),hash(reference["sha256"])))
@@ -83,6 +103,7 @@ object EmotionActionManifest {
runtime.body.fpsDenominator==integer(clip["fpsDenominator"]).toInt())
runtime
}
field="$edgeField.mouthAllowed"
require(edge["mouthAllowed"]==null || edge["mouthAllowed"] is Boolean)
require(edge["mouthAllowed"]!=true || nativeLoop || mouthRuntime!=null)
require(mouthRuntime==null || edge["mouthAllowed"]!=false)
@@ -91,9 +112,11 @@ object EmotionActionManifest {
ContinuousBodyAsset(path(clip["path"]),hash(clip["sha256"]),480,848,pts.size,
integer(clip["durationUs"]),pts,boundedInt(clip["fpsNumerator"],120_000),boundedInt(clip["fpsDenominator"],10_000)),nativeLoop,mouthRuntime)
}
field="combinedRuntimeCacheBytes"
require(packages.values.sumOf { it.rgbaBytes }+
admittedEdges.mapNotNull { it.mouthRuntime }.sumOf { it.rgbaBytes }<=BodyTimeline.MAX_PACK_CACHE_BYTES)
val admitted=visuals.map { visual ->
field="conversationPackages[${rows.indexOfFirst { it["id"]==visual.id }}].anchors/loopEdge/legalExitFrames"
val row=rows.single { it["id"]==visual.id }
require(row["entryAnchor"]=="A" && row["exitAnchor"]=="A")
val loop=row["loopEdge"] as String
@@ -106,12 +129,16 @@ object EmotionActionManifest {
}
visual.copy(approvedEdges=true)
}
field="actions"
val actions=root["actions"] as List<Map<String,Any?>>
val actionPack=if(actions.isEmpty()) null else {
require(actions.size==2 && actions.map { it["id"] }.toSet()==setOf("asset_01","asset_02"))
val assets=actions.map { action ->
val assets=actions.mapIndexed { index,action ->
val actionField="actions[$index]"
field="$actionField.kind/mouthAllowed/disallowTALK/anchors"
require(action["kind"]=="dance" && action["mouthAllowed"]==false && action["disallowTALK"]==true)
require(action["entryAnchor"]=="A" && action["returnAnchor"]=="A")
field="$actionField.clip/audioEndUs"
val clip=obj(action["clip"]);path(clip["path"]);hash(clip["sha256"])
val duration=integer(clip["durationUs"])
require(clip["hasAudio"]==true && integer(action["audioEndUs"]) in 1..duration)
@@ -121,11 +148,14 @@ object EmotionActionManifest {
require(BodyTimeline.valid(pts,count,duration,
boundedInt(clip["fpsNumerator"],120_000),boundedInt(clip["fpsDenominator"],10_000),5400,90_000_000))
require(duration in 1_000_000..90_000_000)
field="$actionField.sourcePackageId/returnPackageId"
require(action["sourcePackageId"]==fallback && action["returnPackageId"]==fallback)
val runtime=packages.getValue(fallback)
field="$actionField.sourceFrame/returnFrame"
val sourceFrame=integer(action["sourceFrame"]);val returnFrame=integer(action["returnFrame"])
require(sourceFrame in 0 until runtime.body.frameCount.toLong() && returnFrame in 0 until runtime.body.frameCount.toLong())
require(sourceFrame in (rows.single { it["id"]==fallback }["legalExitFrames"] as List<*>).map(::integer))
field="$actionField.sourcePtsUs/returnPtsUs"
require(integer(action["sourcePtsUs"])==runtime.body.ptsUs[sourceFrame.toInt()] &&
integer(action["returnPtsUs"])==runtime.body.ptsUs[returnFrame.toInt()])
ActionAsset(action["id"] as String,(duration+999)/1000,ActionMedia(path(clip["path"]),hash(clip["sha256"]),pathRoot,
@@ -134,5 +164,6 @@ object EmotionActionManifest {
ReviewedActionPack(actualSha,assets)
}
EmotionActionIndex(fallback,packages,admitted,actionPack,admittedEdges,pathRoot,rows.associate { it["id"] as String to it["loopEdge"] as String })
} catch(_: Exception) { null }
} catch(_: Exception) { onReject?.invoke(field);null }
}
}