fix: align peer_bus signature, bot presence SQL, XML-RPC timeout

- All specialist agents: handle_peer_request(request_type, params, directive_id)
  replaces handle_peer_request(request: dict) so callers pass structured args
- ab_ai_bot: force-write bus_presence.status via SQL so Odoo 18 WebSocket presence
  shows the correct colour immediately (ORM compute does not trigger on last_poll writes)
- odoo_client: wrap XML-RPC executor calls in asyncio.wait_for to enforce timeout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-19 23:02:51 -04:00
parent 93f2a101fa
commit 233f461480
9 changed files with 69 additions and 59 deletions

View File

@@ -168,22 +168,33 @@ class AbAiBot(models.Model):
try:
Presence = self.env['bus.presence']
now = fields.Datetime.now()
# bus.presence.status is a computed field — write only last_poll/last_presence.
# When online: set both 24h ahead so the bot stays "online" regardless of
# cron timing. The cron explicitly marks offline by setting them to the past.
status = 'online' if online else 'offline'
if online:
poll_time = now + timedelta(minutes=10)
presence_time = now + timedelta(minutes=10)
else:
poll_time = now - timedelta(hours=1)
presence_time = now - timedelta(hours=1)
vals = {'last_poll': poll_time, 'last_presence': presence_time}
rec = Presence.sudo().search([('user_id', '=', bot_user.id)], limit=1)
if rec:
rec.write(vals)
rec.write({'last_poll': poll_time, 'last_presence': presence_time})
# Force-update stored status column directly — Odoo 18 WebSocket-based
# presence doesn't trigger the stored compute when last_poll is written via ORM.
self.env.cr.execute(
"UPDATE bus_presence SET status = %s WHERE user_id = %s",
(status, bot_user.id),
)
rec.invalidate_recordset(['status'])
else:
vals['user_id'] = bot_user.id
Presence.sudo().create(vals)
Presence.sudo().create({
'user_id': bot_user.id,
'last_poll': poll_time,
'last_presence': presence_time,
})
self.env.cr.execute(
"UPDATE bus_presence SET status = %s WHERE user_id = %s",
(status, bot_user.id),
)
except Exception as exc:
_logger.warning('Could not update bot user presence: %s', exc)