Feature: ETag-based CDN model cache invalidation

When admin replaces a model/art file via the CDN browser, the S3 ETag is
now captured and stored on CardAsset.ContentETag. The ETag is included in
the content sync DTO (CardAssetDto) so clients receive it on every sync.

Client-side ModelCache now keys its disk cache on sha256(url + "#" + etag)
instead of sha256(url), so updating a file at the same CDN path busts the
disk cache automatically. A _CACHE_VER="v2" sentinel purges old-scheme
.bin files on first launch after the client update.

Changes:
- CdnUploadResult: add string? ETag field
- S3CdnClient: capture ETag from PutObjectAsync response
- CardAsset: add string? ContentETag property
- Migration 20260318000001_AddAssetContentETag: add content_etag text column
- ContentMessages: add string? ContentETag to CardAssetDto
- ContentDtoMapper: map ContentETag in CardAsset → CardAssetDto
- CdnBrowser.razor: UploadFileToKeyAsync returns Task<string?> (ETag);
  ReplaceAsync calls PropagateAssetETagAsync which updates CardAsset rows
  and touches CardDefinition.UpdatedAt to trigger a version bump
- ModelCache.gd: versioned disk key + cache migration + etag parameter on
  load_model() and evict()
- game_screen.gd: pass model_asset.contentETag to load_model / retry chain

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-18 09:38:17 -04:00
co-authored by Claude Happy
parent 4f0f0e9c0f
commit 73c3a71194
11 changed files with 677 additions and 45 deletions
@@ -793,6 +793,7 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
var def := ContentCache.get_definition(def_id)
var model_asset := _find_model3d_asset(def)
var model_url := str(model_asset.get("cdnUrl", ""))
var model_etag := str(model_asset.get("contentETag", ""))
if model_url.is_empty():
return
@@ -824,7 +825,7 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
return
if model_node == null:
# Download failed — schedule a background retry.
_schedule_model_retry(iid, model_url, 1)
_schedule_model_retry(iid, model_url, 1, model_etag)
return
# Remove the placeholder MeshInstance3D.
@@ -861,13 +862,13 @@ func _add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false)
_anim_players[iid] = ap
if ap != null:
_play_unit_anim(iid, "idle", true)
)
, model_etag)
## Schedule a retry to (re)download the real GLB model for a unit.
## attempt is 1-based; retries stop after MAX_RETRIES.
## Only schedules if no equal-or-later retry is already pending for this unit.
func _schedule_model_retry(iid: String, model_url: String, attempt: int) -> void:
func _schedule_model_retry(iid: String, model_url: String, attempt: int, etag: String = "") -> void:
const MAX_RETRIES := 10
if attempt > MAX_RETRIES:
return
@@ -877,14 +878,14 @@ func _schedule_model_retry(iid: String, model_url: String, attempt: int) -> void
_unit_model_retries[iid] = attempt
print("[GameScreen] Model retry %d/%d scheduled for %s in 60s" % [attempt, MAX_RETRIES, iid])
get_tree().create_timer(60.0).timeout.connect(
func() -> void: _do_model_retry(iid, model_url, attempt),
func() -> void: _do_model_retry(iid, model_url, attempt, etag),
CONNECT_ONE_SHOT)
## Execute one model retry attempt. Evicts the URL so ModelCache re-downloads it.
## If successful, swaps out the placeholder and starts idle animation.
## If it fails again, schedules the next attempt.
func _do_model_retry(iid: String, model_url: String, attempt: int) -> void:
func _do_model_retry(iid: String, model_url: String, attempt: int, etag: String = "") -> void:
# Was this attempt superseded by a later scheduled retry?
if _unit_model_retries.get(iid, -1) != attempt:
return
@@ -893,12 +894,12 @@ func _do_model_retry(iid: String, model_url: String, attempt: int) -> void:
_unit_model_retries.erase(iid)
return
print("[GameScreen] Model retry %d — downloading %s" % [attempt, model_url])
ModelCache.evict(model_url)
ModelCache.evict(model_url, etag)
ModelCache.load_model(model_url, func(model_node: Node3D) -> void:
if model_node == null:
# Still failing — try again later.
_unit_model_retries.erase(iid)
_schedule_model_retry(iid, model_url, attempt + 1)
_schedule_model_retry(iid, model_url, attempt + 1, etag)
return
_unit_model_retries.erase(iid)
# Use the CURRENT body (may differ from when the retry was first scheduled).
@@ -933,7 +934,7 @@ func _do_model_retry(iid: String, model_url: String, attempt: int) -> void:
if ap != null:
_play_unit_anim(iid, "idle", true)
print("[GameScreen] Model retry %d succeeded for %s" % [attempt, iid])
)
, etag)
## Returns the first Model3D asset dict for a card definition, or {} if none.