Repository navigation
Description
Problem Description
A devops gh api call printed a FileNotFoundError traceback when its working directory no longer existed. The post-merge worktree cleanup had deleted the directory. The telemetry setup calls _resolve_git_dir (src/devops_cli/telemetry/tracer.py), which starts from Path.cwd(), and Path.cwd() raises FileNotFoundError for a deleted directory. The command did not report a clean error.
Reproduction Steps
mkdir /tmp/gone && cd /tmp/gone && rmdir /tmp/goneuv run --project /workspaces/devops-cli devops gh api rate_limit
Expected vs Actual Behavior
Expected: telemetry finds no git directory and the command runs, or the command stops with one error line that says the working directory does not exist.
Actual: a FileNotFoundError traceback from _resolve_git_dir.
Environment Diagnostics
main at 2026-10-28, devcontainer.
Logs, Traces, or Terminal Output
telemetry/tracer.py in _resolve_git_dir -> Path.cwd()
FileNotFoundError: [Errno 2] No such file or directory
Proposed design
Problem statement
A devops command run from a deleted working directory crashes with an unhandled FileNotFoundError traceback. The telemetry setup calls _resolve_git_dir, which calls Path.cwd(). Path.cwd() raises FileNotFoundError when the directory no longer exists. The command does not report a clean error and does not complete.
Acceptance criteria
Requirement: Deleted CWD returns no git directory
_resolve_git_dir SHALL return None when Path.cwd() raises FileNotFoundError because the working directory no longer exists.
Scenario: CWD deleted before call
- WHEN Path.cwd() raises FileNotFoundError because the process working directory was removed
- THEN _resolve_git_dir returns None and no exception propagates to the caller
Requirement: Command completes without traceback
A devops command run from a deleted working directory SHALL complete without an unhandled FileNotFoundError traceback from the telemetry setup.
Scenario: gh api from deleted directory
- WHEN a devops gh api command runs after its working directory has been deleted
- THEN the command exits with a clean result or a single error line, not a traceback
Requirement: Normal resolution unaffected
_resolve_git_dir SHALL return the correct git directory when the working directory exists and contains a .git entry.
Scenario: CWD inside a git repository
- WHEN the process working directory exists and is inside a git repository
- THEN _resolve_git_dir returns the path to the .git directory as before
Existing Tool Considered
No external tool or library covers this need. The fix is a try/except OSError around the Path.cwd() call in _resolve_git_dir (src/devops_cli/telemetry/tracer.py:628). The written cost is one try/except block of about 4 lines, one test case, and the maintenance of that guard for the lifetime of the function.
Key questions
- Where in the call chain should the FileNotFoundError from Path.cwd() be caught?: In _resolve_git_dir itself, at the Path.cwd() call site. This is the origin of the exception, and the function already returns None when no git directory is found, so returning None on a deleted CWD is consistent with its contract. Catching it in _detect_vcs_metadata would leave _resolve_git_dir vulnerable for any other caller. (best practice) [sources: src/devops_cli/telemetry/tracer.py:628, src/devops_cli/telemetry/tracer.py:646]
- Chosen: Catch in _resolve_git_dir at the Path.cwd() call. Most targeted fix. Protects all callers. Matches the function's existing None-return contract for the not-found case.
- Rejected: Catch in _detect_vcs_metadata. Leaves _resolve_git_dir vulnerable for other callers. The exception would still propagate if any other code calls _resolve_git_dir directly.
- Rejected: Catch in the CLI entry point. Too broad. Hides the specific cause and makes the telemetry path less testable in isolation.
- Which exception type should the handler catch?: OSError. FileNotFoundError is a subclass of OSError. Path.cwd() can raise OSError for reasons other than a missing directory (for example, a permission error on the underlying getcwd syscall). The existing code in this file already catches OSError in _resolve_git_dir_from_file and _read_packed_refs, so OSError is the established pattern. (best practice) [sources: src/devops_cli/telemetry/tracer.py:618, src/devops_cli/telemetry/tracer.py:596]
- Chosen: Catch OSError. Covers FileNotFoundError and any other OS-level failure from getcwd. Matches the existing pattern in this file.
- Rejected: Catch FileNotFoundError only. Narrower than needed. A permission error on getcwd would still crash the command.
- What value should _resolve_git_dir return when the CWD is unavailable?: None. The function's signature is Path | None, and it already returns None when no .git entry is found in the directory tree. A deleted CWD is another case of 'no git directory found', so None is the correct and consistent return. (best practice) [sources: src/devops_cli/telemetry/tracer.py:628]
- Chosen: Return None. Matches the existing not-found contract. The caller _detect_vcs_metadata already handles None by returning an empty dict.
- Rejected: Raise a custom exception. Adds a new exception type for a case that is semantically identical to 'no git directory found'. Unnecessary complexity.
- Does _normalize_code_filepath need the same guard?: No. It already wraps its body in try/except Exception and returns the original filepath on any failure. A FileNotFoundError from Path.cwd() inside that function is already caught. [sources: src/devops_cli/telemetry/tracer.py:700]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Oct 28, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
The command crashes with an unhandled FileNotFoundError traceback instead of reporting a clean error.The crash is real but only occurs in the rare case of a deleted working directory.Most users will not run a command from a directory that no longer exists.The fix is to catch the FileNotFoundError from Path.cwd() in one function and return a clean result.Both items handle cwd-related failures in devops commands, but #1010 fixes relative path resolution in project commands while the candidate fixes an unhandled Path.cwd() exception in telemetry/tracer.py.devops-cli-service commentedon Oct 29, 2026
Status set to Ready at 0f7bc26 (see proposed design in issue body).
devops-cli-service commentedon Nov 1, 2026
Staged: branch
fix/2531-a-devops-command-run-from-a, draft pull request #2995. The pull request plans the item and closes no issue.The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:
These paths of the plan are no file on the default branch, and no group creates them:
tests/test_tracer.py. A person checks that the plan names them right.27 remaining items
devops-cli-service commentedon Nov 1, 2026
The runner Job devops-cli-runner-20261101-230849-2b22 ended: succeeded.
Image digest: sha256:b949bd8406a0bfcfb30e4f62b707fbdba2709666e80c3d6b6f57d6dd9a11e53f
The last lines of its log:
devops-cli-service commentedon Nov 1, 2026
Cleared the stop at fix by the rule
digest: the runner image changed since the stop, from sha256:b949bd8406a0bfcfb30e4f62b707fbdba2709666e80c3d6b6f57d6dd9a11e53f to sha256:f206af606614022263cb3e3e36711137492f1954c806edd078e8193eb82a254c. The item is Planned again, and the Service takes it in the next round. The Service clears a stop one time for each runner image. A new stop on this image waits for a commentimplement: retry.fix(cli): report a removed working directory in the exit seam (#2531)
docs(openspec): archive the change (#2531)
fix(cli): stop a command group in a removed directory (#2531)
docs(openspec): archive the change (#2531)
fix(cli): check the working directory in a dry run of a group (#2531)
docs(openspec): archive the change (#2531)