Skip to content

execute_code ignores the Code API artifact_truncation response field #556

Description

@usnavy13

Summary

The Code Interpreter API reports output files it detected but could not include in files[] through a top-level artifact_truncation object (LibreChat-AI/code-interpreter#198, shipped in #199). createCodeExecutionTool in src/tools/CodeExecutor.ts never reads it. When the sandbox drops generated files, the model is told nothing, the "Generated files" summary appended to the tool output undercounts, and the host application cannot surface the omission because the artifact does not carry the field either.

Server contract

type ArtifactTruncationReason = 'max_files' | 'depth' | 'size' | 'path' | 'unreadable';

interface ArtifactTruncation {
  code: 'artifact_truncated';
  reasons: Partial<Record<ArtifactTruncationReason, number>>;
  skipped: string[];        // up to 20 relative paths
  skipped_count: number;
}

// POST /exec response
{ session_id, files, artifact_truncation?, stdout, stderr, code, signal, message, status, wall_time }

Example response from an execution that carried 120 input files with the default SANDBOX_MAX_OUTPUT_FILES=50:

{
  "files": [ /* 50 entries */ ],
  "artifact_truncation": {
    "code": "artifact_truncated",
    "reasons": { "max_files": 70 },
    "skipped": ["report_070.csv", "report_068.csv", "..."],
    "skipped_count": 70
  }
}

Current behaviour

CodeExecutor.ts handles the sibling field artifact_delivery: it is normalized with normalizeArtifactDeliveryFailure, a warning is appended to the tool output with appendArtifactDeliveryWarning, and the normalized object is echoed in the artifact in both the with-files and no-files branches. There is no equivalent for artifact_truncation; the string does not appear anywhere in the repository. The response above produces a tool message and artifact describing 50 files with no indication that 70 more were written and dropped.

Per code-interpreter#198, generated outputs fill the cap first and inherited refs only take leftover slots, so in a conversation that already carries many files it is the newly generated outputs that get cut.

Impact

  • The model believes every file it wrote was delivered and tells the user so. It has no signal to write fewer files or bundle them.
  • The host cannot warn the user or log the omission.

Proposed change

Mirror the artifact_delivery handling:

  1. Add normalizeArtifactTruncation(value) alongside normalizeArtifactDeliveryFailure: require code === 'artifact_truncated', a non-negative integer skipped_count, a reasons map of non-negative integers keyed by the known reasons, and a skipped string array of at most 20 entries. Return undefined otherwise so a malformed marker cannot alter the tool output.

  2. Append a warning to the tool output ahead of the file summary, for example:

    Note: 70 output file(s) were written but not delivered (max_files: 70). Not delivered: report_070.csv, ... (20 of 70 shown). Write fewer files per execution or combine them into an archive.
    
  3. Echo the normalized object in the artifact as artifact_truncation in both branches so the host can render or log it.

  4. Add the optional field to the response types and cover: marker with and without files, unknown reason keys, malformed marker ignored, skipped longer than 20 entries.

Reproduction

  1. Upload more than 50 small files to one session via POST /upload/batch.
  2. Invoke execute_code with all of them in _injected_files and code that only lists /mnt/data.
  3. Compare the raw POST /exec response with the tool's content and artifact: the response carries artifact_truncation; the tool output and artifact do not.

Versions: @librechat/agents 3.9.1 (main at 7bb25ae shows the same), Code Interpreter API with #199 applied.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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