Skip to content

pm-dispatch(github): GitHub API response bodies are shape-trusted — a token-less access-token reply is sent as Bearer undefined, a wrong-shape create reply is returned as a successful issue, and a null create body falls back to a duplicate gh create #7101

Closed

Description

@dezren39

Problem

pm-stack/dispatch/src/github.ts — the GitHub App client every pm-dispatch session/task launch uses to create its tracking issue, verify attach targets, comment, and label — reads every GitHub API response body through a bare TypeScript cast and never validates the shape. A wrong-shape 200/201 from the API (or any intermediary that answers 2xx with an unexpected body) is silently trusted:

  • github.ts:104-105 — the installation lookup: const data = (await res.json()) as { id: number }; installationId = data.id;
  • github.ts:110-112 — the access-token mint: const data = (await res.json()) as { token: string; expires_at: string }; the token is cached and returned unvalidated.
  • github.ts:183-184 — issue creation: const data = (await res.json()) as { number: number; html_url: string }; return { number: data.number, url: data.html_url };
  • github.ts:230-241 — issue lookup (getIssue): the same cast for { number, state, html_url, pull_request? }.

This is the dispatch sibling of the projector GitHub client fixed in #6954 ("a token-less access-token reply is returned as a valid app token") and of the dispatch OpenCode client fixed in #7085 — this module was never given the same boundary. test/attach_verify.test.ts exercises getIssue only with well-formed bodies and a 404; no test feeds the client a wrong-shape 2xx.

Evidence (verified this run)

Probe on the laptop, ~/git/fleet/probe-dispatch-github (probe.ts, probe2.ts): the real src/github.ts copied verbatim (md5 90762430977c01650312e325510c915a on both sides, current main bfa5caede7622a9e3dee01beeec110e2c5fde2bf), fetch stubbed in the style of test/attach_verify.test.ts, and a fake gh first in PATH so the CLI fallback is deterministic. Control cases pass: a well-formed installation/token/create sequence returns { number: 123, url: "…/issues/123" }, and a well-formed lookup returns the issue.

With a wrong-shape 2xx, the client does not raise a boundary error:

  1. Installation {} → the token mint is POSTed to /app/installations/undefined/access_tokens (the undefined id used verbatim) and the flow "succeeds".
  2. Access-token {} → issue creation proceeds with the header Authorization: Bearer undefined and is reported as success (the probe stub records authIsUndefined: true on the create call). A numeric token ({ token: 123, … }) is likewise coerced and sent as Bearer 123. A bad expires_at is cached as expiresAt: NaN.
  3. Create-issue {} → createIssue returns {} — i.e. { number: undefined, url: undefined } — as a success. Downstream (src/server.ts) that phantom ref feeds canonicalDedupeKey(kind, repo, issue.number), the agent-note comment(repo, issue.number, …) and addLabels(repo, issue.number, …) calls, and the 201 response's issue_number — all against an issue that was never identified.
  4. Create-issue { number: "abc", html_url: 42 } → returned verbatim as { number: "abc", url: 42 }.
  5. Lookup {} → getIssue returns a non-null info with number/state/url all undefined (only isPullRequest: false survives serialization). The fix(pm-dispatch): POST /v1/tasks issue_number attach never verifies the issue exists, is open, or is an issue #3007 attach verification then rejects the target with issue #<n> … is undefined, not open — a live, open issue refused on a fabricated state.
  6. JSON null bodies (installation, token, create, lookup) → a raw TypeError (null is not an object (evaluating 'data.token') / 'data.number' / '(await res.json()).id') escapes the parse site, is caught only by the generic app-route fallback, and is misreported as a dual-route failure ("issue create failed via app (…) and via gh (…)"). For issue creation this is worse than a confusing error: the app POST may already have created the issue server-side before its body failed to parse, and the fallback then creates a second tracking issue via gh.

Why it matters

pm-dispatch is the fleet's launch door: every dispatched session/task anchors its queue packet, dedupe key, agent-note comment, and labels to the issue identity this client returns. A single malformed 2xx can (a) send a literal Bearer undefined credential, (b) anchor a real queue task to a phantom undefined issue, (c) reject a valid attach target as "undefined, not open", or (d) duplicate the tracking issue across the app and gh routes. The failure mode is silent or misattributed in every case — nothing in the response tells the operator the GitHub reply itself was malformed.

Acceptance criteria

  • Every res.json() body in pm-stack/dispatch/src/github.ts (installation lookup, access-token mint, issue create, issue lookup) is validated before use: the body must be a JSON object; id a positive integer; token a non-empty string with a parseable expires_at; create/lookup number an integer, state and html_url strings. Violations raise GitHubError naming the endpoint and the malformed field — never a raw TypeError/SyntaxError, never a silently coerced or undefined value.
  • A malformed 2xx create-issue body does not trigger the gh fallback create (the issue may already exist server-side); it surfaces as an explicit error. Malformed installation/token replies may still fall back to gh (no side effect has happened yet), with the malformed-body reason preserved in the combined error.
  • New regression tests (new test/github.test.ts or extending test/attach_verify.test.ts, stubbed fetch in the existing style) cover at least: installation {}, token {}, token numeric, create {}, create wrong-typed fields, lookup {}, and a null body — each failing on the pre-fix code — while the well-formed control cases and the existing dispatch suite stay green.
  • No behavior change for well-formed responses or for definitive HTTP failures (404 lookup still returns null; non-2xx still raises/falls back as today).

Dedup: searched open + closed issues for installationToken, "dispatch github shape", and pm-dispatch GitHub-client titles — no hits. #6954 covers pm-stack/projector/src/github.ts, not this client; #7085 covers pm-stack/dispatch/src/opencode.ts, not this module.

Activity

  1. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor
  2. added
    source/creatorFiled by the new-issue-creator job
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    priority/normalOrdinary priority (the default)
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    app/pm-stackpm-stack (Pad/Grist) in developing-today/code
    effort/sSmall: expected under 2 hours of work
    on Nov 8, 2026
  3. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 10, 2026
  5. added a commit that references this issue on Nov 10, 2026
  6. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

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

    app/pm-stackpm-stack (Pad/Grist) in developing-today/codeeffort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions