Repository navigation
Keep observation watermarks advancing beyond the retrieval cap #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
rudycelekli
wants to merge
1
commit into
google-deepmind:main
from
rudycelekli:fix/observation-watermark-full-memory-20261104
+127
−4
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
concordia/components/agent/observation_watermark_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # Copyright 2026 DeepMind Technologies Limited. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Regression tests for observation memory watermarks.""" | ||
|
|
||
| from absl.testing import absltest | ||
| from concordia.agents import entity_agent | ||
| from concordia.associative_memory import basic_associative_memory | ||
| from concordia.components.agent import memory | ||
| from concordia.components.agent import observation | ||
| from concordia.typing import entity_component | ||
| import numpy as np | ||
|
|
||
|
|
||
| class _RecordingAct(entity_component.ActingComponent): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| self.contexts = [] | ||
|
|
||
| def get_action_attempt(self, contexts, action_spec): | ||
| del action_spec | ||
| self.contexts.append(contexts['observations']) | ||
| return 'waits' | ||
|
|
||
| def get_state(self): | ||
| return {} | ||
|
|
||
| def set_state(self, state): | ||
| del state | ||
|
|
||
|
|
||
| def _agent(bank, reader): | ||
| act = _RecordingAct() | ||
| agent = entity_agent.EntityAgent( | ||
| 'Alice', | ||
| act, | ||
| { | ||
| '__memory__': bank, | ||
| 'to_memory': observation.ObservationToMemory(), | ||
| 'observations': reader, | ||
| }, | ||
| ) | ||
| return agent, act | ||
|
|
||
|
|
||
| class ObservationWatermarkTest(absltest.TestCase): | ||
|
|
||
| def test_observation_after_old_retrieval_cap_is_delivered_once(self): | ||
| bank = ['non-observation filler'] * 1_000_000 | ||
| reader = observation.ObservationsSinceLastPreAct() | ||
| agent, act = _agent(memory.ListMemory(bank), reader) | ||
| agent.act() | ||
| self.assertEqual(reader.get_state()['last_seen_index'], 1_000_000) | ||
| agent.observe('Fresh observation beyond old cap') | ||
| agent.act() | ||
| self.assertIn( | ||
| '[observation] Fresh observation beyond old cap', act.contexts[-1] | ||
| ) | ||
| self.assertEqual(reader.get_state()['last_seen_index'], 1_000_001) | ||
| agent.act() | ||
| self.assertNotIn('Fresh observation beyond old cap', act.contexts[-1]) | ||
|
|
||
| def test_multiple_observations_keep_order_and_resume_without_replay(self): | ||
| bank = ['non-observation filler'] | ||
| reader = observation.ObservationsSinceLastPreAct() | ||
| agent, act = _agent(memory.ListMemory(bank), reader) | ||
| agent.act() | ||
| agent.observe('First fresh observation') | ||
| agent.observe('Second fresh observation') | ||
| agent.act() | ||
| self.assertIn( | ||
| '[observation] First fresh observation\n' | ||
| '[observation] Second fresh observation\n', | ||
| act.contexts[-1], | ||
| ) | ||
| state = reader.get_state() | ||
| restored = observation.ObservationsSinceLastPreAct() | ||
| restored.set_state(state) | ||
| resumed, resumed_act = _agent(memory.ListMemory(bank), restored) | ||
| resumed.act() | ||
| self.assertNotIn('fresh observation', resumed_act.contexts[-1]) | ||
| resumed.observe('Observation after restore') | ||
| resumed.act() | ||
| self.assertIn( | ||
| '[observation] Observation after restore', resumed_act.contexts[-1] | ||
| ) | ||
| self.assertNotIn('First fresh', resumed_act.contexts[-1]) | ||
|
|
||
| def test_associative_memory_retains_append_order_and_once_only_delivery(self): | ||
| bank = basic_associative_memory.AssociativeMemoryBank( | ||
| sentence_embedder=lambda _: np.ones(2) | ||
| ) | ||
| bank.add('non-observation filler') | ||
| reader = observation.ObservationsSinceLastPreAct() | ||
| agent, act = _agent(memory.AssociativeMemory(bank), reader) | ||
| agent.act() | ||
| agent.observe('First associative observation') | ||
| agent.observe('Second associative observation') | ||
| agent.act() | ||
| self.assertIn( | ||
| '[observation] First associative observation\n' | ||
| '[observation] Second associative observation\n', | ||
| act.contexts[-1], | ||
| ) | ||
| self.assertEqual(reader.get_state()['last_seen_index'], 3) | ||
| agent.act() | ||
| self.assertNotIn('associative observation', act.contexts[-1]) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| absltest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now materializes the entire memory history on every
pre_act, even if only one observation was appended.ListMemory.get_all_memories_as_text()copies all N strings into a tuple; the associative backend builds a full DataFrame/text list, so a long simulation becomes O(N) work/allocation per action (O(N²) over N actions). The old one-million-item cap at least bounded that cost, and this becomes unbounded exactly where the PR fixes the watermark. Could we expose an append count/cursor and fetch onlycount - last_seen_indexrecent entries, with a regression for histories beyond the previous cap?