Skip to content

Update WritePromptTextToYAML to chunk large text into multiple heredoc blocks#1879

Merged
pelikhan merged 7 commits intomainfrom
copilot/update-compiler-function-helper
Oct 17, 2025
Merged

Update WritePromptTextToYAML to chunk large text into multiple heredoc blocks#1879
pelikhan merged 7 commits intomainfrom
copilot/update-compiler-function-helper

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 17, 2025

Update WritePromptTextToYAML to chunk text in groups of lines less than 20000 characters, with a maximum of 5 chunks.

Summary

Successfully implemented prompt text chunking to handle GitHub Actions step size limits (21KB per step).

Latest Changes (addressing PR feedback)

  • Generate separate steps for each chunk: The 21KB limit is per step, not per heredoc. Now generateStaticPromptStep creates multiple steps (one per chunk) instead of multiple heredocs in a single step.
  • Refactored architecture:
    • WritePromptTextToYAML now creates a single heredoc block
    • generateStaticPromptStep handles chunking and creates multiple steps
    • Each chunk gets its own step with proper naming (e.g., "part 1", "part 2")

Requirements Met ✅

  1. Chunks in groups of lines < 20000 characters: Each step contains < 20KB
  2. At most 5 chunks: Maximum of 5 steps generated
  3. All content preserved: When max chunks reached, remaining lines added to last step
  4. Data integrity verified: Tests ensure no lines or chunks are lost
  5. Separate steps per chunk: Each chunk is a separate GitHub Actions step

Implementation

Core Changes

  • generateStaticPromptStep (pkg/workflow/prompt_step_helper.go): Now chunks text and creates multiple steps (one per chunk)
  • WritePromptTextToYAML (pkg/workflow/sh.go): Simplified to write a single heredoc block
  • chunkLines (pkg/workflow/sh.go): Helper function to split lines into size-appropriate chunks
  • Constants (pkg/workflow/compiler.go): MaxPromptChunkSize (20000) and MaxPromptChunks (5)

Example Output

Old approach (incorrect - multiple heredocs in ONE step):

- name: Append instructions to prompt
  run: |
    cat >> $GITHUB_AW_PROMPT << 'EOF'
    [chunk 1...]
    EOF
    cat >> $GITHUB_AW_PROMPT << 'EOF'
    [chunk 2...]
    EOF

New approach (correct - separate steps):

- name: Append instructions to prompt (part 1)
  run: |
    cat >> $GITHUB_AW_PROMPT << 'EOF'
    [chunk 1...]
    EOF

- name: Append instructions to prompt (part 2)
  run: |
    cat >> $GITHUB_AW_PROMPT << 'EOF'
    [chunk 2...]
    EOF

Test Coverage

  • 26 comprehensive tests covering unit and integration scenarios
  • Updated tests to verify separate step generation for large text
  • All tests pass ✅

Verification

✅ Small text (< 1KB): Single step
✅ Medium text (~10KB): Single step  
✅ Large text (~25KB): 2 steps
✅ Very large text (~50KB): 3 steps
✅ Extremely large text (~120KB): 5 steps (max limit)
✅ Content preservation: All lines preserved
✅ Data integrity: No lines or chunks lost
✅ Separate steps: Each chunk is its own step

Testing Completed

  • ✅ All unit tests pass (26 test cases)
  • ✅ Data integrity verified
  • ✅ No regressions
  • ✅ Code formatted and linted
  • ✅ All workflows recompile successfully

Impact

  • No breaking changes: Small text continues to use single step
  • Enhanced reliability: Large prompt texts now handled correctly with separate steps
  • Correct implementation: Respects GitHub Actions 21KB limit per step
  • Performance: Minimal overhead
  • Maintainability: Well-tested with comprehensive coverage
Original prompt

Update the compiler function helper that appends prompt text to the prompt file: the helper should chunk the text prompt in groups of lines of less than 20000 characters (steps have a 21k limit). At most 5 chunks.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 4 commits October 17, 2025 18:36
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update compiler function helper to chunk prompt text Update WritePromptTextToYAML to chunk large text into multiple heredoc blocks Oct 17, 2025
Copilot AI requested a review from pelikhan October 17, 2025 18:56
Comment thread pkg/workflow/sh.go Outdated
// Each chunk is written as a separate heredoc to avoid GitHub Actions step size limits (21KB).
func WritePromptTextToYAML(yaml *strings.Builder, text string, indent string) {
yaml.WriteString(indent + "cat >> $GITHUB_AW_PROMPT << 'EOF'\n")
const maxChunkSize = 20000 // 20KB limit for each chunk
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot move constants to constants.go

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 8f1bb14. Moved maxChunkSize and maxChunks constants to the package-level const block in compiler.go as MaxPromptChunkSize and MaxPromptChunks.

Comment thread pkg/workflow/sh_integration_test.go
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot the limit is for "steps" so you need to generate a new step for each chunk.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 17, 2025

@copilot the limit is for "steps" so you need to generate a new step for each chunk.

Done in commit b5cd9f3. Now generating separate steps for each chunk instead of multiple heredocs in one step. The 21KB limit is per step, so each chunk now gets its own step with proper naming (e.g., "part 1", "part 2").

Example output:

- name: Append instructions (part 1)
  run: |
    cat >> $GITHUB_AW_PROMPT << 'EOF'
    [chunk 1...]
    EOF

- name: Append instructions (part 2)
  run: |
    cat >> $GITHUB_AW_PROMPT << 'EOF'
    [chunk 2...]
    EOF

Tested with 230KB input → creates 5 separate steps correctly.

@pelikhan pelikhan marked this pull request as ready for review October 17, 2025 19:25
@github-actions
Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

@pelikhan pelikhan merged commit f22ceed into main Oct 17, 2025
20 of 21 checks passed
@pelikhan pelikhan deleted the copilot/update-compiler-function-helper branch October 17, 2025 19:27
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.

2 participants