← Back to Pull requests

fix(config): give each git worktree its own namespace for subdirectory configs #1168

Closed
unknown closed this pull request without merging on Nov 30, 2026 00:30 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 21:41 UTC
Author

Linked git worktrees of one repository now get separate namespaces even when pitchfork.toml lives in a subdirectory or the worktree's directory name contains --. No per-worktree file is needed. Reported in https://github.com/jdx/pitchfork/discussions/1167.

Config in a subdirectory of a worktree

Before, every worktree's app/pitchfork.toml derived the namespace app from its own directory. So pitchfork start api in a second worktree said app/api was already running, and pitchfork stop api stopped the other worktree's daemon.

A derived namespace for a project in a subdirectory of a linked git worktree is now prefixed with the worktree's directory name. This includes worktrees of a bare repository or a --separate-git-dir clone:

| Config | Namespace |
|--------|-----------|
| ~/demo/app/pitchfork.toml (main checkout) | app (unchanged) |
| ~/feature-a/app/pitchfork.toml (linked worktree) | feature-a-app |
| ~/feature-a/pitchfork.toml (worktree root) | feature-a (unchanged) |

$ cd ~/feature-a/app && pitchfork start api
✔ pitchfork: [feature-a-app/api] started
$ cd ~/feature-b/app && pitchfork start api
✔ pitchfork: [feature-b-app/api] started
$ pitchfork stop api
pitchfork Stopped daemon feature-b-app/api

An explicit namespace = "..." and a pitchfork config add namespace registration still take precedence. The proxy and web UI read namespaces the same way, so they pick this up as well.

Invalid directory names are sanitized

Before, a worktree directory such as review--1234 made the config fail to load with invalid namespace 'review--1234' ... contains reserved sequence '--'. A derived name that is not a valid namespace is now sanitized: spaces and other ASCII punctuation become -, runs of - or . collapse, and leading or trailing - are trimmed. So review--1234 becomes review-1234. Names that are already valid are unchanged. Directory names with non-ASCII characters still need an explicit namespace, because sanitizing them would drop most of the name. An invalid explicit namespace is still rejected and is never rewritten.

Compatibility

A daemon already running from a subdirectory of a linked worktree stays registered under its old ID (for example app/api). After upgrading, the same short name in that worktree resolves to the new ID (feature-a-app/api). Stop the old daemon by its qualified ID. Only git worktrees are detected; jj workspaces are not.

Validation

  • New unit test: a primary checkout and two linked worktrees (one named review--1234), each with app/pitchfork.toml. It covers derived namespaces at the checkout root and in subdirectories, worktrees of a bare repository, submodules (not treated as worktrees), and explicit-namespace precedence. I also checked a real bare-repository worktree pair by hand.

  • Updated integration tests for sanitized and rejected names.

  • Ran the reproduction from the discussion with a dev build and an isolated supervisor; the output above is from that run. mise run ci-dev passes.
  • AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: 2.1.332.

    🤖 Generated with Claude Code

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Changes how qualified daemon IDs are derived for worktree subdirectories and renamed worktree folders, which can leave old daemons registered under previous IDs until stopped by qualified name.

    > Overview

    Namespace derivation no longer uses only the project directory name. Config under a subdirectory of a linked git worktree gets a namespace prefixed with that worktree’s directory name (e.g. feature-a-app instead of shared app), via new linked_worktree_root detection on the .git file and worktree admin commondir.

    > ASCII directory names that would fail namespace rules are sanitized when derived (spaces/punctuation → -, collapsed --, trimmed edges), so names like review--1234 become review-1234 instead of a load error. Non-ASCII directory names still fail unless you set an explicit namespace; explicit namespace values are validated as before, not rewritten.

    > Documentation in docs/concepts/namespaces.md describes worktree subdir behavior and sanitization. Unit and integration tests cover worktrees (bare repo, relative gitdir, submodules, separate-git-dir), sanitization, and explicit namespace precedence.

    > <sup>Reviewed by Cursor Bugbot for commit cb689da5d50174feab9f60b60736044f451bc87c. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

  • New Features

  • - Project namespaces in linked worktrees now include the worktree directory name when the project config is in a repository subdirectory. Worktree roots and primary-checkout directories retain directory-based names.
    - Derived ASCII names replace unsupported characters with hyphens, collapse repeated hyphens or periods, and trim edge hyphens.
  • Bug Fixes

  • - Non-ASCII directory names still require an explicit namespace, and explicitly configured namespaces must meet naming rules.
  • Documentation

  • - Added examples showing namespace names in a main checkout and linked worktrees.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jdx Review duration: 168m
    All Vouch review confidence checks passed
    Residual risk 0.32 = Change Risk (0.75) × (1 − Review Confidence (0.58)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    57%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #1168"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 58.0% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 58.0% · Lower = rushed or shallow review
    58.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 31.6% · Safe to merge
    31.6%
    Repository