Skip to content

fix: handle GitHub OIDC format and error handling - #37889

Closed
chAwater wants to merge 3 commits into
anomalyco:devfrom
chAwater:fix-37823
Closed

fix: handle GitHub OIDC format and error handling#37889
chAwater wants to merge 3 commits into
anomalyco:devfrom
chAwater:fix-37823

Conversation

@chAwater

Copy link
Copy Markdown

Issue for this PR

Closes#37823

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The GitHub OIDC tokens changed from repo:octocat/my-repo:ref:refs/heads/main to repo:octocat@123456/my-repo@456789:ref:refs/heads/main (according to the GitHub changelog), breaking the exchange_github_app_token endpoint and causing a cryptic failure chain in the GitHub Action log.

> Run opencode github run
Failed to parse JSON
Creating comment...
Error: Unexpected error
undefined is not an object (evaluating 'p.rest')

The root cause is a three-link chain (detailed analysis in the issue #37823):

  1. api.ts — owner/repo parsed incorrectly from new sub format
    New format repo:octocat@123456/my-repo@456789:ref:… was split as-is, producing octocat@123456 / my-repo@456789, which fails the installation lookup.
  2. api.ts — uncaught installation lookup error returns non-JSON 500
    The failed getRepoInstallation call throws through Hono without a catch, so the client receives an HTML/text error page.
  3. github.handler.ts — client assumes JSON response, masks the real error
    response.json() fails on the text body → Failed to parse JSON. Then the catch block calls createComment with an uninitialized octoRestundefined is not an object (evaluating 'p.rest'), which buries the real cause.

This PR fixes the parsing of new OIDC tokens and adding error handling to expose the real error message.

How did you verify your code works?

The api.ts cannot be tested end-to-end before deployment.
I only tested the error handling part using a test repo with test workflow: GitHub Actions logs

Screenshots / recordings

None

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@xinyi688life

Copy link
Copy Markdown

i am sorry, i can not execute action success with anomalyco/opencode/github@dev or anomalyco/opencode/github@main,can you tell me how to fix it with my workflow config? name: opencode

on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]

jobs:
opencode:
if: |
contains(github.event.comment.body, ' /oc') ||
startsWith(github.event.comment.body, '/oc') ||
contains(github.event.comment.body, ' /opencode') ||
startsWith(github.event.comment.body, '/opencode')
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
persist-credentials: true

 - name: Run opencode
uses: anomalyco/opencode/github@dev
env:
OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
with:
model: opencode/big-pickle

@opencode-agent

Copy link
Copy Markdown
Contributor

User xinyi688life does not have write permissions

github run

@xinyi688life

Copy link
Copy Markdown

Run anomalyco/opencode/github@dev
with:
model: opencode/big-pickle
use_github_token: false
env:
OPENCODE_API_KEY: ***
Get opencode version
0s
Run VERSION=$(curl -sf https://api.github.com/repos/anomalyco/opencode/releases/latest | grep -o '"tag_name": "[^"]"' | cut -d'"' -f4)

Cache opencode
0s
Install opencode
2s
Add opencode to PATH
0s
Run echo "$HOME/.opencode/bin" >> $GITHUB_PATH
Run opencode
2s
Run opencode github run
opencode github run
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
env:
OPENCODE_API_KEY: ***
MODEL: opencode/big-pickle
AGENT:
SHARE:
PROMPT:
USE_GITHUB_TOKEN: false
MENTIONS:
VARIANT:
OIDC_BASE_URL:
Failed to parse JSON
Creating comment...
Error: Unexpected error
undefined is not an object (evaluating 'p.rest')
Error: Process completed with exit code 1. how can i fix this problem, i thought version change to dev can work

@chAwater

Copy link
Copy Markdown
Author

@xinyi688life, just set the use_github_token: true

 - name: Run opencode
uses: anomalyco/opencode/github@latest
env:
OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
with:
model: opencode/big-pickle
use_github_token: true

If this helped you, please add 👍 emoji to the PR, thanks 🙏

@0xjei

Copy link
Copy Markdown

bump! the usage of Github Token is a workaround but makes things badly configured since we pass from the action instead of the agent.

@appspringtech

Copy link
Copy Markdown

anyway to help and get this released asap?

@chAwater

Copy link
Copy Markdown
Author

bump this PR and rebased the branch to the latest

@neriousy

Copy link
Copy Markdown
Contributor

Thanks @chAwater for the detailed root-cause analysis and initial error-handling fix. The issue is now resolved by #44776 on dev and #44778 on v2. Your analysis of the non-JSON response and uninitialized GitHub client directly informed the merged fix.

Sign up for freeto 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.

GitHub action fails on repos created after 2026-07-15 (new OIDC sub format)

5 participants

@chAwater@xinyi688life@0xjei@appspringtech@neriousy