wenjin272 commented on code in PR #1002:
URL: https://github.com/apache/flink-agents/pull/1002#discussion_r3841621852


##########
python/flink_agents/runtime/memory/mem0/mem0_long_term_memory.py:
##########
@@ -429,18 +446,33 @@ def drain_ltm_observation_records(self, key: str, 
observation_id: str) -> str:
     def get_memory_set(self, name: str) -> MemorySet:
         """Get the memory set by name.
 
+        The current partition key and observation context are copied onto the 
set
+        so that operations submitted to a worker thread stay scoped to the 
action
+        that obtained it. Must be called on the mailbox thread.

Review Comment:
   **[P1] Enforce mailbox-thread access for memory-set management**
   
   I think `get_memory_set` and `delete_memory_set`, as memory-set-level 
management operations, should only run on the mailbox thread. Otherwise, 
passing either to `durable_execute_async` can preserve the same cross-key race. 
Could we enforce this in both Java and Python, similar to 
`RunnerContextImpl#getResource`?



##########
python/flink_agents/runtime/memory/mem0/mem0_long_term_memory.py:
##########
@@ -123,6 +123,23 @@ def validate_config(cls, v: Any, values: Any) -> Any:
     return _FlinkAgentsLlmConfig, _FlinkAgentsEmbedderConfig
 
 
+def _bound_partition_key(memory_set: MemorySet) -> str:
+    """Return the partition key the set is scoped to.
+
+    Mem0 ignores a falsy ``agent_id`` rather than matching on it, so an 
unbound set
+    would widen every operation to all keys sharing the job id and set name, 
which
+    for a delete means deleting another key's items. Refuse the operation 
instead.
+    """
+    if memory_set.partition_key is None:

Review Comment:
   **[P1] Handle empty partition keys safely**
   
   `""` is a valid Flink key, but Mem0 ignores a falsy `agent_id`, dropping 
partition isolation. Please reject empty keys or encode them into a non-empty, 
collision-free value. Also use `None`/`null`, rather than `""`, for the unbound 
state.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to