ADR icon indicating copy to clipboard operation
ADR copied to clipboard

[Discovery] Linux: the root user's home (/root) is never swept — home discovery treats every HOME_ROOT as a parent-of-homes, and the miss is not reported as a coverage gap

Open SOCTeam-ai opened this issue 2 months ago • 0 comments

Summary

On Linux, Discovery/ never enumerates the root user's home directory /root, even though LinuxProviders explicitly declares it as a home root. Because /home almost always contains at least one real user directory, the $HOME fallback in homes() never fires, and /root is silently dropped.

The result is a silent false negative in a tool whose central design claim is that absence is a coverage fact — /root appears neither in roots_swept nor in unavailable / truncated / boundaries_hit. The endpoint is reported as swept while a whole home directory went unread.

Environment

  • uber/ADR @ 9117d8a79c61861599e1d4deffdfb244584bfcb1 (2026-09-28, current main)
  • adr-discovery 0.2.0, Python 3.12, Linux x86_64
  • run as root; getent passwd root → root:x:0:0:root:/root:/bin/bash

Root cause

homes() assumes that every entry of home_roots() is a directory containing home directories:

# Discovery/adr_discovery/enumerator/roots.py:46
def homes(gate) -> tuple[str, ...]:
    found: list[str] = []
    for base in gate.providers.home_roots():
        listing = gate.list_dir(base)
        if not listing.ok:
            continue
        for entry in listing.value:
            if entry.is_dir and not entry.path.rsplit("/", 1)[-1].startswith("."):
                found.append(entry.path)          # <-- treats children of base as homes
    if not found:
        home = gate.env.get("HOME")               # <-- only reached when nothing was found
        if home:
            found.append(home)
    return tuple(found)

That is correct for /home (/home/alice, /home/bob) but wrong for /root, which is a home directory rather than a container of them:

# Discovery/adr_discovery/world/platform/linux.py:14
HOME_ROOTS = ("/home", "/root")

Listing /root yields its children — /root/java, or nothing at all if there is no non-hidden child — so /root itself never enters found. And because a real machine's /home normally contains at least one user directory, found is non-empty and the if not found: fallback (which would have produced $HOME=/root) is dead code on precisely the hosts where it is needed.

homes() is the single source of home directories for the whole enumerator:

# Discovery/adr_discovery/enumerator/__init__.py:39
found.extend(from_app_state(gate, homes(gate)))
found.extend(from_binaries(gate, homes(gate)))
found.extend(from_model_stores(gate, homes(gate)))

so every ~-templated surface is skipped for the root user — CONFIG_FILE_TEMPLATES (~/.claude.json, ~/.claude/settings.json, ~/.cursor/mcp.json, ~/.codex/config.toml, ~/.config/opencode/opencode.json, …), STATE_ROOTS (~/.ollama, ~/.claude, ~/.cursor, …), EDITOR_EXTENSION_ROOTS (~/.vscode/extensions), BROWSER_PROFILE_ROOTS, FIREFOX_PROFILE_ROOTS, and root's PATH binaries. ordered_roots() derives the sweep roots from the same tuple, which is why /root is never swept and a bogus entry like /root/java shows up in roots_swept instead.

Same class of issue on macOS: DarwinProviders.HOME_ROOTS = ("/Users",) (platform/darwin.py:21) misses /var/root. That one is code reading only — I had no macOS host to confirm the live behaviour.

Minimal reproduction

Prerequisites: a host where /home contains at least one real user directory — that is exactly the condition that suppresses the $HOME fallback — plus root privileges to write under /root. Replace /home/user with any existing non-root home on the machine. (On a minimal container where /home is empty the bug does not reproduce, because the fallback then fires and /root is found; this is also why it survives the test suite.)

git clone --depth 1 https://github.com/uber/ADR && cd ADR/Discovery

# control: a home discovered through /home
mkdir -p /home/user/.claude
echo '{"mcpServers":{"control-mcp":{"command":"npx","args":["-y","@modelcontextprotocol/server-everything"]}}}' \
  > /home/user/.claude/settings.json

# subject: the real root home
mkdir -p /root/.claude
echo '{"mcpServers":{"subject-mcp":{"command":"npx","args":["-y","@modelcontextprotocol/server-everything"]}}}' \
  > /root/.claude/settings.json

uv run adr-discovery --json | jq '{assets: [.assets[] | {kind, name: (.catalog_id // .name), path: .evidence[0].path}], roots: [.coverage.roots_swept[].path]}'

Observed

assets:
  [mcp_server] control-mcp   <- /home/user/.claude/settings.json   ✅ detected
  (subject-mcp from /root/.claude/settings.json)                   ❌ absent

coverage.roots_swept (root/home):
  /home/user   513
  /root/java    33      <-- not a home; it is a child of one
  ...

/root itself appears nowhere in coverage:

  • not in roots_swept (only /root/java and its ~/<code-root> expansions are)
  • not in unavailable (["dns_cache", "exec_journal"])
  • not in truncated ([])
  • not in boundaries_hit

So the snapshot reports a clean endpoint with no stated gap, while an entire home directory — one that commonly holds agent state on CI runners, containers and dev VMs, which frequently run as root — was never read.

Corroborating evidence: fixture mode detects the same file that live mode misses

mkdir -p /tmp/fx/root/.claude
echo '{"mcpServers":{"fixture-mcp":{"command":"npx","args":["-y","x"]}}}' > /tmp/fx/root/.claude/settings.json

HOME=/root uv run adr-discovery --root /tmp/fx --json   # -> fixture-mcp DETECTED at /root/.claude/settings.json
uv run adr-discovery --json                             # -> the live /root/.claude/settings.json is MISSED

Reason: with --root != "/", providers=None (cli.py:92), so NullProviders.HOME_ROOTS = ("/Users", "/home") is used; neither exists under the fixture, found == (), and the $HOME fallback produces /root. Live, LinuxProviders takes over and /home/user keeps found non-empty, so the fallback never runs.

Why the test suite is green anyway

The harness is written on the assumption that /root is a home — the very assumption the platform provider violates:

  • Discovery/tests/tools/synthesize.py:30 → HOME = "/root"
  • Discovery/tests/scoring/match.py:55,76 and scoring/score.py:91 → home: str = "/root" default

Because the fixtures reach home through the $HOME fallback (or through --root-relative paths), the bug is invisible to the suite and only appears against a live host.

Impact

On the machine used for this report, /root holds 61 hidden directories, including state for .claude, .cursor, .codeium, .continue, .aider-desk, .agents, .copilot, .qwen, .kilocode, .kiro, .junie, .iflow, .lingma, .mcpjam, .kode, and more. All of it is invisible to the inventory, and none of it is reported as an unread surface — which defeats the module's stated contract that a gap must surface in coverage rather than make the machine look clean.

Suggested fix

Stop inferring homes from a parent-directory listing. Home directories are a passwd-database fact, not a convention:

import pwd

def homes(gate) -> tuple[str, ...]:
    found = [p.pw_dir for p in pwd.getpwall() if p.pw_dir and os.path.isdir(p.pw_dir)]
    if not found:                      # keep the existing fallback for odd hosts
        home = gate.env.get("HOME")
        if home:
            found.append(home)
    return tuple(dict.fromkeys(found))

If reading passwd is not acceptable on some platform, the minimal fix is to recognise a HOME_ROOT that is itself a home:

for base in gate.providers.home_roots():
    # `/root` is a home, not a container of homes
    if base not in ("/",) and _is_home_shaped(gate, base):
        found.append(base)
        continue
    ...existing listing...

The passwd-based version also fixes non-standard layouts (/var/root on macOS, /export/home/* on Solaris derivatives) and removes the need to guess which roots are containers.

Whatever the fix, /root (or any home that could not be read) should appear in coverage as a boundary so that a skipped home is visible rather than silent.

Checklist

  • [x] Reproduced on current main (9117d8a)
  • [x] Minimal reproduction provided
  • [x] Root cause identified with file:line
  • [x] Searched existing issues — no duplicate found (#21, #28, #30, #118, #125, #133 are unrelated)

SOCTeam-ai avatar Sep 29 '26 12:09 SOCTeam-ai