Skip to content

Harden get_pad_code schema, truncation, and environments - #212

Merged
adamtheturtle merged 3 commits into
mainfrom
agent/fix-pad-code-batch
Aug 20, 2026
Merged

Harden get_pad_code schema, truncation, and environments#212
adamtheturtle merged 3 commits into
mainfrom
agent/fix-pad-code-batch

Conversation

@adamtheturtle

@adamtheturtle adamtheturtle commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Document max_file_chars as a UTF-8 byte budget with a default of 200,000 and keep truncation markers inside that budget.
  • Mark malformed pad_environment_ids, missing/null nonbinary contents, and non-boolean binary flags as incomplete schema errors.
  • Keep binary files when the text budget is exhausted; sanitize paths/titles; verify environment response IDs and pad ownership; bound concurrent environment fetches.

Fixes #120
Fixes #121
Fixes #122
Fixes #123
Fixes #124
Fixes #125
Fixes #126
Fixes #127
Fixes #128
Fixes #129
Fixes #130
Fixes #131
Fixes #132
Fixes #133
Fixes #134
Fixes #175
Fixes #176
Fixes #177
Fixes #178
Fixes #179
Fixes #180

Test plan

  • swift test --filter PadCodeTests
  • CI green

Note

Medium Risk
Touches untrusted remote pad/environment payloads: path sanitization, ownership checks, and output size bounds. Logic is defensive and well-tested, but mistakes here could leak files across pads or blow MCP context.

Overview
Hardens get_pad_code so malformed API data cannot silently produce unbounded, incomplete, or cross-pad file lists.

Truncation and budgets: max_file_chars is documented as a UTF-8 byte cap (default 200k). The truncation marker now counts toward that budget. Binary files are kept after the text budget is exhausted.

Schema completeness: Malformed pad_environment_ids, missing/null nonbinary contents, non-boolean binary flags, missing file_contents, and unsafe paths/languages mark the payload incomplete with schema_errors. Environment responses must match the requested id and pad (pad_id).

Sanitization and fetch: Paths reject trailing slashes and empty components; flattened/suffixed names stay within path byte limits. Display fields strip Unicode format controls. Language→extension maps cover creatable pad languages. Environment fetches parse and drop each concurrent batch before the next so raw bodies are not retained all at once.

Reviewed by Cursor Bugbot for commit 0d33126. Bugbot is set up for automated code reviews on this repo. Configure here.

@adamtheturtle
adamtheturtle force-pushed the agent/fix-pad-code-batch branch from ef39740 to 6c3c3b3 Compare August 20, 2026 15:24

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 196cdff. Configure here.

Comment thread Sources/CoderPadToolCore/PadCode.swift
adamtheturtle and others added 3 commits August 20, 2026 16:38
Keep truncation markers inside the UTF-8 byte budget, document the
default per-file cap, surface malformed environment and file schema
problems as incomplete payloads, and verify environment ownership.

Co-authored-by: Cursor <cursoragent@cursor.com>
Split environment file assembly into a shared state object so body length
and parameter-count limits stay within CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@adamtheturtle
adamtheturtle force-pushed the agent/fix-pad-code-batch branch from 86ec1ac to 0d33126 Compare August 20, 2026 15:38
@adamtheturtle
adamtheturtle merged commit a33f3a1 into main Aug 20, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment