Repository navigation
fix(agent): 退出浏览器时关闭记忆库连接,不再多等一分钟后崩溃 - #42
Merged
Merged
Conversation
LedgerBackend opens memory.sqlite through Sqlite.sys.mjs on the first agent turn (the ledger digest is read for every turn, with or without a bound workspace) and never closed it. Sqlite.sys.mjs waits in profile-before-change until every connection is closed, so after one agent turn the browser process stayed around for 60 seconds after the window was gone and then died with "AsyncShutdown timeout in profile-before-change" (memory.sqlite#0: waiting for shutdown). Register a blocker on Sqlite.shutdown when the connection is opened and close it there. After that _db() refuses to reopen: digest and mergeHandoff keep returning their "ledger unavailable" results, recall and remember report that the memory database is closed. If the blocker can no longer be registered, or shutdown starts while the tables are being created, the fresh connection is closed right away instead of being kept. Measured on the unmodified v0.27.1 arm64 package and on a copy with this module swapped in (temporary profile, headless): quit takes 61.2 s and ends with SIGSEGV before, 0.3 s with exit code 0 after; facts written before the quit are read back after a restart in both. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
背景
给#41做真实引擎验证时发现的,和#41的改动无关,在没改动的v0.27.1上就有:agent跑过一轮之后,退出浏览器时进程要再留61秒,最后以崩溃结束。
原因:
LedgerBackend用Sqlite.sys.mjs打开记忆库memory.sqlite,之后没有任何地方关闭它。每个agent回合开头都会读一次账本摘要,不管有没有绑定工作目录,所以只要跑过一轮,连接就开着。Sqlite.sys.mjs在profile-before-change阶段等所有连接关闭,等不到,60秒后AsyncShutdown超时,进程崩溃退出:也就是说窗口已经关了,进程还留着,一分钟后崩溃退出。
改动(按提交)
fix(agent)退出浏览器时关闭记忆库连接(ba142eb):Sqlite.shutdown上登记一个回调,退出时由它关闭连接(会等进行中的语句结束);recall和remember明确报“记忆库已关闭”;dev/selftest-ledger-shutdown.mjs,14项,用假的Sqlite覆盖上面几种情况。docs(54710ab):readme“main(尚未发布)”一条。验证
全量自测:
bash scripts/selftest-agent-tools.sh通过,共48步。真实引擎(v0.27.1最终arm64包的临时副本,临时profile、无头启动,经marionette操作,退出走
Services.startup.quit):和#41一起:#41的真实引擎冒烟(正常回合、脚本失败、循环停止、续跑后压缩,其中压缩那一段会往账本里写入)在只换#41的模块时26项通过,但浏览器要61.1秒后崩溃退出;再换上这个模块后26项通过,0.2秒退出,退出码0。
说明
🤖 Generated with Claude Code