[Bug]: Dev servers start on page loads with Developer Tools turned off

クローズ
#1,800 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
php
領域
devtools

調査の方向性

Start with the shutdown function in server.php, which rewrites herd.json to store lastSite under a lock, and with HerdConfiguration::loadConfigFile(), which reads the same file without one. Run the race.php script from the report against herd.json to reproduce the empty reads. Done means a concurrent reader can never see an empty file and treat aiAssistant as enabled. The fix needs maintainer agreement on the locking approach.

索引モデルが issue の本文から書いたものです。

説明

fixed-in-next-release macOS
Platform

macOS

Operating system version

macOS Sequoia 15.6.1 (24G90)

System architecture

ARM64 (M1, M2, etc)

Herd Version

2.0.3 (Build: 72)

PHP Version

No response

Bug description

With "Enable Herd Developer Tools" off (aiAssistant.enabled: false in herd.json), Herd still occasionally starts npm run dev for a site I'm browsing, under herd-devtools-helper, and leaves a public/hot behind.

I traced it to a race on herd.json. The shutdown function in server.php rewrites the file on every request to store lastSite, locking it, truncating it and then writing it. But HerdConfiguration::loadConfigFile() reads it with a plain file_get_contents() and no lock. A request that reads it between the truncate and the write gets an empty string, fill() ends up with no aiAssistant key, and since a missing enabled defaults to true, aiAssistantEnabled() returns true. LaravelValetDriver::ensureViteDevServer() then calls /ai/dev-ensure and the dev server boots.

So any site that gets concurrent requests (a page and its XHRs, an Inertia app polling etc.) hits it eventually.

Steps to reproduce
  1. Save this as race.php, it reads herd.json the same way HerdConfiguration does:
<?php

$until = microtime(true) + 15;
$reads = $empty = 0;

while (microtime(true) < $until) {
    $reads++;
    if (file_get_contents($argv[1]) === '') {
        $empty++;
    }
}

echo "$empty empty reads out of $reads\n";
  1. Run it while firing concurrent requests at any Laravel site (POSTs, so nothing actually boots):
php race.php ~/Library/Application\ Support/Herd/config/herd.json &
seq 400 | xargs -P 12 -I{} curl -s -k -o /dev/null -X POST https://example.test/

I get 72 empty reads out of ~520k. Each of those would read as AI assistant enabled.

Relevant log output

When it happens the unified log shows:

[HerdDevtools] vite.start skipped for lido: queued until the worktree resolves
[HerdDevtools] ensureRepo path=/Users/jack/Projects/lido nonGit=false
[HerdDevtools] worktree.create useRepoPath=true repoId=49101c7f
[HerdDevtools] worktree.created repoId=49101c7f id=e82bb067 branch=main

And /var/tmp/herd-dev-ensure-<md5 of site> is touched in the same second.

主要言語
言語のデータがありません
スター
125
フォーク
1
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

beyondcode/herd-community のほかの issue

beyondcode/herd-community の issue をすべて見る

似ている issue

DevTools の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。