Skip to content

[Bug] agent_sub_stages 使用 asyncio.create_task 写入导致 SQLite database is locked #8570

@jason9033

Description

@jason9033

What happened / 发生了什么

群聊环境下正常聊天bot有时会直接发送了下面这一段错误。我不太确定具体是因为Astrbot的问题还是我设备性能的问题。

Error occurred while processing agent request: (sqlite3.OperationalError) database is locked
(Background on this error at: https://sqlalche.me/e/20/e3q8)

我让bot帮我分析了一下。它说是在处理 Agent 请求时,服务端出现 SQLite 数据库被锁定的报错,导致部分 LLM 请求状态记录失败。检查代码发现在 agent_sub_stages.internal 记录 LLM 请求状态时,使用了 asyncio.create_task 将数据库写入操作放入后台并发执行。由于 SQLite 是基于文件锁的数据库,在面临高并发异步写入时容易产生锁冲突,从而抛出 database is locked 异常。

Reproduce / 如何复现?

群聊环境下正常聊天有概率出现这个问题

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

debian13 linux AstrBot Desktop v4.25.2

OS

Linux

Logs / 报错日志

Error occurred while processing agent request: (sqlite3.OperationalError) database is locked
(Background on this error at: https://sqlalche.me/e/20/e3q8)

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backendarea:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions