def metadata_batch(self, state: State):
        """Context manager to ensure batched metadata is always written to the `State`."""
        try:
            yield
        finally:
            self.write_metadata(state)
Context manager to ensure batched metadata is always written to the `State`.
openhands/memory/condenser/condenser.py