Skip to content

Limit response size for github_list_releases tool to prevent context overruns #83

@blinkagent

Description

@blinkagent

Problem

The github_list_releases tool can return excessively large responses that cause the model to exceed context limits, resulting in "Input is too long for requested model" errors in brand new chats.

Root Cause Analysis

When fetching releases with include_body_and_assets: true, the tool returns massive amounts of data. Testing with coder/coder:

  • 5 releases with bodies and assets = ~38KB of JSON
  • Each release has ~24 assets (download URLs, sizes, counts, etc.)
  • Release bodies can be ~1KB each (full changelogs)
  • Requesting 100 releases with full data could exceed 500KB+

The tool implementation at packages/github/src/tools.ts (line ~928) passes data through without any size limits:

list_releases: toolWithOctokit(({ octokit }) =>
  tool({
    inputSchema: z.object({
      owner: z.string(),
      repo: z.string(),
      page: z.number(),
      per_page: z.number(),  // No max limit!
      include_body_and_assets: z.boolean(),
    }),
    execute: async (args, opts) => {
      // ...
      return {
        releases: response.data.map((release) => ({
          // Full body returned, no truncation
          body: args.include_body_and_assets
            ? (release.body ?? undefined)
            : undefined,
          // ALL assets returned
          assets: args.include_body_and_assets
            ? release.assets.map((asset) => ({ ... }))
            : undefined,
        })),
      };
    },
  })
),

Proposed Solution

Modify the tool in packages/github/src/tools.ts:

  1. Cap per_page to a reasonable max (e.g., 10 releases)
  2. Truncate release bodies to ~500-1000 chars with a [truncated] indicator
  3. Limit assets per release to 5-10 most relevant ones
  4. Add response size indicator so the model knows data was limited
list_releases: toolWithOctokit(({ octokit }) =>
  tool({
    inputSchema: z.object({
      owner: z.string(),
      repo: z.string(),
      page: z.number(),
      per_page: z.number().max(10), // Hard cap
      include_body_and_assets: z.boolean(),
    }),
    execute: async (args, opts) => {
      const MAX_BODY_LENGTH = 500;
      const MAX_ASSETS = 5;
      
      const response = await (await octokit()).request(...);
      
      return {
        releases: response.data.map((release) => ({
          // ...
          body: args.include_body_and_assets && release.body
            ? release.body.length > MAX_BODY_LENGTH
              ? release.body.slice(0, MAX_BODY_LENGTH) + '... [truncated]'
              : release.body
            : undefined,
          assets: args.include_body_and_assets
            ? release.assets.slice(0, MAX_ASSETS).map((asset) => ({ ... }))
            : undefined,
          total_assets: release.assets.length, // Let model know if more exist
        })),
        _truncated: true, // Signal that limits were applied
      };
    },
  })
),

Related Context

This affects the Blink agent (coder/agents) which uses github.tools directly. The fix should be in the SDK (coder/blink) since that's where the tool is defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions