Skip to content

Include labels in formatContext() output for issues and PRs#1298

Open
joshpayne-joby wants to merge 1 commit into
anthropics:mainfrom
joshpayne-joby:fix/include-labels-in-formatted-context
Open

Include labels in formatContext() output for issues and PRs#1298
joshpayne-joby wants to merge 1 commit into
anthropics:mainfrom
joshpayne-joby:fix/include-labels-in-formatted-context

Conversation

@joshpayne-joby
Copy link
Copy Markdown

Summary

The `<formatted_context>` block sent to the agent currently omits labels for both issues and pull requests, even though the GraphQL queries already fetch them. This causes agents to confidently report "no labels" on issues that have labels — a real foot-gun for workflows that route on label state (e.g., drift-fix routing on `drift:*` labels).

This PR fixes both halves of the gap:

  1. `formatContext()` now emits a `Labels:` line for both PR and Issue branches, in line with existing fields (Title, Author, State). Emits `none` when there are no labels rather than omitting the line — explicit > silent.
  2. GraphQL queries bumped from `labels(first: 1)` → `labels(first: 100)` in both `PULL_REQUEST_QUERY` and `ISSUE_QUERY`. The previous cap meant only one label would ever surface even after the formatter fix. `first: 100` matches the convention used for `comments(first: 100)` and `commits(first: 100)` in the same queries.

Discovery context

Found while setting up an internal seed-framework repo that uses this action for drift-watcher routing. The agent was repeatedly asserting "no labels" on a labeled issue. I asked it to inspect this action's source code from `/home/runner/work/_actions/anthropics/claude-code-action/v1/` — it identified `formatContext()` and the GraphQL pagination cap on its own. A satisfying full-loop debugging session.

After this fix lands, the workaround in our workflow (telling the agent to explicitly fetch labels via `gh issue view --json labels` in the system prompt) can be removed.

Test plan

  • `bun test` — 667 pass / 0 fail (was 665; added 2 new tests covering the "with labels" case for both PR and Issue branches)
  • `bun run typecheck` — clean
  • `bun run format:check` — clean
  • Updated existing `formatContext` tests to expect the new `Labels: none` line

Output sample

Before, for a labeled issue:

```
Issue Title: My Issue
Issue Author: someone
Issue State: OPEN
```

After:

```
Issue Title: My Issue
Issue Author: someone
Issue State: OPEN
Issue Labels: architecture, agent-sdk, drift:functional
```

For unlabeled issues:

```
Issue Title: My Issue
Issue Author: someone
Issue State: OPEN
Issue Labels: none
```

🤖 Generated with Claude Code

The formatted_context block sent to the agent omitted labels for both
issues and pull requests, even though the GraphQL queries already
fetched them. This caused agents to incorrectly report "no labels"
when labels existed, breaking any workflow that routes on label state
(e.g., drift-fix routing on drift:* labels in a Drift Watcher pattern).

Changes:
- Add 'PR Labels:' line to PR context output
- Add 'Issue Labels:' line to issue context output
- Both emit 'none' when no labels are present (explicit > omitted)
- Bump labels(first: 1) → labels(first: 100) in both queries; the
  previous cap meant only one label would appear even after the
  formatter fix
- Update existing tests + add 'with labels' tests for both PR and
  issue branches

Discovered while building a GitHub Actions workflow that uses this
action for drift-watcher routing in an internal seed framework
(joshpayne-joby/slim-routines#6). The agent self-diagnosed the gap
by inspecting this action's source — a satisfying full-loop.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant