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

Abierto
#1,800 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
php
Área
devtools

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Sin datos de lenguaje
Estrellas
125
Forks
1
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de beyondcode/herd-community

Todos los issues de beyondcode/herd-community

Issues similares

Más issues de DevTools

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.