Skip to content

fix(cli): docs check resolves every devops argv in src #868

Closed

Description

@dan-petty

Problem

devops devcontainer bootstrap-k8s has never deployed a stack. _auto_deploy_k8s_stack (src/devops_cli/commands/devcontainer.py:960-972) runs ["devops", "k8s", "deploy-stack", stack] (:964). devops k8s deploy-stack takes no positional argument; the stack is the --stack/-s option (src/devops_cli/commands/k8s/stack_lifecycle.py:695-726, option at :697). The call fails with "unexpected extra argument", exit 2. The line came in with 491907c (v0.2.0), and deploy_stack took the stack only as --stack then too.

The failure is easy to miss:

  • The call runs with check=False, quiet=True (devcontainer.py:966-967), and run_subprocess captures output by default (core/process.py:224). The captured output is thrown away. The warning says only Failed to auto-deploy Kubernetes stack '<stack>' (devcontainer.py:971), with no exit status, and deploy-stack's usage error never reaches the terminal or the background log.
  • bootstrap-k8s deploys by default (--deploy/--no-deploy, devcontainer.py:1664-1666).
  • This repo's devcontainer sets DEVOPS_K8S_AUTO_DEPLOY=true (.devcontainer/devcontainer.json:44). So every post-start with Minikube autostart spawns bootstrap-k8s --stack infra --deploy in the background (devcontainer.py:1146-1155, :1016-1024), and its deploy step fails inside /tmp/devops-k8s-bootstrap.log.
  • The test for this path, test_bootstrap_k8s_autodeploy_k8s_stack (tests/test_devcontainer.py:792-820), patches run_subprocess to succeed for any argv and uses the stack observability, which deploy-stack rejects (commands/k8s/networking.py:59-72). It then asserts the mock's success message.

The same broken command is printed as a tip when Qdrant is unreachable: 'devops k8s deploy-stack llm'. It appears in lang/en/messages.py:589-592 (read by commands/rag.py:167), again inline in commands/rag.py:261-262, and in lang/en/errors.py:220 (ERRORS.rag.cannot_connect, which nothing reads). #920 and #921 fix the same mistake, but only in Markdown.

The static check has a gap. #836 added resolve_devops_argv (src/devops_cli/docs/command_resolver.py) and an AST collector (src/devops_cli/docs/mcp_argv_collector.py), and devops docs check runs both (docs/generator.py:1078-1087). The collector has two limits:

  • It reads only the MCP server (collect_mcp_server_argv_references, mcp_argv_collector.py:64-74).
  • It collects only lists that start with uv run devops (_is_devops_argv, :118-121; CONST_DEVOPS_ARGV_PREFIX, config/constants.py:118).

So nothing checks 8 other argv lists in src/devops_cli:

  • 4 uv run devops docs … lists in commands/ci.py (:361, :445, :1022, :1024);
  • uv run devops ci run in commands/release.py:1287;
  • 3 bare ["devops", …] lists, at commands/devcontainer.py:964, :1016 and core/cli.py:132.

docs/ROADMAP.md:766 records the bare case as #836's follow-up.

Reading more files is not enough on its own. Measured on the release/v0.2.25 tip (9c879ae): with all 174 lists collected (166 in the server, 8 elsewhere), the current resolver reports 0, the broken line included. The resolver reports only literal leftover arguments, because a computed token left over "may be an option the caller computes" (command_resolver.py:78-82; _unexpected_argument, :169-177). stack at :964 is computed, so it is skipped. A planted literal ["devops", "k8s", "deploy-stack", "infra"] is reported (unexpected extra argument 'infra' for 'devops k8s deploy-stack'), but the real bug is not.

A stricter rule was measured on the same tree: report a computed single token left over where the command takes no more positional arguments, after splitting a conditional between two string literals into both alternatives. It reports exactly 2 of the 174 lists:

  • devcontainer.py:964, the bug;
  • ai/mcp/server.py:604 (config_output), whose option comes from a local flag = "--json" if … else "--export" (:603). With the conditional written inline, both alternatives resolve.

ai_gateway_failover (server.py:2671-2682, conditional at :2679) already passes an inline conditional, and both --simulate and --no-simulate resolve.

Cost, on this host under load:

  • Parsing every module under src/devops_cli (501 files) took 2.8-4.1 s.
  • Collecting only from files that contain a "devops" string literal (16 files, all 5 files with argv lists among them, the server included) took 0.35-0.58 s.

Acceptance criteria

Call site:

  • _auto_deploy_k8s_stack runs ["devops", "k8s", "deploy-stack", "--stack", stack]. A test with run_subprocess patched asserts the exact argv ["devops", "k8s", "deploy-stack", "--stack", "infra"].
  • _auto_deploy_k8s_stack runs deploy-stack with capture_output=False, as release.py:1289 does for devops ci run. deploy-stack's own output then goes to the terminal when bootstrap-k8s runs in the foreground, and to /tmp/devops-k8s-bootstrap.log when it runs in the background, because the background worker's stdout and stderr are that log (devcontainer.py:1036-1042). The call site parses none of that output.
  • On a non-zero exit, the warning names the stack and the exit status, for example Warning: Failed to auto-deploy Kubernetes stack 'infra' (exit 2). It quotes no text from deploy-stack. A test patches run_subprocess to return exit 2 with the real stderr shape: the Typer usage panel (│ Got unexpected extra argument(s) (infra) │ inside ╭─ Error ─╮ … ╰─╯) followed by Elapsed: 0.5s. It asserts that the call passed capture_output=False, that the warning contains 'infra' and exit 2, and that the warning contains neither Elapsed nor ╰.
  • test_bootstrap_k8s_autodeploy_k8s_stack uses a stack that deploy-stack accepts, and asserts the argv it ran, not only the mock's success.
  • The Qdrant tip reads devops k8s deploy-stack --stack llm and lives in one string. commands/rag.py:261-262 uses MESSAGES.rag.cannot_connect_qdrant, and the unread ERRORS.rag.cannot_connect (lang/en/errors.py:220) is deleted. A test passes the command quoted in the tip to resolve_devops_argv and gets no finding.

Static check:

  • The collector reads every module under src/devops_cli. It collects list literals that start with "devops" and lists that start with "uv", "run", "devops", and devops docs check resolves every one. A file with no "devops" string literal is skipped without being parsed.
  • A computed single token (a list element, or the argument of .append) that is left over where the command takes no more positional arguments is reported as an unexpected argument. A starred element, or .extend of a non-literal, still stands for any number of tokens and is not reported. A conditional between two string literals is resolved once for each alternative. Other callers of resolve_devops_argv (fix(ai): the knowledge base names only commands, options and components that exist #920, fix(github): supply-chain claims made true — live Dependabot, zizmor and workflow invocation contracts #861) see no change in behaviour.
  • Fixture tests:
    • ["devops", "k8s", "deploy-stack", "infra"] and ["devops", "k8s", "deploy-stack", stack] are each reported at their fixture line.
    • ["devops", "k8s", "deploy-stack", "--stack", stack], a list ending in *args, and cmd.extend(flags) are not reported.
    • A conditional where one alternative is an unknown option is reported, naming that option.
  • devops docs check exits 1 and names <path>:<line> when the collector returns the broken fixture line. This follows the pattern of test_docs_check_reports_an_unresolved_mcp_argv (tests/test_docs_mcp_argv_collector.py:157).
  • A test over all of src replaces test_every_mcp_server_argv_resolves (tests/test_docs_mcp_argv_collector.py:129-155). With the fixes above in, it collects at least 174 lists from at least 5 files and reports none. config_output writes its conditional inline in the argv (ai/mcp/server.py:603-605).
  • Neither the resolver nor the collector runs a command or starts a process. The test over all of src keeps the subprocess.Popen and _run_mcp_cmd guards.
  • The added collection costs at most 1 s in the gate. The task file records the measurement.
  • The names that say "MCP server" are replaced, with no alias left behind: the module, collect_mcp_server_argv_references, check_mcp_server_argv and CONST_DEVOPS_ARGV_PREFIX. The collector's docstring states the branch-blind rule and the single-token rule.

Delivery:

  • changelog.d/868.md holds the ### Fixed entries. CHANGELOG.md and docs/ROADMAP.md are not edited.
  • Every test runs offline. uv run devops ci passes.
  • Pending a person: in the devcontainer with Minikube running, run devops devcontainer bootstrap-k8s --stack infra --deploy. deploy-stack's Installing … lines appear in the terminal, it prints Auto-deployed Kubernetes stack 'infra', and helm list -A shows the infra releases.
  • Pending a person: in the same devcontainer, run devops devcontainer bootstrap-k8s --stack observability --deploy. The terminal shows deploy-stack's Invalid stack: 'observability'. Supported stacks: infra, llm, logging, all line, then a warning naming 'observability' and exit 1.

Key questions

  • Should argv built across branches be followed? (proposed) No. The collector stays branch-blind, as fix(mcp): mcp tools and resources call commands and options that exist #836's is (mcp_argv_collector.py:50-56). A false positive from appends in branches that exclude each other is acceptable, and the docstring states the limit. The one such list in src today, devcontainer.py:1016-1024, reads as … --stack <stack> --deploy --no-deploy, which resolves.

  • Should a computed token be reported where the command takes no positional argument? (proposed) Yes, for a single token only, with conditionals between literals split into their alternatives. Without this rule, the widened check would still pass the bug that prompted this item. Measured on today's tree, the rule adds one false positive, and inlining the conditional at server.py:603-605 removes it. From then on, an option name in an argv list must be a literal or a conditional between literals. This changes fix(mcp): mcp tools and resources call commands and options that exist #836's documented rule (command_resolver.py:80-81), which is why the owner should confirm it. Without the rule, the call-site argv test is the only guard for this bug.

  • Should the collector follow a local name bound to a conditional, as in config_output? (proposed) No. There is one such case; inline it instead.

  • Do the Qdrant tips belong in this item? (proposed) Yes. They print the same broken command from src, and neither fix(ai): the knowledge base names only commands, options and components that exist #920 nor docs: hand-written docs name only commands, options and components that exist #921 covers Python strings.

  • Should the warning quote deploy-stack's stderr? (proposed) No. Leave the output uncaptured instead. The last line of a captured devops stderr is never the error: main.py registers _print_elapsed with atexit (main.py:22-30), and it prints Elapsed: … to stderr whenever the root callback has set _timing["start"] (main.py:212), which happens before any subcommand parses its arguments. Measured on 9c879ae by running the real entry point with output captured, as _auto_deploy_k8s_stack does:

    • devops k8s deploy-stack infra (today's call) exits 2. Its stderr is the Typer usage panel, │ Got unexpected extra argument(s) (infra) │ between box-drawing borders, followed by Elapsed: 1.13s.
    • devops k8s deploy-stack --stack observability exits 1. Its stderr is Invalid stack: 'observability'. Supported stacks: infra, llm, logging, all followed by Elapsed: 1.35s.

    Stripping the footer and the panel borders would be fragile. The panel wraps long messages over several lines, and a Helm failure prints many lines (stack_lifecycle.py:623-625). Uncaptured output also shows the deploy's progress during a run that can take minutes (--wait is the default, with --timeout 10m, stack_lifecycle.py:701-711). The output in the log is what deploy-stack prints when a person runs it by hand. This call site adds nothing to it, so it needs no masking of its own.

  • Should bootstrap-k8s --stack reject a stack deploy-stack would reject? (proposed) No, not in this item. With the output uncaptured, the background log carries deploy-stack's own Invalid stack: '<stack>'. Supported stacks: infra, llm, logging, all line, followed by the warning that names the stack and exit 1.

  • Are tests, workflows and Markdown in scope? (proposed) No. Test fixtures hold broken argv on purpose. Workflows and pre-commit entries are item (3) of fix(github): supply-chain claims made true — live Dependabot, zizmor and workflow invocation contracts #861. Markdown belongs to fix(ai): the knowledge base names only commands, options and components that exist #920 and docs: hand-written docs name only commands, options and components that exist #921.

  • Should tuples be collected too? (proposed) No. Every argv in src is a list. The only matching tuple is the prefix constant (config/constants.py:118).

  • Is this a critical fix? (proposed) No. It is a P1 defect in v0.2.29, and nothing in v0.2.25 to v0.2.28 waits on it.

Depends on: #836 (closed; delivered in v0.2.24 by #867). No open dependency. The item can start at any point in v0.2.29.

Related:

Update 2026-10-08

Owner's scope decision. The auto-deploy argv fix already shipped in v0.2.26 with #741. _auto_deploy_k8s_stack runs ["devops", "k8s", "deploy-stack", "--stack", stack] (commands/devcontainer.py:970), and tests/test_devcontainer.py:2014-2040 asserts that argv. This item now delivers only the docs-check half and the Qdrant tip. _auto_deploy_k8s_stack, its warning and its tests stay as they are. Post-start auto-deploy moves to the owner-decision issue #1368: making deploy-stack's output and exit status visible would not make it deploy (premise 5 below).

Reduced acceptance criteria. These replace the "Call site" and "Static check" lists above:

  • The collector reads every module under src/devops_cli. It collects list literals that start with "devops" or with "uv", "run", "devops", and devops docs check resolves every one. A module with no quoted devops literal is skipped without being parsed.
  • A computed single token left over where the command takes no more positional arguments is reported as an unexpected argument. That covers a list element or the argument of .append. A starred element, or .extend of a non-literal, still stands for any number of tokens and is not reported. The marker is opt-in, so the Markdown collectors (fix(ai): the knowledge base names only commands, options and components that exist #920, docs: hand-written docs name only commands, options and components that exist #921) and tests/markdown_examples.py (docs(review): SELF_IMPROVEMENT, AGENTS.md and the knowledge base describe the review loop as it runs #952) see no change.
  • A conditional between string literals, or between such conditionals (nested), is resolved once per alternative, and each list is reported at most once.
  • roadmap_refine and roadmap_intake write --repo, --ref, --title and --source as literals. Each is validated with _validate_mcp_arg, and the argv order is unchanged. roadmap_intake's mode flag is a nested conditional between the three literal flags. config_output writes its conditional inline. _roadmap_cmd is unchanged.
  • Fixture tests:
    • ["devops", "k8s", "deploy-stack", "infra"] and ["devops", "k8s", "deploy-stack", stack] (as an element and as an append) are reported at their lines.
    • --stack stack, a *args tail and cmd.extend(flags) are not reported.
    • A conditional with an unknown option is reported, naming that option, and a nested literal conditional resolves each alternative.
  • devops docs check exits 1 and names <path>:<line> for a broken collected line, with the Markdown checks patched so the call stays under 1 s.
  • A test over all of src replaces test_every_mcp_server_argv_resolves. It finds at least 174 lists from at least 5 files and reports none. Command trees are built in a module-scoped fixture.
  • Neither the resolver nor the collector runs a command; the subprocess.Popen and _run_mcp_cmd guards stay.
  • The added collection costs at most 1 s in the gate, and the task file records the measurement.
  • The names that say "MCP server" are replaced with no alias left behind: the module, collect_mcp_server_argv_references, check_mcp_server_argv, CONST_DEVOPS_ARGV_PREFIX and the now-unused CONST_MCP_SERVER_MODULE. The collector's docstring states the branch-blind rule and the single-token rule.
  • The Qdrant tip reads devops k8s deploy-stack --stack llm in one MESSAGES string. commands/rag.py uses it on both paths, ERRORS.rag.cannot_connect is deleted, and the quoted command resolves with resolve_devops_argv.
  • changelog.d/868.md holds the ### Fixed entries. CHANGELOG.md and docs/ROADMAP.md are not edited.
  • Every test runs offline with each call phase under 1 s, and uv run devops ci passes.

Moved to #1368: running deploy-stack with capture_output=False, the exit status in the warning, the observability stack in test_bootstrap_k8s_autodeploy_k8s_stack and test_post_start_autodeploy_k8s_stack, and both "Pending a person" bootstrap-k8s checks.

Corrected premises (checked on release/v0.2.29 at 910b823):

  1. The argv half is done (feat(k8s): devops-cli runs in the homelab cluster as Jobs, and every cluster Secret is pushed from the keyring, also by deploy-stack (devops k8s push-secrets, devops k8s run-job) #741, above). The failure warning is now MESSAGES.devcontainer.auto_deploy_failed (lang/en/messages.py:895-898) and carries a keyring unlock hint.

  2. Today the single-token rule reports 3 lists, not 1. They are config_output (ai/mcp/server.py:645-647), plus roadmap_refine (:800-804) and roadmap_intake (:833-843), which were added in v0.2.26 and built f"--{name}" and f"--{mode}" option names. With the rewrites above, it reports 0 of 179.

  3. Counts: there are 179 argv lists in 5 files (172 in the server, 3 in commands/ci.py, 2 in commands/devcontainer.py, and 1 each in commands/release.py and core/cli.py). The resolver before this change reported 0 of them. The prefilter leaves 24 of 545 modules to parse.

  4. Collection cost, measured in-process over seven interleaved runs at load average 10 to 12: the MCP-only collector took a median of 0.10 s, and the collector over all of src a median of 0.52 s, so about 0.4 s is added.

  5. Making deploy-stack's output visible would not make auto-deploy work:

    • run_subprocess's isolated env drops DBUS_SESSION_BUS_ADDRESS, so the child gets the fail keyring backend even when the keyring is unlocked.
    • No --context is passed, so deploy-stack uses the configured k8s.context, not necessarily the Minikube that bootstrap-k8s starts. Post-start spawns the bootstrap by default only when that context is minikube, but a hand-run bootstrap-k8s --deploy or the autostart env override deploys to whatever context is configured, including an Argo-managed one.
    • Post-start spawns the bootstrap before it starts the session bus, while the keyring is normally locked.

    Details and options are in fix(cli): devcontainer auto-deploy reaches the keyring and the Minikube it started, or is dropped for a printed deploy-stack command #1368.

  6. Updated line references: the Qdrant tip is at lang/en/messages.py:701-704, commands/rag.py:264-266 and lang/en/errors.py:237. ai_gateway_failover's inline conditional is at ai/mcp/server.py:2864.

Activity

  1. added
    type/bug
    scope/cli
    priority/p2-medium
    on Oct 1, 2026
  2. added
    priority/p1-high
    and removed
    priority/p2-medium
    on Oct 2, 2026
  3. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Grooming (2026-10-02): Priority p2-medium → p1-high. devops devcontainer bootstrap-k8s defaults to --deploy, and its deploy step has failed every time since v0.2.0 behind a warning. A command that never does half its job counts as broken under policy.

    Checked against the code at the release/v0.2.25 tip.

  4. added this to the v0.2.29 milestone on Oct 2, 2026
  5. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Placed in v0.2.29 on 2026-10-02. v0.2.29 holds P1 work that has to land before v0.3.0, which v0.2.25 to v0.2.28 had no room for. Backlog P1 items were ranked by Value, then Effort, with defects and security fixes first at a tie. This item ranked in the top ten, and two of the release's twelve slots stay open for P1 items that surface before then.

  6. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Refined to Ready on 2026-10-02 for v0.2.29. The body was checked claim by claim against release/v0.2.25 at 9c879ae, and a second agent then tried to refute it; every major objection was resolved in a revision. Cited lines were updated for code that moved, and the scope was corrected where merged work changed it. Acceptance criteria were tightened so each fails on the current code, and every key question now has a proposed answer.

  7. changed the title [-]fix(cli): devcontainer auto-deploy calls deploy-stack without --stack, and docs check resolves every devops argv in src[/-] [+]fix(cli): docs check resolves every devops argv in src[/+] on Oct 8, 2026
  8. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1370, merged into release/v0.2.29 as cc13995.

    Closes #868

    The owner reduced the scope on 2026-10-08. The auto-deploy argv fix already shipped with #741 (v0.2.26), and post-start auto-deploy cannot work as specified: the child process gets no keyring, no context is passed, and post-start runs before the session bus. So this PR delivers only the docs-check half, and the auto-deploy decision is #1368.

    • Collector: reads every module under src/devops_cli (a prefilter skips modules with no quoted devops), collecting list literals that start with "devops" or "uv", "run", "devops". Each list is located by its repository path so CI annotations can open it.
    • Single-token rule: a computed token left over where the command takes no more positional arguments is reported as unexpected.
    • MCP argv: roadmap_refine and roadmap_intake write their option names as literals, still validated and in the same order. The mode flag is a nested literal conditional, and config_output is inlined. With these, the strict rule reports none of the 179 lists in src.
    • Qdrant tip: one MESSAGES.rag.cannot_connect_qdrant string reading devops k8s deploy-stack --stack llm, which the CLI accepts. A test resolves the quoted command and checks the output of rag index and rag index-kb.

    uv run devops ci passes locally (3m 59s).

    19 file(s) changed.

    How it was verified

    Check runs at ef3185c:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Analyze (python): pass
    • Static Analysis: pass
    • Analyze (actions): pass
    • Tests & Coverage: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-868-docs-check-resolves-every-devops-argv.md:

    • The collector reads every module under src/devops_cli and collects lists that start with devops or with uv run devops. devops docs check resolves each one. test_a_module_without_a_quoted_devops_is_not_parsed shows that a module that only imports devops_cli is not parsed (ast.parse called twice for three modules).
    • A computed single token, whether a list element or an .append argument, left over where the command takes no more arguments is reported. A starred element or an .extend of a runtime value is not. A conditional between literals is resolved once per alternative, nested conditionals included. test_a_single_token_placeholder_is_reported_only_when_left_over covers the resolver. test_a_placeholder_for_any_number_of_tokens_is_never_reported and the unchanged tests/test_docs_knowledge_base_argv.py, tests/test_docs_review_loop.py and tests/test_docs_command_resolver.py results show that other callers see no change.
    • The fixture tests (test_argv_lists_and_everything_added_to_them_are_collected, test_unresolved_fixture_argv_are_reported_with_their_source_line) report devops k8s deploy-stack infra and devops k8s deploy-stack <stack>, element and append, at their lines. They do not report --stack <stack>, a list ending in *args, or cmd.extend(flags). A conditional with the unknown --yaml is reported and names it, and every alternative of a nested conditional resolves.
    • devops docs check exits 1 and names fixture.py:43 when the collector returns the broken fixture line (test_docs_check_reports_an_unresolved_source_argv). The Markdown checks are patched, so the call phase stays under 1 s.
    • test_the_collector_reads_every_module_and_both_prefixes and test_every_devops_argv_in_src_resolves replace test_every_mcp_server_argv_resolves. They find at least 174 lists (179 today) in ai/mcp/server.py, commands/ci.py, commands/devcontainer.py, commands/release.py and core/cli.py, and report none. The inline config_output conditional is collected as a choice.
    • Neither the resolver nor the collector runs a command. The shared src_references fixture collects with subprocess.Popen and _run_mcp_cmd patched to raise, and the resolve test asserts that neither was called. The command trees are built in a module-scoped fixture, so each call phase stays under 1 s.
    • The added collection costs at most 1 s in the gate: about 0.4 s at load average 10 to 12, measured above.
    • The names that said "MCP server" are gone, with no alias left: the module, collect_mcp_server_argv_references, check_mcp_server_argv, CONST_DEVOPS_ARGV_PREFIX and the now-unused CONST_MCP_SERVER_MODULE. The collector's docstring states the branch-blind and single-token rules.
    • roadmap_refine and roadmap_intake keep their argv order: test_roadmap_refine_contract_and_argv, the new test_roadmap_intake_argv_keeps_its_order_and_writes_only_on_confirm, and the in-process tests/test_roadmap_intake.py MCP tests pass.
    • The Qdrant tip reads devops k8s deploy-stack --stack llm in one string. Both rag paths print it, and ERRORS.rag.cannot_connect is deleted. test_an_unreachable_qdrant_tip_names_a_deploy_command_the_cli_accepts passes the quoted command to resolve_devops_argv and gets None.
    • changelog.d/868.md holds the ### Fixed entries. CHANGELOG.md and docs/ROADMAP.md are not edited.
    • Every test runs offline, and uv run devops ci passes.
  9. added a commit that references this issue on Oct 8, 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

    priority/p1-highscope/clitype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions