Lesson 056: Environment Self-Interference in AI-Assisted Development

Lesson 056: Environment Self-Interference in AI-Assisted Development

The Lesson

An AI coding assistant that launches background processes (dev servers, database connections, build watchers) will fight with its own previous instances over shared resources like ports and file locks. Explicit cleanup before each launch — kill orphan processes, release locks, verify port availability — must be part of the workflow, not an afterthought.

Context

Across 64 development sessions, port conflicts and database locks were a recurring friction source. The AI assistant would launch a dev server on port 8070, then later need to restart it (after code changes), but fail to kill the previous instance. The result: "port already in use" errors, DuckDB "file already open" errors, and cascading failures that wasted 5-10 minutes per incident. The root cause was always the same: the AI's own previous process was still running.

What Happened

  1. A typical incident: the dev server is running on port 8070. The user asks for a code change. The AI edits the file and tries to restart the server. The old process is still listening on 8070. The new process fails with "address already in use." The AI tries again. Same error. Eventually someone thinks to kill the old process.

  2. DuckDB has a single-writer constraint — only one process can open the database for writing. The web server opens it read-only, but if a CLI process (tagging, deduplication) has the database open for writing, the web server can't start. And if a previous CLI process crashed without closing the connection, the lock persists until the process is killed.

  3. The fix was straightforward but required discipline: before every server launch, check for and kill existing processes on the target port. Before every database write operation, verify no other process holds the lock. This was codified into the /push skill and into CLAUDE.md as a development server rule.

  4. The pattern repeated across projects — not just Artemis. Any project with a dev server hit the same issue. The fix was the same each time, confirming it's a systemic pattern rather than a project-specific bug.

Key Insights

Applicability

This pattern applies whenever an AI assistant manages long-running processes:

Does NOT apply when:

Related Lessons