Skip to content

fix: Codespaces — skip GITHUB_TOKEN auto-enable, cap retries, fix phantom command#415

Merged
anandgupta42 merged 1 commit intomainfrom
fix/codespaces-github-models-rate-limit
Mar 24, 2026
Merged

fix: Codespaces — skip GITHUB_TOKEN auto-enable, cap retries, fix phantom command#415
anandgupta42 merged 1 commit intomainfrom
fix/codespaces-github-models-rate-limit

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 23, 2026

What does this PR do?

Fixes three issues reported by Brian Waligorski when running altimate-code in a fresh GitHub Codespace:

  1. Skip github-models/github-copilot auto-enable in Codespaces — The Codespace GITHUB_TOKEN is machine-scoped for repo operations, not model inference. Auto-enabling these providers led to immediate 429 "Too Many Requests" errors with infinite retry loops (attempt chore(deps-dev): Bump @parcel/watcher-darwin-arm64 from 2.5.1 to 2.5.6 #11, 33m backoff).

  2. Cap retry attempts at 5 — Added RETRY_MAX_ATTEMPTS = 5 to prevent infinite retry loops for any provider. Previously there was no upper bound.

  3. Fix phantom /discover-and-add-mcps command — Toast notification referenced a non-existent slash command. Updated to "Ask the assistant to add them."

  4. Add .devcontainer/ config — Node 22 + Bun 1.3.10 for reproducible Codespace environments.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Issue for this PR

Closes #413

How did you verify your code works?

  • All 98 provider tests pass (including 3 new Codespace-specific tests)
  • All 25 retry tests pass (including exact RETRY_MAX_ATTEMPTS assertion)
  • Full test suite: 4487 pass, 0 new failures
  • Typecheck passes across all 5 packages
  • Marker guard passes (--markers --base main --strict)
  • 6-model consensus code review (Claude, GPT 5.2, Gemini 3.1, Kimi K2.5, MiniMax M2.5, GLM-5) — all approved

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective
  • New and existing tests pass locally

Summary by CodeRabbit

  • New Features

    • Updated MCP auto-discovery flow: discovered servers are surfaced via a notification and can be added by asking the assistant.
  • Bug Fixes

    • Added a capped retry limit for session retries.
    • Improved detection to skip GitHub Copilot/Models in Codespaces and Actions machine environments.
  • Documentation

    • Clarified MCP discovery and GitHub Actions/Codespaces provider behavior and setup guidance.
  • Chores

    • Added a Codespaces devcontainer and post-create setup script.
  • Tests

    • Added end-to-end and unit tests covering Codespaces/Actions and retry behavior.

Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai
Copy link

coderabbitai bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

Addresses issue #413 by adding a Codespaces devcontainer, gating GitHub provider auto-enablement in Codespaces/Actions when only machine-scoped tokens exist, capping session retry attempts at 5, and updating UI/docs to use mcp_discover instead of the non-existent /discover-and-add-mcps.

Changes

Cohort / File(s) Summary
Devcontainer Setup
​.devcontainer/devcontainer.json, ​.devcontainer/post-create.sh
Add Codespaces devcontainer (Node 22, Bun 1.3.10, git, VS Code extensions) and post-create script that configures git identity and runs bun install with quick-start hints.
Provider Environment Gating
packages/opencode/src/provider/provider.ts
Detect Codespaces/Actions via env vars and skip auto-enabling github-models / github-copilot when provider envs consist solely of machine-scoped tokens (GITHUB_TOKEN, GH_TOKEN).
Retry Attempt Limiting
packages/opencode/src/session/retry.ts, packages/opencode/src/session/processor.ts
Add exported SessionRetry.RETRY_MAX_ATTEMPTS = 5 and enforce max attempts in session retry handling; log warning and set error state when exhausted.
MCP Discovery Workflow
docs/docs/configure/tools.md, docs/docs/reference/security-faq.md, packages/opencode/src/mcp/index.ts
Replace references to /discover-and-add-mcps with mcp_discover(action: "add") and update toast/documentation text to reflect non-auto-connected project-scoped MCPs surfaced via notification.
Tests — Providers & Retry
packages/opencode/test/provider/codespace-e2e.test.ts, packages/opencode/test/provider/provider.test.ts, packages/opencode/test/session/retry.test.ts
Add extensive e2e/unit tests covering Codespaces/Actions env behaviors, provider inclusion/exclusion, adversarial token/env cases, and retry max-attempt validation.
Changelog / Metadata
.github/meta/commit.txt
Update commit metadata describing Codespaces/Actions gating, retry cap, devcontainer addition, and tests; close #413.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰
In Codespaces snug where dev lights gleam,
I hop and patch the retry stream.
Tokens gated, phantom commands gone,
Devcontainers set — the build hops on.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the three main bug fixes: skipping GITHUB_TOKEN auto-enable in Codespaces, capping retries, and fixing the phantom command reference.
Description check ✅ Passed The description comprehensively covers what changed and why, includes detailed test verification, and follows the repository template with all sections completed.
Linked Issues check ✅ Passed The PR fulfills all four coding objectives from issue #413: prevents github-models/github-copilot auto-enable in Codespaces, caps retry attempts at 5, fixes the phantom command toast message, and adds devcontainer configuration.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the objectives in #413. No unrelated modifications were introduced beyond the four bug fixes and devcontainer setup.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/codespaces-github-models-rate-limit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gitguardian
Copy link

gitguardian bot commented Mar 23, 2026

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@anandgupta42 anandgupta42 force-pushed the fix/codespaces-github-models-rate-limit branch 2 times, most recently from 3c83332 to e2253d3 Compare March 23, 2026 22:36
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
packages/opencode/test/provider/codespace-e2e.test.ts (1)

38-45: Let tmpdir own the config setup here.

withEnv() and the two standalone tmp dirs only write opencode.json, so using the fixture’s config option will simplify the setup and keep these tests on the repo’s standard path.

Suggested refactor
-  await using tmp = await tmpdir({
-    init: async (dir) => {
-      await Bun.write(
-        path.join(dir, "opencode.json"),
-        JSON.stringify({ $schema: "https://altimate.ai/config.json" }),
-      )
-    },
-  })
+  await using tmp = await tmpdir({
+    config: {
+      $schema: "https://altimate.ai/config.json",
+    },
+  })

As per coding guidelines, "Use the config option to write an opencode.json configuration file when tests need project configuration".

Also applies to: 228-238, 254-269

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/provider/codespace-e2e.test.ts` around lines 38 - 45,
The test manually writes opencode.json inside the tmpdir init callback; instead
use the tmpdir fixture's config option so the fixture owns config setup—replace
the tmpdir({... init: async (dir) => await Bun.write(path.join(dir,
"opencode.json"), ... ) }) usage with tmpdir({ config: { $schema:
"https://altimate.ai/config.json" } }) (and apply the same change for the other
tmpdir instances referenced around the test and lines 228-238, 254-269),
removing the explicit Bun.write and leaving withEnv() and other fixtures to
operate on the repo-standard config path.
packages/opencode/test/provider/provider.test.ts (1)

2288-2297: Use tmpdir({ config }) for these new cases.

Each block only needs a minimal opencode.json, so the fixture can create it directly and remove the repeated Bun.write setup.

Suggested refactor
-  await using tmp = await tmpdir({
-    init: async (dir) => {
-      await Bun.write(
-        path.join(dir, "opencode.json"),
-        JSON.stringify({
-          $schema: "https://altimate.ai/config.json",
-        }),
-      )
-    },
-  })
+  await using tmp = await tmpdir({
+    config: {
+      $schema: "https://altimate.ai/config.json",
+    },
+  })

As per coding guidelines, "Use the config option to write an opencode.json configuration file when tests need project configuration".

Also applies to: 2312-2321, 2338-2347

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/provider/provider.test.ts` around lines 2288 - 2297,
The test uses tmpdir with an init callback that writes a minimal opencode.json
via Bun.write; replace that pattern by passing the config option to tmpdir
instead (e.g., tmpdir({ config: { $schema: "https://altimate.ai/config.json" }
})) so the fixture creates the opencode.json automatically; update the three
blocks that currently call tmpdir({ init: async (dir) =>
Bun.write(path.join(dir, "opencode.json"), ...) }) to use tmpdir({ config: { ...
} }) and remove the init/Bun.write code (refer to the tmpdir call in the failing
tests and the opencode.json payload to copy the minimal config).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/docs/reference/security-faq.md`:
- Line 171: Update the sentence about project-scoped MCP configs to reflect
actual behavior: they are auto-loaded by default (no per-server trust prompt)
controlled by the global flag auto_mcp_discovery, and the opt-out is the config
key experimental.auto_mcp_discovery: false; do not state they are "disabled by
default" or require explicit approval via mcp_discover—instead say they are
auto-loaded at startup and can be opted out with
experimental.auto_mcp_discovery: false.

In `@packages/opencode/src/provider/provider.ts`:
- Line 1088: Add "github-copilot-enterprise" to the skipGithubProviders set so
the enterprise variant is also excluded from the env-based auto-enable path;
update the declaration of skipGithubProviders (the Set created as const
skipGithubProviders = new Set([...])) to include "github-copilot-enterprise"
alongside "github-models" and "github-copilot" to prevent Codespaces/Actions
from auto-enabling the enterprise provider using GITHUB_TOKEN/GH_TOKEN.
- Line 1086: The check for machine CI (const isMachineEnv) incorrectly treats
any non-empty CODESPACES or GITHUB_ACTIONS value as true; change it to test for
the literal string "true" (e.g., env["CODESPACES"] === "true" ||
env["GITHUB_ACTIONS"] === "true") so that values like "false" don't enable the
flag; update the isMachineEnv assignment in provider.ts to use strict equality
against "true" for both env["CODESPACES"] and env["GITHUB_ACTIONS"] (referencing
the isMachineEnv variable and env map).

In `@packages/opencode/test/provider/codespace-e2e.test.ts`:
- Around line 125-135: The test "github-copilot is available outside Codespace
with GITHUB_TOKEN" currently makes no assertions; update the callback that calls
withEnv and Provider.list() to assert that providers includes the
"github-copilot" entry (e.g. providers["github-copilot"] is defined) and
optionally verify its source is "env" so the non-Codespace path cannot regress;
locate the assertion around the withEnv callback after the call to
Provider.list() and add expectations for providers["github-copilot"].

---

Nitpick comments:
In `@packages/opencode/test/provider/codespace-e2e.test.ts`:
- Around line 38-45: The test manually writes opencode.json inside the tmpdir
init callback; instead use the tmpdir fixture's config option so the fixture
owns config setup—replace the tmpdir({... init: async (dir) => await
Bun.write(path.join(dir, "opencode.json"), ... ) }) usage with tmpdir({ config:
{ $schema: "https://altimate.ai/config.json" } }) (and apply the same change for
the other tmpdir instances referenced around the test and lines 228-238,
254-269), removing the explicit Bun.write and leaving withEnv() and other
fixtures to operate on the repo-standard config path.

In `@packages/opencode/test/provider/provider.test.ts`:
- Around line 2288-2297: The test uses tmpdir with an init callback that writes
a minimal opencode.json via Bun.write; replace that pattern by passing the
config option to tmpdir instead (e.g., tmpdir({ config: { $schema:
"https://altimate.ai/config.json" } })) so the fixture creates the opencode.json
automatically; update the three blocks that currently call tmpdir({ init: async
(dir) => Bun.write(path.join(dir, "opencode.json"), ...) }) to use tmpdir({
config: { ... } }) and remove the init/Bun.write code (refer to the tmpdir call
in the failing tests and the opencode.json payload to copy the minimal config).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3e25d8cf-2741-4ca2-8577-ed5b20695266

📥 Commits

Reviewing files that changed from the base of the PR and between 4c01aac and 389ef51.

📒 Files selected for processing (12)
  • .devcontainer/devcontainer.json
  • .devcontainer/post-create.sh
  • .github/meta/commit.txt
  • docs/docs/configure/tools.md
  • docs/docs/reference/security-faq.md
  • packages/opencode/src/mcp/index.ts
  • packages/opencode/src/provider/provider.ts
  • packages/opencode/src/session/processor.ts
  • packages/opencode/src/session/retry.ts
  • packages/opencode/test/provider/codespace-e2e.test.ts
  • packages/opencode/test/provider/provider.test.ts
  • packages/opencode/test/session/retry.test.ts

@anandgupta42 anandgupta42 force-pushed the fix/codespaces-github-models-rate-limit branch 2 times, most recently from b8cb0bd to 2a9d1ac Compare March 24, 2026 00:36
…x phantom command

Closes #413

- Skip auto-enabling `github-models` and `github-copilot` providers in
  machine environments (Codespaces: `CODESPACES=true`, GitHub Actions:
  `GITHUB_ACTIONS=true`) when only machine-scoped tokens (`GITHUB_TOKEN`,
  `GH_TOKEN`) are available. The Codespace/Actions token lacks
  `models:read` scope needed for GitHub Models API.
- Cap retry attempts at 5 (`RETRY_MAX_ATTEMPTS`) to prevent infinite
  retry loops. Log actionable warning when retries exhaust.
- Replace phantom `/discover-and-add-mcps` toast with actionable message.
- Add `.devcontainer/` config (Node 22, Bun 1.3.10) for Codespaces.
- Add 32 adversarial e2e tests covering full Codespace/Actions env
  simulation, `GH_TOKEN`, token variations, config overrides, retry bounds.
- Update docs to reference `mcp_discover` tool.
@anandgupta42 anandgupta42 force-pushed the fix/codespaces-github-models-rate-limit branch from 2a9d1ac to 2b2d41c Compare March 24, 2026 00:52
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/opencode/test/provider/provider.test.ts (1)

2286-2333: Good test coverage for the core Codespaces gating scenarios.

The tests correctly verify:

  1. github-models exclusion when CODESPACES=true with only GITHUB_TOKEN
  2. github-models inclusion when GITHUB_TOKEN is set outside machine environments
  3. github-copilot exclusion in Codespaces

The defensive Env.remove() calls in test 2 (lines 2308-2309) are good practice to prevent CI environment leakage.

Consider adding tests for these additional scenarios (or confirm they're covered in codespace-e2e.test.ts):

  • GITHUB_ACTIONS=true environment detection
  • github-copilot-enterprise provider exclusion
  • Mixed token scenario (e.g., GITHUB_TOKEN + custom COPILOT_API_KEY) where the provider should NOT be skipped
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/provider/provider.test.ts` around lines 2286 - 2333,
Add tests covering the missing Codespaces/CI scenarios: create new tests using
Instance.provide/tmpdir that (1) set Env.set("GITHUB_ACTIONS","true") with only
GITHUB_TOKEN and assert Provider.list() excludes
"github-models"/"github-copilot", (2) set a machine env and verify exclusion of
"github-copilot-enterprise", and (3) set both Env.set("GITHUB_TOKEN","...") and
a custom COPILOT_API_KEY (or similar) and assert the relevant provider is NOT
skipped; reuse the same test pattern and helpers (Instance.provide, tmpdir,
Env.set/Env.remove, Provider.list) and add assertions mirroring the existing
tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/opencode/test/provider/provider.test.ts`:
- Around line 2286-2333: Add tests covering the missing Codespaces/CI scenarios:
create new tests using Instance.provide/tmpdir that (1) set
Env.set("GITHUB_ACTIONS","true") with only GITHUB_TOKEN and assert
Provider.list() excludes "github-models"/"github-copilot", (2) set a machine env
and verify exclusion of "github-copilot-enterprise", and (3) set both
Env.set("GITHUB_TOKEN","...") and a custom COPILOT_API_KEY (or similar) and
assert the relevant provider is NOT skipped; reuse the same test pattern and
helpers (Instance.provide, tmpdir, Env.set/Env.remove, Provider.list) and add
assertions mirroring the existing tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 12b8d5dc-492f-49ee-a106-c525e0971731

📥 Commits

Reviewing files that changed from the base of the PR and between 389ef51 and 2b2d41c.

📒 Files selected for processing (14)
  • .devcontainer/devcontainer.json
  • .devcontainer/post-create.sh
  • .github/meta/commit.txt
  • docs/docs/configure/providers.md
  • docs/docs/configure/tools.md
  • docs/docs/reference/security-faq.md
  • docs/docs/usage/github.md
  • packages/opencode/src/mcp/index.ts
  • packages/opencode/src/provider/provider.ts
  • packages/opencode/src/session/processor.ts
  • packages/opencode/src/session/retry.ts
  • packages/opencode/test/provider/codespace-e2e.test.ts
  • packages/opencode/test/provider/provider.test.ts
  • packages/opencode/test/session/retry.test.ts
✅ Files skipped from review due to trivial changes (6)
  • packages/opencode/src/mcp/index.ts
  • docs/docs/usage/github.md
  • .devcontainer/post-create.sh
  • docs/docs/reference/security-faq.md
  • .devcontainer/devcontainer.json
  • .github/meta/commit.txt
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/opencode/test/session/retry.test.ts
  • packages/opencode/src/session/retry.ts
  • packages/opencode/src/session/processor.ts
  • docs/docs/configure/tools.md
  • packages/opencode/test/provider/codespace-e2e.test.ts

@anandgupta42 anandgupta42 merged commit 966f43c into main Mar 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codespaces: GitHub Models rate limiting and phantom /discover-and-add-mcps command

1 participant