Skip to content

Compile emits invalid lock file when a prompt chunk starts with an indented line (bare literal block scalar) #76963

Done

Description

@Etienne-M

Summary

gh aw compile can generate an invalid .lock.yml when a prompt chunk happens to begin with an indented line (for example the continuation line of a Markdown list item). The prompt content is emitted as a bare | literal block scalar whose first line is more indented than the following lines, so YAML ends the scalar early and the lock file no longer parses.

Whether it triggers depends only on where the ~20.9 KB chunk boundary falls, so it appears or disappears whenever the prompt text changes.

Version

gh aw version v1.2.2 (also reproduced by reading the v1.2.2 source, see "Analysis").

Reproduction

Self-contained, uses only generic content:

#!/usr/bin/env bash
set -euo pipefail
dir=$(mktemp -d) && cd "$dir" && git init -q && mkdir -p .github/workflows

{
cat <<'FM'
---
on:
  workflow_dispatch:
engine: copilot
inlined-imports: true
permissions:
  contents: read
---

# Guidelines

xxxxx

FM
for i in $(seq 1 300); do
  echo "$i. Step $i: do the thing described in this step carefully."
  echo "   Continuation text for step $i, indented under the list item."
done
} > .github/workflows/repro.md

gh aw compile repro --no-check-update

The xxxxx line only shifts the byte offsets so that the first chunk boundary (maxChunkSize = 20900 in splitContentIntoChunks) lands on an indented continuation line. Without it, or with a different amount of padding, the boundary can land on an unindented line and the compile succeeds.

inlined-imports: true is used only so that the body is inlined and chunked in a single file; the same happens for any inlined imported Markdown (e.g. an import with with: inputs).

Actual result

✗ repro.md (1 error(s)):
  • 1. .github/workflows/repro.md:1:1: error: cannot parse generated Actions AST for linting
✗ compilation failed

With --no-lint the compiler's own YAML validation reports the real problem:

generated lock file is not valid YAML: [639:13] value is not allowed in this context. map key-value is pre-defined
  637 |           GH_AW_PROMPT_CONTENT_0006: |
  638 |                Continuation text for step 144, indented under the list item.
> 639 |             145. Step 145: do the thing described in this step carefully.
  640 |                Continuation text for step 145, indented under the list item.

Note that with --no-lint the invalid repro.lock.yml is still written to disk even though the compile reports failure; it fails to parse with other YAML parsers too (e.g. Ruby Psych: did not find expected key while parsing a block mapping). Without --no-lint no lock file is written.

Expected result

A valid lock file whose GH_AW_PROMPT_CONTENT_* values round-trip to the original prompt text, regardless of where a chunk boundary falls.

Analysis

This is from reading the v1.2.2 source, not from instrumenting the library:

  1. generateUnifiedPromptCreationStep (pkg/workflow/unified_prompt_step.go) writes each chunk through writeYAMLEnv, i.e. as a safely quoted %q string. At this point the YAML is valid.
  2. The step is later re-marshaled with goccy/go-yaml using DefaultMarshalOptions (pkg/workflow/yaml_options.go), which includes yaml.UseLiteralStyleIfMultiline(true). Every multiline string becomes a literal block scalar.
  3. For a chunk whose first line has leading spaces, the emitted header is a bare | (no explicit indentation indicator such as |2). YAML infers the block indent from the first non-empty line, so subsequent lines with less indentation terminate the scalar and break the mapping.

Suggested fix

Preferably in the marshal step, since it applies to every multiline value and does not depend on chunking:

  • When a multiline string's first line starts with a space or tab (or the string starts with a newline), emit it as a double-quoted scalar instead of a literal block (the existing %q form is already correct), or emit an explicit indentation indicator.
  • Add a round-trip check after generating the step: parse the output and compare each GH_AW_PROMPT_CONTENT_* value with the intended text, and fail compilation (without writing the lock file) on mismatch. This would catch the whole class of bug, not just this case.

Approaches I would avoid: trimming the first line of each chunk (changes the prompt; indentation is meaningful in nested Markdown lists) and adjusting chunk boundaries to avoid indented lines (hides the bug until the next edit shifts a boundary).

Workaround

Pin the CLI to a version that produces a valid file for the given prompt, or change the prompt text so the boundary no longer lands on an indented line (fragile).

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions