Skip to content

fix(protocol): don't read a 403 body as the agent's login - #101

Open
glennfaison wants to merge 1 commit into
mainfrom
fix/agent-self-403
Open

glennfaison wants to merge 1 commit into
mainfrom
fix/agent-self-403

Conversation

@glennfaison

Copy link
Copy Markdown
Owner

Found by running /retrospective over the last 14 days of a downstream repo's run log (glennfaison/livepage, Nov 1–15, 143 entries).

Problem

A runner using a GitHub App installation token logged gh auth status / gh api user failures in 39 of 69 problem entries, and 12 entries traced to trust going wrong. For such a token gh api user is a 403 ("Resource not accessible by integration"), and gh still prints the error body on stdout. _agent_self captured that body, and _trusted_logins split it on commas into the trusted-author list. Agents reported exactly this ("_agent_self captured an error JSON"). Downstream it led to ready handoffs posted and then reverted, and duplicate PRs claiming one issue.

Separately, agents had no guidance on how to check gh, so they ran gh auth status themselves, read the App-token failure as "invalid token", and logged it as a problem on almost every Triaging run. Reads and writes worked the whole time: the same bot wrote 126 log comments in the window.

Change

  • lib.sh _agent_self: use the output of gh api user only when the call succeeded and it is a login (name or name[bot]); otherwise the agent is unknown.
  • Protocol Shell setup: how to check that gh works (gh repo view), why not gh auth status / gh api user, and that a 401/403 on an actual write is a failed problem.
  • Protocol Trust: a trusted_authors login is matched whole, as the API shows it (my-app[bot], not my-app), * matches nothing, and an agent whose gh api user is a 403 must be listed. The downstream runner passed kilo-code-bot,…,*, which trusted nobody.
  • Changeset (patch).

Tests

New Agent identity section in tests/lib.test.sh. Real gh prints the 403 body on stdout, which the simulator's faults do not (they write to stderr only), so the tests put a gh function in front of the simulator. Before the fix 4 of the 8 new checks failed, with the error JSON inside the trusted logins; all pass after. npm run check is green (lint, validate, plugin version, 561 tests), and the pre-push hook ran it.

Not in this PR

  • setup-github-agent-workflow step 1 still says gh auth status must succeed. A human runs setup once, but an App token would fail it. Changing it touches the skill's contract and the simulator surface, so I left it for a follow-up.
  • A wildcard for trusted_authors is not added. The trust list stays exact logins.

For a GitHub App installation token `gh api user` is a 403, and `gh` still
prints the error body on stdout. `_agent_self` took that body as the agent's
login, and `_trusted_logins` split it into the trusted authors.

`_agent_self` now uses the output only when the call succeeds and it is a
login (`name` or `name[bot]`). The protocol says how to check that `gh`
works without `gh auth status` or `gh api user`, and that a trusted_authors
login is matched whole, so `*` matches nothing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants