Skip to content

fix(agentmain): use pid+nanos for long-prompt temp filename#666

Open
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:fix/issue-665-agentmain-prompt-filename-race
Open

fix(agentmain): use pid+nanos for long-prompt temp filename#666
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:fix/issue-665-agentmain-prompt-filename-race

Conversation

@Kailigithub

Copy link
Copy Markdown
Contributor

修复

agentmain.py:148 临时文件名使用秒级时间戳 int(time.time()),在并发 --func / run_subagents 同一秒内会撞名 → 进程 A 写到 user_prompt_1720xxx.md 后被进程 B 覆盖;后续 file_read 读到的是别人任务的 prompt,产出串内容。

改动

1 行:int(time.time())os.getpid() + time.time_ns(),与项目内 code_run(用 tempfile.NamedTemporaryFile)、ga_ultraplan.py _subagent(用全局递增序号)的一致性补齐。

- task_file = os.path.join(script_dir, 'temp', f'user_prompt_{int(time.time())}.md')
+ task_file = os.path.join(script_dir, 'temp', f'user_prompt_{os.getpid()}_{time.time_ns()}.md')

验证

/tmp/test_issue_665.py (8 threads × 50 attempts in 1s):

行为 唯一路径 撞名
OLD (秒级时间戳) 1 / 50 49
NEW (pid+nanos) 50 / 50 0
NEW (8 进程) 30 / 30 0

线程池场景下,新方案 50/50 全唯一;旧方案 49/50 撞名。ProcessPool 也 30/30 唯一,覆盖 run_subagents 多子进程场景。

Closes #665

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.

Race condition: user_prompt_{int(time.time())}.md temp file collides under concurrent --func / run_subagents

1 participant