Skip to content

mctl_list_previews reports count 0 when the ArgoCD query fails #698

Closed

Description

@mashkovd

Summary

When its ArgoCD query fails, mctl_list_previews reports {"count": 0, "items": []}. A failed read is presented as "no previews". In addition, the handler lists ArgoCD Applications, but previews are not ArgoCD Applications. So even a successful query cannot find them.

Observed (2026-10-18)

mctl_list_previews(team=labs, service=psa-smoke) returned:

{"count":0,"items":[],"note":"ArgoCD query failed: parsing argocd list response: missing items array"}

At that moment a preview Helm release for labs/psa-smoke existed in labs-preview.

Defect 1: a failed read becomes an empty list

internal/api/handlers_read.go:683 (ListPreviews), origin/main:

  • :705: apps, err := h.opts.ArgoCD.ListApps(team)
  • :707-713: ErrUnauthenticated returns HTTP 200 with items: [], count: 0 and an error string.
  • :715-721: ErrForbidden returns HTTP 200 with items: [], count: 0 and a note.
  • :722-728: any other error, including internal/argocd/client.go:364 "missing items array", returns HTTP 200 with items: [], count: 0 and a note.

This breaks the workspace rule that "could not observe" is never "observed absent". A failed, partial or malformed read must surface as an error or an explicit unknown state, never as an empty set or a zero. Anything that checks count == 0, including an agent deciding whether a stale preview needs cleanup, is told there is nothing there. The MCP wrapper (internal/mcp/server.go:2107) passes the body through as a successful result.

Defect 2: the handler queries the wrong source of truth

  • The handler (handlers_read.go:703-705, :730-733) and the tool description (internal/mcp/server.go:2112-2115) assume preview ArgoCD Applications named preview-{team}-{service}-{id}.
  • mctl-gitops wft-preview-deploy does not create an ArgoCD Application. It runs helm upgrade --install directly into {team}-preview (mctl-gitops platform-gitops/argo-workflows/cluster-templates/wft-preview-deploy.yaml:357 for NS="${TEAM}-preview" and :450 for helm upgrade --install).
  • The release name is preview-${COMPONENT}-${PREVIEW_ID} (wft-preview-deploy.yaml:388), with no team segment. The handler's prefix preview-{team}-{service}- could not match it even if such Applications existed.

So, as written, ListPreviews cannot return a preview created by mctl_create_preview, whether or not ArgoCD answers.

Proposed

  1. On any failed read (unauthenticated, forbidden, transport, malformed envelope), return an error: a non-2xx status and an MCP tool error. Do not return count: 0. If a soft result is ever needed, use an explicit "state": "unknown" with no count field.
  2. List from the actual source of truth: the Helm release Secrets (owner=helm, name=preview-<service>-*) or the resources labelled mctl.ai/preview=true / mctl.ai/preview-id in {team}-preview, filtered by service. Then update the tool description to match.
  3. Add tests for both: a failing backend yields an error and not count: 0, and a release named the way wft-preview-deploy names it is listed.

Related: mctl-gitops wft-preview-deploy / wft-preview-delete, and the TTL issue filed alongside this one.

🤖 Generated with Claude Code

Activity

  1. added
    bugSomething isn't working
    agents:intakeFeed this issue to the mctl-agents Temporal pipeline
    on Oct 18, 2026
  2. removed
    agents:intakeFeed this issue to the mctl-agents Temporal pipeline
    on Oct 24, 2026
  3. mctl-agents commented on Oct 24, 2026

    @mctl-agents
    Contributor

    mctl-agents issue-investigator has analyzed this issue and created a proposal:

    https://github.com/mctlhq/mctl-gitops/tree/main/platform-gitops/agents-state/mctl-api/proposals/issue-698-mctl-list-previews-reports-count-0-when/

    Status: proposed — pending human approval. Review requirements.md, design.md and tasks.md, then approve: signal this issue's DevLoopWorkflow (mctl-api POST /api/v1/agents/dev-loop/dev-loop-mctlhq-mctl-api-698/approve, or python -m orchestrator.temporal.cli approve dev-loop-mctlhq-mctl-api-698 --approver <your-identity>) — the workflow flips .status.yaml to accepted via the mctl-agents-approve operation and runs the Tier 2 implementer. If no DevLoopWorkflow is running for this issue (pre-Temporal proposal), run the mctl-agents-approve operation directly with service=mctl-api slug=issue-698-mctl-list-previews-reports-count-0-when and expected_content_digest=<digest>, the digest of the content you reviewed: in an mctl-gitops checkout, python3 scripts/proposal-content-digest.py --rev <reviewed-commit> platform-gitops/agents-state/mctl-api/proposals/issue-698-mctl-list-previews-reports-count-0-when. Without it the approve is refused (approval_content_unbound), and it is refused at the flip if the proposal changed after the commit you reviewed. See mctl-gitops docs/runbooks/proposal-approval-content-digest.md.

    The approver is recorded in .status.yaml and in the gitops commit, and the implementer refuses a proposal whose control.requires_human_approval carries no named approver — so prefer the mctl-api endpoint, which takes the approver from the authenticated caller rather than from what the caller types.

    To approve with amendments, edit requirements.md, design.md or tasks.md on mctl-gitops main through a PR first. The edit supersedes the pending grant, and the loop asks for a decision on the new one: approve that, and the implementer works from the amended files. The approve reason is recorded for audit only and never reaches the implementer, and @MCTL reinvestigate carries no text, so neither can carry amendments.

  4. added a commit that references this issue on Oct 24, 2026
  5. mctl-agents commented on Oct 24, 2026

    @mctl-agents
    Contributor

    Approval grant aar_de7b5b3c71b84faead66735b32184407 was superseded because the proposal was rewritten. It was bound to digest sha256:1adbfbead21c5de822f7c6c9eab561a854e600c1d03c0eea1aa26b6bc3b78711; the current digest is sha256:05b84be9018413add21db6225a81817b4493f70efc1536151f43c134986346ce. Please decide the fresh grant aar_4e94a2b2c89d4f2395a2b3f2e3a655c8.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions