fix: prevent agents from killing production dashboard on port 4040

An AI review agent (FN-1506) killed the running dashboard by finding
the process on port 4040 via lsof and running kill -9, causing exit
code 137 (SIGKILL) with no logs. This adds multi-layer guardrails:

- AGENTS.md: project-level rule reserving port 4040
- Executor/reviewer system prompts: explicit prohibition on killing
  port 4040 processes, with instruction to use --port 0 instead
- Core agent-prompts.ts: same guardrails in all prompt variants
- Reviewer told to issue REVISE if executor violates the rule
- SIGHUP handlers in dashboard.ts and serve.ts for resilience
- Background engine reconciliation in dashboard/serve startup

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-13 18:00:49 -07:00
parent 9a028b6573
commit 564659fcbe
6 changed files with 64 additions and 2 deletions

View File

@@ -115,6 +115,7 @@ You are running in an **isolated git worktree**. This means:
If you attempt to write to a path outside the worktree, the file tools will reject the operation with an error explaining the boundary.
## Guardrails
- **NEVER kill processes on port 4040.** Port 4040 is the production dashboard. Do not run \`kill\`, \`pkill\`, \`killall\`, or \`lsof -ti:4040 | xargs kill\` against it. If you need to start a test server, use \`--port 0\` for a random free port. If port 4040 is occupied, pick a different port — do NOT kill the occupant.
- Treat the File Scope in PROMPT.md as the expected starting scope, not a hard boundary when quality gates fail
- Read "Context to Read First" files before starting
- Follow the "Do NOT" section strictly
@@ -400,7 +401,10 @@ access to the codebase and can run commands to inspect code.
### Suggestions
- [Optional improvements, not blocking]
\`\`\``;
\`\`\`
## Safety Rules
- **NEVER kill processes on port 4040.** Port 4040 is the production dashboard. If you need to test server endpoints, start a server on a different port (\`--port 0\` for random). If port 4040 is occupied, use a different port — do NOT kill the occupant. Issue REVISE if the executor kills or attempts to kill processes on port 4040.`;
/**
* Base merger prompt text (without commit format instructions, which are
@@ -522,6 +526,7 @@ You are running in an **isolated git worktree**. This means:
If you attempt to write to a path outside the worktree, the file tools will reject the operation with an error explaining the boundary.
## Guardrails
- **NEVER kill processes on port 4040.** Port 4040 is the production dashboard. Do not run \`kill\`, \`pkill\`, \`killall\`, or \`lsof -ti:4040 | xargs kill\` against it. If you need to start a test server, use \`--port 0\` for a random free port. If port 4040 is occupied, pick a different port — do NOT kill the occupant.
- Treat the File Scope in PROMPT.md as the expected starting scope, not a hard boundary when quality gates fail
- Read "Context to Read First" files before starting
- Follow the "Do NOT" section strictly
@@ -675,7 +680,10 @@ submissions to a high bar for correctness, security, and maintainability.
### Suggestions
- [Optional improvements, not blocking]
\`\`\``;
\`\`\`
## Safety Rules
- **NEVER kill processes on port 4040.** Port 4040 is the production dashboard. If you need to test server endpoints, start a server on a different port (\`--port 0\` for random). If port 4040 is occupied, use a different port — do NOT kill the occupant. Issue REVISE if the executor kills or attempts to kill processes on port 4040.`;
const CONCISE_TRIAGE_PROMPT_TEXT = `You are a task specification agent for "fn". Produce a concise, actionable PROMPT.md from the given task description.