Skip to content

fix(config): devops config unset stops with a TypeError for a key that a YAML merge key gives #2656

Description

@dan-petty

Problem Description

devops config unset <key> stops with a TypeError traceback when the config file gives the key through a YAML merge key (<<: *anchor). _find in src/devops_cli/config/round_trip.py finds the key in the merged mapping, because ruamel.yaml lists merged keys as keys of the mapping. It then asks for the line of the key with node.lc.key(dotted), and ruamel.yaml gives no position for a merged key.

devops config audit-keys loads the file with PyYAML, which resolves the merge, so it reports the key as a plaintext secret. Thus the audit reports a leak that devops config unset cannot remove, and the audit keeps failing. The key of the anchor mapping, such as a.b.api_key below, is the real place of the value, and the audit does not scan it because it is three levels deep.

Reproduction Steps

  1. Make a temporary HOME and a git repository in a temporary directory.
  2. Write this text to config.yaml in the repository:
    a:
      b: &d
        api_key: FAKE-2513-value
    ai:
      <<: *d
  3. Set PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring. Run devops config audit-keys in the repository. The audit reports <repo>/config.yaml:ai.api_key.
  4. Run devops config unset ai.api_key in the repository.

Expected vs Actual Behavior

Expected: the command exits 1 with a message that names the file and says that the key comes from a merge key. Or it removes the value from the mapping that holds it. It prints no traceback.

Actual: step 4 prints a traceback that ends with TypeError: 'NoneType' object is not subscriptable at round_trip.py:161.

Environment Diagnostics

devops-cli 0.16.1 at origin/main, ruamel.yaml and PyYAML as locked in uv.lock, Python 3.14.10, Linux.

Logs, Traces, or Terminal Output

Security Alert: Found plaintext secrets stored in config files: ['<repo>/config.yaml:ai.api_key']. ...
$ devops config unset ai.api_key
  ...
  161 |   return (*prefix, dotted), int(node.lc.key(dotted)[0]) + 1
TypeError: 'NoneType' object is not subscriptable

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate.

Source: #2513

Proposed design

Problem statement

devops config unset crashes with a TypeError when the target key is present only through a YAML merge key (<<: *anchor). The _find function in round_trip.py calls node.lc.key(dotted), which returns None for merged keys, and the code then indexes into None. The user sees a traceback instead of a clear message, and the audit keeps reporting a secret that the command cannot remove.

Acceptance criteria

Requirement: Merge key unset reports a clear error

When the target key is present only through a YAML merge key, devops config unset SHALL exit with code 1 and print a message that names the file and states the key comes from a merge key.

Scenario: unset a merge-derived key

  • WHEN the config file defines the key via <<: *anchor and the user runs devops config unset on that key
  • THEN the command exits 1, prints a message naming the file and mentioning the merge key, and prints no Python traceback

Requirement: Direct key removal is unchanged

When the target key is directly present in the file, devops config unset SHALL remove the key and exit with code 0.

Scenario: unset a directly-present key

  • WHEN the config file holds the key as a direct entry and the user runs devops config unset on that key
  • THEN the key is removed from the file and the command exits 0

Existing Tool Considered

The project already uses ruamel.yaml for round-trip YAML editing. ruamel.yaml lists merged keys as keys of the mapping but gives no position for them, so node.lc.key() returns None. No external tool covers the need to detect a merge-derived key and report a friendly error. The fix is a few lines in the project's own round_trip.py: check whether node.lc.key(dotted) is None before indexing, and raise a ConfigurationError. Written cost: roughly 10 tokens of new code, no new dependency, no ongoing maintenance beyond the existing module.

Key questions

  • Why does node.lc.key(dotted) return None for a merge-derived key?: ruamel.yaml resolves merge keys into the mapping so that dotted in node is True, but the merged key has no position in the source text. The lc (line/column) table holds no entry for it, so lc.key(dotted) returns None. Indexing None[0] raises TypeError. [sources: src/devops_cli/config/round_trip.py:161]
  • Should the fix raise a clear error or remove the value from the anchor mapping?: Raise a ConfigurationError. The anchor may be shared by multiple merge targets, so removing from the anchor would silently affect keys the user did not ask to remove. A clear error names the file and tells the user to remove the key from the anchor mapping directly. (best practice) [sources: src/devops_cli/config/round_trip.py]
    • Chosen: Raise ConfigurationError naming the file and the merge key. Safe: does not modify a shared anchor. Clear: tells the user exactly where to act. Matches the existing error pattern in the module.
    • Rejected: Remove the value from the anchor mapping. Rejected: the anchor may be shared by other merge targets. Removing from it would silently change keys the user did not request, and the user asked to remove ai.api_key, not a.b.api_key.
  • What should the error message say?: The message SHALL name the file and state that the key comes from a YAML merge key. This follows the existing ConfigurationError pattern in the module, for example 'Cannot save the settings: {name} is not valid YAML'. (best practice) [sources: src/devops_cli/config/round_trip.py]
    • Chosen: Name the file and state the key comes from a merge key. Matches the existing error style in the module. Gives the user enough to locate and fix the key in the anchor.
    • Rejected: Print a generic 'key not found' message. Rejected: the key is found in the merged mapping. A 'not found' message is misleading and does not tell the user what to do.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/high
    effort/low
    on Oct 29, 2026
  2. dan-petty commented on Oct 29, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. A TypeError crash in an existing command is a defect, not a new feature or security vulnerability.
    • Priority: P1-High. The crash blocks removal of a reported plaintext secret and prints an unhandled traceback.
    • Value: High. Users cannot remove a secret that the audit reports, and the command crashes instead of giving a clear message.
    • Effort: Low. The fix is localized to the _find path in round_trip.py where node.lc.key(dotted) returns None for merged keys.
    • Related: fix(config): devops config unset leaves the plaintext secret that it removes in its .bak copy #2645, which asks for a different change. Both items concern devops config unset, but the candidate fixes a TypeError crash on merge keys while #2645 fixes the .bak copy retaining the removed secret.
  3. added
    priority/p1-high
    on Oct 29, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 29, 2026
  5. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 19a2e08 (see proposed design in issue body).

  6. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Staged: branch fix/2656-devops-config-unset-stops-with-a, draft pull request #2697. 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:

    1. Detect merge-derived key in _find and raise ConfigurationError: 3268 tokens
  7. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Staged: branch fix/2656-devops-config-unset-stops-with-a, draft pull request #2719. 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:

    1. Add merge-key error in _find: 3152 tokens
  8. removed
    status/ready
    on Oct 29, 2026
  9. 32 remaining items

  10. added
    status/ready
    and removed
    status/in-progress
    on Oct 30, 2026
  11. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    The runner Job devops-cli-runner-20261030-183930-529c ended: succeeded.

    The last lines of its log:

    b'# Implement plan for dan-petty/devops-cli\n\n## To implement\n- #2656 fix(config): devops config unset stops with a TypeError for a key that a YAML merge key gives: Planned, new branch `fix/2656-devops-config-unset-stops-with-a` and a new pull request (a retry: the stop on record is cleared first)\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: list_files, ok.\nTool call: list_files, ok.\nTool call: grep, ok.\nTool call: read_file, ok.\nTool call: write_file, ok.\nTool call: shell, program uv, ok.\n\xe2\x9c\x93 Took 0 item(s) to a ready pull request, stopped 1.\nElapsed: 2m 19s\n'
    
  12. dan-petty commented on Oct 30, 2026

    @dan-petty
    OwnerAuthor

    implement: retry

  13. added
    status/in-progress
    and removed
    status/ready
    on Oct 30, 2026
  14. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    The runner Job devops-cli-runner-20261030-202214-d182 ended: failed.

    The last lines of its log:

    b'# Implement plan for dan-petty/devops-cli\n\n## To implement\n- #2656 fix(config): devops config unset stops with a TypeError for a key that a YAML merge key gives: Planned, new branch `fix/2656-devops-config-unset-stops-with-a` and a new pull request (a retry: the stop on record is cleared first)\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: list_files, ok.\nTool call: list_files, ok.\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: write_file, ok.\n'
    

    The Job left this item without a result. The item is Ready again, and the job will not run it. Fix the cause. Then comment implement: retry.

  15. added
    status/ready
    and removed
    status/in-progress
    on Oct 30, 2026
  16. added
    status/in-review
    and removed
    status/ready
    on Oct 31, 2026
  17. removed
    status/in-review
    on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p1-highscope/configsource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions