indicator integration

This commit is contained in:
2026-03-04 03:28:09 -04:00
parent 185fa42caa
commit a50955558e
14 changed files with 2777 additions and 13 deletions

View File

@@ -116,6 +116,10 @@ class SyncRegistry:
logger.info(f"apply_client_patch: New state after patch: {new_state}")
self._update_model(entry.model, new_state)
# Verify the model was actually updated
updated_state = entry.model.model_dump(mode="json")
logger.info(f"apply_client_patch: Model state after _update_model: {updated_state}")
entry.commit_patch(patch)
logger.info(f"apply_client_patch: Patch committed, new seq={entry.seq}")
# Don't broadcast back to client - they already have this change
@@ -206,7 +210,37 @@ class SyncRegistry:
await self.websocket.send_json(msg.model_dump(mode="json"))
def _update_model(self, model: BaseModel, new_data: Dict[str, Any]):
# Update model using model_validate for potentially nested models
new_model = model.__class__.model_validate(new_data)
for field in model.model_fields:
setattr(model, field, getattr(new_model, field))
# Update model fields in-place to preserve references
# This is important for dict fields that may be referenced elsewhere
for field_name, field_info in model.model_fields.items():
if field_name in new_data:
new_value = new_data[field_name]
current_value = getattr(model, field_name)
# For dict fields, update in-place instead of replacing
if isinstance(current_value, dict) and isinstance(new_value, dict):
self._deep_update_dict(current_value, new_value)
else:
# For other types, just set the new value
setattr(model, field_name, new_value)
def _deep_update_dict(self, target: dict, source: dict):
"""Deep update target dict with source dict, preserving nested dict references."""
# Remove keys that are in target but not in source
keys_to_remove = set(target.keys()) - set(source.keys())
for key in keys_to_remove:
del target[key]
# Update or add keys from source
for key, source_value in source.items():
if key in target:
target_value = target[key]
# If both are dicts, recursively update
if isinstance(target_value, dict) and isinstance(source_value, dict):
self._deep_update_dict(target_value, source_value)
else:
# Replace the value
target[key] = source_value
else:
# Add new key
target[key] = source_value