Skip to content

patch tool: await keyword corruption in TypeScript/TSX files #4451

@AxDSan

Description

@AxDSan

Bug Description

The patch tool intermittently corrupts the await keyword when applying changes to TypeScript/TSX files, replacing it with ***.

Reproduction

This has occurred multiple times in our Next.js project when patching React components:

Example 1

File: apps/web/app/[locale]/dashboard/blog/new/page.tsx

  • Before patch: const token = await getToken();
  • After patch: const token=*** getToken();

Example 2

File: apps/web/app/[locale]/dashboard/blog/[id]/edit/page.tsx

  • Before patch: const token = await getToken();
  • After patch: const token=*** getToken();

Both instances:

  • Used the same patch tool with mode: replace
  • Targeted lines containing await keyword
  • Resulted in corrupted syntax that broke the build

Environment

  • OS: Linux (containerized environment)
  • File types affected: .tsx, .ts
  • Hermes Agent version: Latest (as of March 2026)
  • Project: Next.js 14 + TypeScript

Impact

  • Silent failures: The patch reports success, but the file is corrupted
  • Build breaks: TypeScript compilation fails with cryptic errors
  • Time loss: Requires manual investigation and fix

Workaround

After any patch operation on files containing await, manually verify the file content:

# Check for corruption
grep -n "\*\*\*" apps/web/app/**/*.tsx

Suggested Fix

The patch tool should:

  1. Validate output is valid TypeScript/JavaScript syntax before reporting success
  2. Add a pre-flight check for common keyword corruption patterns
  3. Consider using AST-aware patching for code files instead of text replacement

Additional Context

The corruption appears related to how the tool handles special characters or encoding around async/await keywords. This is a critical reliability issue for automated code editing workflows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High — major feature broken, no workaroundcomp/agentCore agent loop, run_agent.py, prompt buildertool/fileFile tools (read, write, patch, search)type/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions