Skip to content

Conversation

@jonathanpopham
Copy link
Collaborator

@jonathanpopham jonathanpopham commented Jan 23, 2026

Summary

Internal errors now include reportable: true, repo, and a suggestion that guides agents to file an issue, fork the repo, or open a PR with a fix. This surfaces the intent in the agent's conversation context without requiring gh CLI or auto-filing machinery.

What's in the error response

{
  "error": {
    "type": "internal_error",
    "code": "UNKNOWN_ERROR",
    "message": "An unexpected error occurred.",
    "recoverable": false,
    "reportable": true,
    "repo": "supermodeltools/mcp",
    "suggestion": "This may be a bug in the MCP server. You can help by opening an issue at https://github.com/supermodeltools/mcp/issues with the error details, or fork the repo and open a PR with a fix."
  }
}

Which errors are reportable

Code Status Reportable
SERVER_ERROR 5xx Yes (with retry advice)
API_ERROR Unhandled 5xx Yes
ZIP_CREATION_FAILED Yes
UNKNOWN_ERROR Yes
INVALID_API_KEY 401 No
FORBIDDEN 403 No
RATE_LIMITED 429 No
All other client errors No

Additional fixes

  • 4xx in the default case is now validation_error, not internal_error
  • details.directory uses basename() to avoid leaking local paths
  • SERVER_ERROR restores retry advice alongside the reporting link
  • Suggestion constants extracted (DRY)

Test plan

  • 97 tests pass (16 new for reportable fields)
  • TypeScript type check passes
  • Verifies reportable present on all internal errors
  • Verifies reportable absent on all client errors (auth, 403, 404, 429, timeout, network, 4xx)
  • Verifies path sanitization in error details

Closes #74

Summary by CodeRabbit

  • New Features

    • Error responses now include explicit reportable flags, repository/reporting suggestions, and clearer recovery guidance; ZIP/graph failures surface sanitized, user-friendly details.
  • Bug Fixes

    • Improved classification and messages for server, auth, rate-limit, not-found, timeout, and network errors to better guide recovery or reporting.
  • Tests

    • Expanded test coverage validating reportable metadata, suggestions, and sanitized failure details.
  • Documentation

    • Added guidance on error handling and reporting for maintainers.

✏️ Tip: You can customize this high-level summary in your review settings.

When the MCP server encounters an internal_error, it now automatically
files a GitHub issue on supermodeltools/mcp with reproduction context
(error type, code, message, details, platform info).

Deduplication:
- Session-level: same error code won't file twice per process lifetime
- GitHub-level: searches for existing open issues before creating

Uses gh CLI (fire-and-forget, non-blocking). If gh is unavailable or
fails, the error response is unaffected.

Closes #74
@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Walkthrough

Adds optional reportable and repo fields to StructuredError, exports and extends classifyApiError to populate reporting metadata/suggestions for server/internal/ZIP failures, updates tests to validate reportable behavior, and documents reportable vs recoverable error handling in server docs. (≤50 words)

Changes

Cohort / File(s) Summary
Types
src/types.ts
Added optional fields reportable?: boolean and repo?: string to StructuredError.
Error handling & helper export
src/tools/create-supermodel-graph.ts
Exported classifyApiError; enriched classification to attach reportable, repo: 'https://github.com/supermodeltools/mcp.git', and suggestion for internal/server/HTTP 5xx and ZIP creation failures; normalized ZIP details.directory to basename(directory); extended reporting metadata across non-object, response/request, and specific-status branches.
Tests
src/tools/create-supermodel-graph.test.ts
Imported classifyApiError; added test suites asserting presence/absence of reportable/repo across internal, server, API, client, and ZIP error cases.
Docs / server guidance
src/server.ts
Added documentation block describing error.recoverable vs error.reportable, how to use error.repo to search or file issues, and guidance for filing issues or PRs.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • greynewell
  • robotson

Poem

🐞 When a zip fails or servers sigh,
A little flag points where bugs hide.
Repo and hint light up the way,
File an issue — save the day. 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a reportable flag and repo metadata to internal errors, which is the core objective of this PR.
Linked Issues check ✅ Passed The PR implements all requirements from issue #74: structured reportable/repo/suggestion metadata on internal errors, restricted to server-side failures, with proper 4xx/5xx differentiation and test coverage.
Out of Scope Changes check ✅ Passed All changes align with the stated objectives: error classification, type definitions, test coverage, and documentation are directly scoped to implementing agent self-reporting for internal errors.

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

✨ Finishing touches
  • 📝 Generate docstrings

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

@jonathanpopham jonathanpopham marked this pull request as draft January 23, 2026 15:58
[auto-report] unknown-error: ... instead of [auto-report] UNKNOWN_ERROR: ...
Replace auto-filing machinery with simple metadata on error responses.
Internal errors now include reportable: true, repo, and a suggestion
with a link to the issues page. Agents can choose to file an issue
based on their own permissions and context.

Removes error-reporter.ts (auto-filing via gh CLI) in favor of
surfacing intent in the conversation context.

Closes #74
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: 2

🤖 Fix all issues with AI agents
In `@src/tools/create-supermodel-graph.ts`:
- Around line 371-379: The error object zipError currently includes the full
local path in details: { directory }, which can leak usernames/paths; change the
code that builds zipError (and any related reporting before
reportError/asErrorResult) to replace directory with a sanitized value (e.g.,
use path.basename(directory) or a short hash like
crypto.createHash('sha256').update(directory).digest('hex').slice(0,8')) and
store it as sanitizedDirectory or directoryIdentifier in the details field so
reports no longer contain full local paths (update references around zipError,
reportError, and asErrorResult accordingly).

In `@src/utils/error-reporter.ts`:
- Around line 15-42: The current reportError function marks errors as seen by
calling reportedThisSession.add(error.code) before attempting ghExec, which
means transient failures will permanently suppress retries; move the
deduplication step so the code only adds error.code to reportedThisSession after
a successful check/create (i.e., after confirming no existing issue or after
successfully creating the issue), or alternatively perform the add only on
success and remove/error-roll back reportedThisSession in the catch block;
adjust logic inside reportError around the ghExec calls (and keep logger,
buildIssueBody, REPO, and ghExec usage unchanged) so failures do not leave
reportedThisSession containing the code.

…ests

- SERVER_ERROR suggestion now includes explicit retry guidance alongside
  the issue-reporting link, since this error is marked recoverable: true
- Export classifyApiError for direct testing
- Add 12 tests covering reportable metadata:
  - Internal errors (UNKNOWN_ERROR, SERVER_ERROR, API_ERROR) include
    reportable: true, repo, and suggestion with issues link
  - Client errors (auth, forbidden, not_found, rate_limit, timeout,
    network) do NOT include reportable flag
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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/tools/create-supermodel-graph.ts (1)

904-913: Don’t mark unhandled 4xx as reportable.
Right now HTTP 400/422 land in the default branch and get reportable: true, which conflicts with the “server-side only” rule. Example: a bad request should not trigger bug reporting. Consider gating reportable (and the bug-report suggestion) to status >= 500.

🛠️ Example fix (gate reportable to server errors)
-      default:
-        return {
-          type: 'internal_error',
-          message: `API request failed with HTTP ${status}.`,
-          code: 'API_ERROR',
-          recoverable: false,
-          reportable: true,
-          repo: 'supermodeltools/mcp',
-          suggestion: 'This may be a bug. If you want our team to look into it, open an issue at https://github.com/supermodeltools/mcp/issues with the error details.',
-          details: { httpStatus: status },
-        };
+      default: {
+        const isServerError = status >= 500;
+        return {
+          type: isServerError ? 'internal_error' : 'validation_error',
+          message: `API request failed with HTTP ${status}.`,
+          code: 'API_ERROR',
+          recoverable: false,
+          reportable: isServerError ? true : undefined,
+          repo: isServerError ? 'supermodeltools/mcp' : undefined,
+          suggestion: isServerError
+            ? 'This may be a bug. If you want our team to look into it, open an issue at https://github.com/supermodeltools/mcp/issues with the error details.'
+            : 'Check the request parameters and base URL configuration.',
+          details: { httpStatus: status },
+        };
+      }
🤖 Fix all issues with AI agents
In `@src/tools/create-supermodel-graph.ts`:
- Around line 375-377: The suggestion text hardcodes "open an issue" and is
duplicated in multiple places (e.g., the object with properties
reportable/repo/suggestion in create-supermodel-graph.ts and the other
occurrences mentioned); extract a shared constant (e.g.,
REPORT_ISSUE_AND_PR_MSG) that includes both "open an issue" and fork/PR
contribution guidance, then replace the repeated literal suggestion strings with
that constant (update any exports/imports if used across modules). Ensure you
update all instances referenced (the current occurrence and the repeats at the
other locations) so the message is consistent and DRY while preserving repo
context in the surrounding object (reportable/repo).
♻️ Duplicate comments (1)
src/tools/create-supermodel-graph.ts (1)

378-378: Sanitize directory before putting it in details.
Full local paths can leak if an agent copies the error details into a public issue. basename(directory) (or a short hash) is safer.

🔧 Example fix
-      details: { directory, errorType: error.name || 'Error' },
+      details: { directory: basename(directory), errorType: error.name || 'Error' },

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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/tools/create-supermodel-graph.ts (1)

903-913: API_ERROR marks 4xx client failures as reportable.
Line 903-913 applies reportable: true to any unhandled HTTP status, so 400/422/etc get flagged as server bugs. That conflicts with the requirement to report only internal/server errors.

🔧 Suggested fix (gate reportable on 5xx)
-      default:
-        return {
-          type: 'internal_error',
-          message: `API request failed with HTTP ${status}.`,
-          code: 'API_ERROR',
-          recoverable: false,
-          reportable: true,
-          repo: 'supermodeltools/mcp',
-          suggestion: 'This may be a bug. If you want our team to look into it, open an issue at https://github.com/supermodeltools/mcp/issues with the error details.',
-          details: { httpStatus: status },
-        };
+      default: {
+        const reportable = status >= 500;
+        return {
+          type: 'internal_error',
+          message: `API request failed with HTTP ${status}.`,
+          code: 'API_ERROR',
+          recoverable: reportable,
+          ...(reportable
+            ? {
+                reportable: true,
+                repo: 'supermodeltools/mcp',
+                suggestion: 'This may be a bug. If you want our team to look into it, open an issue at https://github.com/supermodeltools/mcp/issues with the error details.',
+              }
+            : {
+                suggestion: 'Check request parameters or base URL; this appears to be a client-side error.',
+              }),
+          details: { httpStatus: status },
+        };
+      }
♻️ Duplicate comments (1)
src/tools/create-supermodel-graph.ts (1)

371-378: Directory path still leaks into error details.
Line 371-378 keeps the full local path in details.directory, which can end up in filed issues. Please sanitize (e.g., basename or short hash).

🔧 Suggested fix (sanitize directory)
-      details: { directory, errorType: error.name || 'Error' },
+      details: { directory: basename(directory), errorType: error.name || 'Error' },

- Gate reportable on 5xx only (4xx is now validation_error, not reportable)
- Restore retry advice on SERVER_ERROR (recoverable: true needs retry guidance)
- Sanitize directory path in error details (basename only, no local path leak)
- Extract REPORT_REPO and REPORT_SUGGESTION constants (DRY)
- Update suggestion to include full loop: issue + fork + PR
- Add 4 tests: reportable present on internal errors, absent on client errors,
  path sanitization

Addresses CodeRabbit comments on PR #76.
@jonathanpopham
Copy link
Collaborator Author

Addressed all CodeRabbit findings + internal feedback

Pushed 98ec2cc:

CodeRabbit fixes:

  • 4xx not reportable: Default case now gates on status >= 500. Unhandled 4xx becomes validation_error without reportable/repo — only server errors trigger reporting.
  • Path sanitization: details.directory now uses basename(directory) — no more full local path leaks into potential issue reports.
  • DRY suggestion string: Extracted REPORT_REPO and REPORT_SUGGESTION constants.

Internal feedback fixes:

  • SERVER_ERROR retry advice restored: Suggestion now combines "Wait a few minutes and retry" with the reporting link. Matches recoverable: true.
  • Test coverage: 16 new tests (97 total) covering classifyApiError directly — verifies reportable present on all internal errors, absent on all client errors (auth, authz, 404, 429, timeout, network, 4xx).

Direction update:

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: 1

🤖 Fix all issues with AI agents
In `@src/tools/create-supermodel-graph.test.ts`:
- Around line 167-182: The test uses a platform-specific path and guards
assertions behind a conditional, causing flaky/quiet passes; update the test
that calls handler and mockClient.generateSupermodelGraph to (1) use a
platform-independent non-existent path (e.g., build one under os.tmpdir() via
path.join(os.tmpdir(), 'nonexistent-<random>') and ensure it does not exist
before calling handler) and (2) remove the surrounding if check so you assert
parsed.error.type === 'internal_error' first and then unconditionally check
parsed.error.reportable, parsed.error.repo and parsed.error.suggestion contents;
reference the handler invocation and parsed.error.type when making these
changes.
🧹 Nitpick comments (1)
src/tools/create-supermodel-graph.ts (1)

896-905: SERVER_ERROR suggestion has redundant guidance.

The REPORT_SUGGESTION constant already contains the full "open an issue at https://github.com/supermodeltools/mcp/issues ... or fork the repo and open a PR" guidance. But here in the SERVER_ERROR case (lines 903), you're using a custom suggestion string that includes similar wording. This means:

  1. You have two places to update if the URL changes
  2. The SERVER_ERROR suggestion includes extra retry advice which is good, but duplicates the issue/PR guidance

Consider composing the suggestion to avoid duplication:

♻️ Optional: Compose suggestion from constant
         return {
           type: 'internal_error',
           message: `Supermodel API server error (HTTP ${status}).`,
           code: 'SERVER_ERROR',
           recoverable: true,
           reportable: true,
           repo: REPORT_REPO,
-          suggestion: 'The API may be temporarily unavailable. Wait a few minutes and retry. If persistent, open an issue at https://github.com/supermodeltools/mcp/issues with the error details, or fork the repo and open a PR with a fix.',
+          suggestion: `The API may be temporarily unavailable. Wait a few minutes and retry. If persistent, ${REPORT_SUGGESTION.toLowerCase()}`,
           details: { httpStatus: status },
         };

Agents now receive guidance on connect telling them to check
error.reportable and error.repo, and if they have GitHub access,
to file an issue or fork + PR a fix.

This bridges the gap between the structured error metadata and
agent action — without this instruction, agents have no protocol-
level reason to act on the reportable flag.
Tell agents to search existing issues before filing to avoid
duplicate reports when multiple agents hit the same bug.
Replace flaky handler tests that depended on /dev/null (Unix-only,
conditional assertions) with deterministic handler-level checks.
The reportable field coverage is fully handled by the classifyApiError
unit tests which don't depend on filesystem state.

Addresses CodeRabbit comment on PR #76.
@jonathanpopham jonathanpopham changed the title feat: auto-file GitHub issues on internal errors feat: add reportable flag for agents and repo metadata to internal errors Jan 23, 2026
@jonathanpopham jonathanpopham marked this pull request as ready for review January 23, 2026 16:46
@jonathanpopham jonathanpopham self-assigned this Jan 23, 2026
Change repo from "supermodeltools/mcp" to
"https://github.com/supermodeltools/mcp.git" so agents can
clone/fork directly without guessing the hosting platform.
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: 1

🤖 Fix all issues with AI agents
In `@src/tools/create-supermodel-graph.ts`:
- Around line 906-915: The default branch currently marks isServerError (status
>= 500) as reportable but leaves recoverable: false and omits retry guidance;
update the default branch in src/tools/create-supermodel-graph.ts (the switch
handling HTTP status with variables isServerError and status) to set
recoverable: true when isServerError, and add the same retry suggestion/handling
used for the 500/502/503/504 case (include suggestion text like retrying or
exponential backoff) while still keeping reportable/repo/REPORT_SUGGESTION for
server errors.

Align the default branch with the explicit 500-504 cases: unhandled
5xx (507, 511, etc.) are now recoverable: true with retry guidance
in the suggestion. 4xx remains recoverable: false.

Addresses CodeRabbit comment on PR #76.
@greynewell greynewell merged commit e407711 into main Jan 23, 2026
2 checks passed
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.

Agent self-reporting capability on internal errors

3 participants