Skip to content

[bugfix] agent: keep one live turn per project across processes (#658) - #694

Open
Birfy wants to merge 1 commit into
ThinkFlowLab:mainfrom
Birfy:fix/658-cross-process-turn-mutex
Open

Birfy wants to merge 1 commit into
ThinkFlowLab:mainfrom
Birfy:fix/658-cross-process-turn-mutex

Conversation

@Birfy

@Birfy Birfy commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #658

Summary

The in-process admission lock could not stop two backends that share a projects directory from starting overlapping turns. This change records the live agent session in catalog.sqlite3, refuses a second start with the existing 409, and expires or releases the row so a crash does not block the project. A queued successor may replace its predecessor in the same transaction so single-instance queue behavior stays the same.

Changes

  • Persist live-turn exclusivity in the shared catalog instead of relying on an in-process lock alone
  • Keep the existing 409 response when another live turn already holds the project
  • Allow an expired lease to release after a crash
  • Let a queued successor take over the lease in one transaction

Test plan

  • Overlapping-start regression failed on unmodified main, then passed after the fix
  • tests/test_agent_turn_mutex.py plus conversations/queue/trace related coverage: 94 passed
  • CI Release checks

Suggested labels: type:bug, area:agent (this account cannot add labels).

…kFlowLab#658)

The in-process admission lock could not stop two backends that share a
projects directory from starting overlapping turns. Record the live
agent session in catalog.sqlite3, refuse a second start with the same
409, and expire or release the row so a crash does not block the
project. A queued successor may replace its predecessor in the same
transaction so single-instance queue behavior stays the same.

@david6666666 david6666666 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非表决 COMMENT · 175355a · Fixes #658

技术结论:暂不建议合入。68/100(范围 3、正确性 2、验证 1、主张证据 2、简洁度 3;各满分 3)。把准入放进共享 SQLite transaction 是对的;在租约有效时,两实例不会同时领到项目。但仅拦开始不够,失去租约的旧 turn 还能继续执行、写回,和接手者重叠。建议把当前 lease 的身份校验带到收尾,并在失去所有权时停止旧 turn。

作者报告 94 项局部测试;我核对了源码与 exact-head Release logs,未重跑。这版单独缺 Python 分片登记,跨实例用例没有被对应工作流选到。

English recap: Shared admission is useful, but lease loss must stop or fence the old turn. The new test module is also missing from the shard manifest.

Dot,代表 @david6666666 作非表决审查。

process cannot take the slot in between.
"""
now = time.time()
existing = self.active_agent_session(db, project_id, now=now)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

旧 turn 续租失败后,现在只是结束 renewal task;运行本身和 conversations.update(finish=...) 不校验当前 lease。这时这里能把已经过期的项目交给新 turn,旧 turn 恢复后仍能写回。建议失去租约时终止旧执行,并在提交结果时核对同一 lease;补一个所有权已交接、旧 turn 的完成被拒的回归。

return root + '/assistant'


def test_two_apps_sharing_a_repository_cannot_run_overlapping_turns(tmp_path, monkeypatch):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个用例对跨实例行为很关键,但目前整个文件没有登记到 Python shard manifest,同版 CI 在文件对账处失败。请把它加到合适分片,再确认 CI 实际收集并运行这里的回归。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] agent: 同一工程可被两个后端实例同时起一轮(互斥只在进程内)

2 participants