disable bubus WAL for now

This commit is contained in:
Nick Sweeting
2025-07-18 12:49:35 -07:00
parent 64f0e22176
commit d2dbe538c9
3 changed files with 87 additions and 87 deletions

View File

@@ -439,8 +439,8 @@ class Agent(Generic[Context, AgentStructuredOutput]):
# Event bus with WAL persistence
# Default to ~/.config/browseruse/events/{agent_session_id}.jsonl
wal_path = CONFIG.BROWSER_USE_CONFIG_DIR / 'events' / f'{self.session_id}.jsonl'
self.eventbus = EventBus(name=f'Agent_{str(self.id)[-4:]}', wal_path=wal_path)
# wal_path = CONFIG.BROWSER_USE_CONFIG_DIR / 'events' / f'{self.session_id}.jsonl'
self.eventbus = EventBus(name=f'Agent_{str(self.id)[-4:]}')
# Cloud sync service
self.enable_cloud_sync = CONFIG.BROWSER_USE_CLOUD_SYNC

View File

@@ -132,7 +132,7 @@ class CloudSync:
await self._resend_pending_events()
# Update WAL events with real user_id
await self._update_wal_user_ids(agent_session_id)
# await self._update_wal_user_ids(agent_session_id)
except Exception as e:
logger.debug(f'Cloud sync authentication failed: {e}')
@@ -151,39 +151,39 @@ class CloudSync:
self.pending_events.clear()
async def _update_wal_user_ids(self, session_id: str) -> None:
"""Update user IDs in WAL file after authentication"""
try:
assert self.auth_client, 'Cloud sync must be authenticated to update WAL user ID'
# async def _update_wal_user_ids(self, session_id: str) -> None:
# """Update user IDs in WAL file after authentication"""
# try:
# assert self.auth_client, 'Cloud sync must be authenticated to update WAL user ID'
wal_path = CONFIG.BROWSER_USE_CONFIG_DIR / 'events' / f'{session_id}.jsonl'
if not await anyio.Path(wal_path).exists():
raise FileNotFoundError(
f'CloudSync failed to update saved event user_ids after auth: Agent EventBus WAL file not found: {wal_path}'
)
# wal_path = CONFIG.BROWSER_USE_CONFIG_DIR / 'events' / f'{session_id}.jsonl'
# if not await anyio.Path(wal_path).exists():
# raise FileNotFoundError(
# f'CloudSync failed to update saved event user_ids after auth: Agent EventBus WAL file not found: {wal_path}'
# )
# Read all events
events = []
content = await anyio.Path(wal_path).read_text()
for line in content.splitlines():
if line.strip():
events.append(json.loads(line))
# # Read all events
# events = []
# content = await anyio.Path(wal_path).read_text()
# for line in content.splitlines():
# if line.strip():
# events.append(json.loads(line))
# Update user_id and device_id
user_id = self.auth_client.user_id
device_id = self.auth_client.device_id
for event in events:
if 'user_id' in event:
event['user_id'] = user_id
# Add device_id to all events
event['device_id'] = device_id
# # Update user_id and device_id
# user_id = self.auth_client.user_id
# device_id = self.auth_client.device_id
# for event in events:
# if 'user_id' in event:
# event['user_id'] = user_id
# # Add device_id to all events
# event['device_id'] = device_id
# Write back
updated_content = '\n'.join(json.dumps(event) for event in events) + '\n'
await anyio.Path(wal_path).write_text(updated_content)
# # Write back
# updated_content = '\n'.join(json.dumps(event) for event in events) + '\n'
# await anyio.Path(wal_path).write_text(updated_content)
except Exception as e:
logger.warning(f'Failed to update WAL user IDs: {e}')
# except Exception as e:
# logger.warning(f'Failed to update WAL user IDs: {e}')
async def wait_for_auth(self) -> None:
"""Wait for authentication to complete if in progress"""

View File

@@ -544,71 +544,71 @@ class TestCloudSync:
# Should handle error gracefully without crashing
async def test_update_wal_events(self, temp_config_dir):
"""Test updating WAL events with real user ID."""
# Create real auth client
auth = DeviceAuthClient(base_url='http://localhost:8000')
auth.auth_config.api_token = 'test-api-key'
auth.auth_config.user_id = 'test-user-123'
# async def test_update_wal_events(self, temp_config_dir):
# """Test updating WAL events with real user ID."""
# # Create real auth client
# auth = DeviceAuthClient(base_url='http://localhost:8000')
# auth.auth_config.api_token = 'test-api-key'
# auth.auth_config.user_id = 'test-user-123'
service = CloudSync(
base_url='http://localhost:8000',
enable_auth=True,
)
service.auth_client = auth
service.session_id = 'test-session-id'
# service = CloudSync(
# base_url='http://localhost:8000',
# enable_auth=True,
# )
# service.auth_client = auth
# service.session_id = 'test-session-id'
# Create the events directory structure that the method expects
events_dir = temp_config_dir / 'events'
events_dir.mkdir(exist_ok=True)
# # Create the events directory structure that the method expects
# events_dir = temp_config_dir / 'events'
# events_dir.mkdir(exist_ok=True)
# Create WAL file with temp user IDs
wal_path = events_dir / f'{service.session_id}.jsonl'
events = [
{
'event_type': 'CreateAgentTaskEvent',
'user_id': '99999999-9999-9999-9999-999999999999', # TEMP_USER_ID
'task': 'Task 1',
},
{
'event_type': 'UpdateAgentTaskEvent',
'user_id': '99999999-9999-9999-9999-999999999999', # TEMP_USER_ID
'status': 'done',
},
{
'event_type': 'CreateAgentStepEvent',
'user_id': 'some-other-user', # Different user, should still be updated
'step': 1,
},
]
# # Create WAL file with temp user IDs
# wal_path = events_dir / f'{service.session_id}.jsonl'
# events = [
# {
# 'event_type': 'CreateAgentTaskEvent',
# 'user_id': '99999999-9999-9999-9999-999999999999', # TEMP_USER_ID
# 'task': 'Task 1',
# },
# {
# 'event_type': 'UpdateAgentTaskEvent',
# 'user_id': '99999999-9999-9999-9999-999999999999', # TEMP_USER_ID
# 'status': 'done',
# },
# {
# 'event_type': 'CreateAgentStepEvent',
# 'user_id': 'some-other-user', # Different user, should still be updated
# 'step': 1,
# },
# ]
# Write events to WAL file
content = '\n'.join(json.dumps(event) for event in events) + '\n'
await anyio.Path(wal_path).write_text(content)
# # Write events to WAL file
# content = '\n'.join(json.dumps(event) for event in events) + '\n'
# await anyio.Path(wal_path).write_text(content)
# Call the method under test (temp_config_dir fixture already sets the env var)
await service._update_wal_user_ids(service.session_id)
# # Call the method under test (temp_config_dir fixture already sets the env var)
# await service._update_wal_user_ids(service.session_id)
# Read back the updated file and verify changes
content = await anyio.Path(wal_path).read_text()
# # Read back the updated file and verify changes
# content = await anyio.Path(wal_path).read_text()
updated_events = []
for line in content.splitlines():
if line.strip():
updated_events.append(json.loads(line))
# updated_events = []
# for line in content.splitlines():
# if line.strip():
# updated_events.append(json.loads(line))
# Verify all user_ids were updated to the authenticated user's ID
assert len(updated_events) == 3
for event in updated_events:
assert event['user_id'] == 'test-user-123'
# # Verify all user_ids were updated to the authenticated user's ID
# assert len(updated_events) == 3
# for event in updated_events:
# assert event['user_id'] == 'test-user-123'
# Verify other fields remained unchanged
assert updated_events[0]['event_type'] == 'CreateAgentTaskEvent'
assert updated_events[0]['task'] == 'Task 1'
assert updated_events[1]['event_type'] == 'UpdateAgentTaskEvent'
assert updated_events[1]['status'] == 'done'
assert updated_events[2]['event_type'] == 'CreateAgentStepEvent'
assert updated_events[2]['step'] == 1
# # Verify other fields remained unchanged
# assert updated_events[0]['event_type'] == 'CreateAgentTaskEvent'
# assert updated_events[0]['task'] == 'Task 1'
# assert updated_events[1]['event_type'] == 'UpdateAgentTaskEvent'
# assert updated_events[1]['status'] == 'done'
# assert updated_events[2]['event_type'] == 'CreateAgentStepEvent'
# assert updated_events[2]['step'] == 1
class TestIntegration: