Skip to content

fix(#8604): env-data loader backtick resync and NUL export state - #8937

Open
fullsend-ai-coder[bot] wants to merge 2 commits into
mainfrom
agent/8604-env-loader-parser-fidelity
Open

fullsend-ai-coder[bot] wants to merge 2 commits into
mainfrom
agent/8604-env-loader-parser-fidelity

Conversation

@fullsend-ai-coder

Copy link
Copy Markdown
Contributor

Summary

Fixes two parser fidelity bugs in the .env data loader (internal/runtime/env_data.go), both follow-ups from the #8591 review. When a statement is rejected, the parser now skips a backtick span that runs across lines as one unit. A value dropped for a NUL byte no longer leaves its name marked for export.

Related Issue

#8604 (follow-up tracker: #8575)

Changes

  • Backtick resync: skip_statement() now handles backticks. A backtick opens a span, whether it appears unquoted, inside double quotes or inside $(...), and only an unescaped backtick closes it. Quotes inside the span do not open a value. An unterminated span still falls back to the line end, the same as other quotes.
  • NUL value export state: assign() now reports whether it accepted the value, and statement() marks the name exported only when it did. Before this fix, A=private followed by export A='x<NUL>y' kept private but exported it.
    • A later bare export NAME also skips a name whose last assignment was dropped for a NUL byte.
    • A later accepted assignment clears that state, so the name can be exported again.
  • Updated the grammar doc comment to cover both behaviours.
  • Regenerated the codex launch golden files (testdata/codex/golden/*.txt), which embed the loader script. The diff there is only the script change.

Testing

  • Tests added/updated for new or modified logic
    • TestEnvDataLoad_NulValueKeepsExportState: an earlier value stays a non-exported shell variable after a dropped NUL value, including through a later bare export. A later accepted value is exported as usual.
    • TestEnvDataLoad_RejectedBacktickStatementSkippedWhole: covers multi-line backticks unquoted, inside double quotes and with an escaped backtick, plus the fallback for an unterminated backtick.
    • Both tests failed before the fix and pass after it. go test ./internal/runtime/... passes.
  • make lint: could not run, because pre-commit could not fetch its remote hook repos (TLS failure in the sandbox). I ran gofmt, go vet ./... and the whitespace, end-of-file and line-ending checks directly, and they passed. golangci-lint is not installed in the sandbox.
  • go test ./internal/cli/... has failures that also occur on main in this sandbox: the fetchserver tests can't dial out, and TestPostScriptEnv_* fails because FULLSEND_OUTPUT_SCHEMA is set in the environment. They are unrelated to this change.

Checklist

  • PR title follows Conventional Commits (correct type, ! for breaking changes)
  • Commits are signed off (DCO) — not applicable: this is an autonomous bot commit, which is exempt

🤖 Generated with Claude Code


Closes #8604

Post-script verification

  • Branch is not main/master (agent/8604-env-loader-parser-fidelity)
  • Secret scan passed (gitleaks — 8b8c75bf5d3ffa22c3b20ff7d96be17835c0688a..HEAD)
  • PR body secret scan passed (gitleaks — no-git)
  • Final PR description secret scan passed (gitleaks — no-git)

Two parser fidelity follow-ups from the #8591 review in the .env
data loader (internal/runtime/env_data.go):

- skip_statement() tracked quotes and ${...}/$(...) but not
  backticks, so a rejected statement with a backtick command
  substitution spanning lines resynced inside it and read its inner
  lines as statements. Backticks now open a span (unquoted, inside
  double quotes or inside $(...)) that only an unescaped backtick
  closes; an unterminated span still falls back to the line end.
- statement() marked a name exported after assign() whether or not
  assign() accepted the value, so `A=private` then
  `export A='x<NUL>y'` kept `private` but exported it. assign() now
  reports acceptance and the export is recorded only on success. A
  name whose last assignment was dropped for a NUL byte is also not
  exported by a later bare `export NAME`; a later accepted
  assignment clears that state.

Adds a test for each, and regenerates the codex launch golden files,
which embed the loader script.

Note: pre-commit could not fetch its remote hook repos (TLS failure
in the sandbox); go-fmt, go-vet, whitespace, EOF and line-ending
checks were run directly and passed. golangci-lint is not installed.

Closes #8604
@fullsend-ai-review

fullsend-ai-review Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 12:09 PM UTC · Completed 12:16 PM UTC

Commit: 479d783 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.54

@fullsend-ai-review fullsend-ai-review Bot added the risk/moderate PR risk: moderate label Oct 30, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

<!-- fullsend:risk-assessment -->
Risk Assessment: moderate (2/5)

Details

Moderate risk for a tightly scoped runtime loader bug fix with full issue alignment and test coverage, elevated from low by high recent commit churn in runtime files and lack of a feature flag rollback mechanism.

Previous run

<!-- fullsend:risk-assessment -->
Risk Assessment: moderate (2/5)

Details

Moderate risk for a tightly scoped runtime loader bug fix with full issue alignment and test coverage, elevated from low by high recent commit churn in runtime files and lack of a feature flag rollback mechanism.

@fullsend-ai-review

fullsend-ai-review Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review

Findings

Low

  • [edge-case] internal/runtime/env_data.go:362 — The new comment branch in skip_statement treats an escaped space before # as a token boundary. For .env content like export X=$(printf x / export INSIDE=1 / printf \\ #) / export KEEP=1, the # is a literal argument character, not a comment. The branch skips the closing ), reaches EOF with a non-empty stack, and resyncs at the first line end, so INSIDE=1 is read from inside the rejected substitution. Contrived input from the user's own .env, and a narrow regression of the new branch. The top-level # check has the same preceding-character weakness but predates this PR.
    Remediation: Track whether whitespace actually establishes a shell token boundary rather than inspecting only the preceding character, and add a regression test with an escaped space immediately before a literal # and the closing ).

Earlier findings

  • internal/runtime/env_data.go:365, edge-case — resolved by change: skip_statement now skips # comments while inside $(...), so a lone backtick or quote in the comment no longer opens an unclosed span. The new test TestEnvDataLoad_RejectedStatementCommentInsideSubstitution covers the backtick and single-quote cases.
Previous run

<!-- fullsend:review-findings-v2:eyJ2ZXJzaW9uIjoyLCJhY3Rpb24iOiJyZXF1ZXN0LWNoYW5nZXMiLCJmaW5kaW5ncyI6W3sic2V2ZXJpdHkiOiJsb3ciLCJjYXRlZ29yeSI6ImVkZ2UtY2FzZSIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL2Vudl9kYXRhLmdvIiwiaWQiOiJmXzViNTI0ZWY1ZTVjZGM1NTIiLCJsaW5lIjozNjUsImFjdGlvbmFibGUiOnRydWV9XX0= -->

Review

Findings

Low

  • [edge-case] internal/runtime/env_data.go:365 — skip_statement() does not recognize # comments while inside $(...) (its comment handling runs only under elif not stack:). The new unquoted-backtick branch pushes a span for any backtick, including one inside such a comment. Before this PR the backtick was ignored there. For a rejected statement whose $(...) contains a comment with a lone backtick (export X=$(printf x # <backtick>, then export INSIDE=1, then )), the span is never closed, the function falls back to the first newline, and INSIDE is imported. The base skipped it. The base already fails the same way when such a comment contains ' or ", so this extends a pre-existing limitation rather than adding a new class. The new tests do not cover comments inside $(...).
    Remediation: In skip_statement, when the top of the stack is ), recognize a word-start # (preceded by whitespace or one of ;&|()) and skip to the newline without altering the stack, before quotes and backticks are interpreted. Add a regression test asserting INSIDE is absent and KEEP is retained.

Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-coder

fullsend-ai-coder Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Finished Fix · ✅ Success · Started 12:18 PM UTC · Completed 12:24 PM UTC

Commit: 479d783 · View workflow run →

Runtime: claude · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $0.27

@codecov

codecov Bot commented Oct 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

skip_statement() did not recognize # comments while inside $(...), so a
lone backtick (or quote) in such a comment opened a span that never
closed and the resync fell back to the first newline, importing lines
from the rejected statement. A word-start # inside $(...) now skips to
the newline without altering the span stack. Adds a regression test and
regenerates the codex launch golden files that embed the loader script.

Note: pre-commit could not fetch its remote hook repos (TLS failure in
the sandbox); gofmt and go vet were run directly and passed.
golangci-lint is not installed.

Addresses #8937

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@fullsend-ai-coder

Copy link
Copy Markdown
Contributor Author

🔧 Fix agent — iteration 1 (bot-triggered)

Addressed the single low-severity finding: comments inside rejected $(...) statements are now skipped in the env-data loader resync, with a regression test (verified failing before the fix) and regenerated golden files.

Fixed (1):

  1. skip_statement() does not recognize # comments inside $(...), so a lone backtick in such a comment leaves a span open and imports lines from a rejected statement (internal/runtime/env_data.go): Inside $(...), a word-start # now skips to the newline without changing the span stack, before quotes/backticks are interpreted. Added a regression test and regenerated the codex launch golden files that embed the loader script.

Tests: passed

CI inspections (5):

  1. CI / test (pending, in_progress): Still running when inspected.
  2. E2E Tests / playback (pending, in_progress): Still running when inspected.
  3. E2E Tests / behaviour (pending, in_progress): Still running when inspected.
  4. CI / commit-lint (passing, success)
  5. CI / web (passing, success)

Conflict update: skipped; strategy none; forge MERGEABLE; target main

Next steps:

  • /fs-review — request a re-review of the changes
  • /fs-fix <your instruction> — run another fix pass with specific guidance
  • Push commits directly — review re-runs automatically on push
    Updated by fullsend fix agent

@fullsend-ai-review

fullsend-ai-review Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 12:25 PM UTC · Completed 12:31 PM UTC

Commit: 40a58dc · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $0.90

elif top == "\x60":
if c == "\x60":
stack.pop()
elif top == ")" and c == "#" and s[i - 1] in " \t\n;&|()":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[low] edge-case

The new comment branch in skip_statement treats an escaped space before # as a token boundary, so a literal escaped-space-then-# inside a rejected $(...) swallows the closing paren and resyncs at the first line end, importing INSIDE=1 from inside the rejected substitution. Narrow regression of the new branch.

Suggested fix: Track whether whitespace actually establishes a shell token boundary rather than inspecting only the preceding character; add a regression test with an escaped space before a literal # and the closing paren.

@fullsend-ai-review fullsend-ai-review Bot added the ready-for-merge All reviewers approved — ready to merge label Oct 30, 2026

This branch was successfully deployed

No deployments
dev — 40a58dc7 Deployed Oct 30, 2026 by fullsend-ai-coder[bot] via behaviour #18341
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-merge All reviewers approved — ready to merge ready-for-review Triggers review agent dispatch risk/moderate PR risk: moderate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

env-data loader: parser fidelity follow-ups from #8591 review

1 participant