Skip to content

ci: harden shell-portability-lint detection precision (sed -i spellings, portability-scope precision, awk operand edge case) #1513

Description

@kyle-sexton

This was generated by AI during work-loop execution.

Context

#1491 added scripts/check-shell-portability.sh. An automated Codex review on the PR (#1511) raised
several detection-precision findings; the two that risked a real false positive on the CORRECT
portable form (grep -Pn/sort -Vr combined-flag clusters, and the sed -i ''/sed -i ""
empty-suffix idiom wrongly flagged) were fixed directly in that PR. This issue tracks the remaining,
lower-severity findings deliberately deferred:

1. Additional GNU sed -i spellings not yet covered

The current token only catches a literal standalone -i followed by a separate (space-delimited)
argument. GNU sed also accepts:

  • -Ei / -iE (combined with the extended-regex short flag)
  • --in-place[=SUFFIX] (long form)
  • an attached (no-space) empty suffix, e.g. -i'' — ambiguous with BSD's own attached-suffix syntax,
    so this one needs real sed-dialect research before encoding, not a quick pattern tweak.

--in-place alone is a clean, unambiguous addition (a literal token, no combined-cluster complexity).
The -Ei/-iE combined-cluster case needs the same "flag can appear anywhere in the cluster"
treatment #1511 already applied to grep -P / sort -V / echo -e, scoped carefully so it does not
also start matching unrelated -i uses (e.g. grep -i, sort -i... -i is common across tools, so a
bare cluster-scan risks over-matching if not anchored to sed specifically — verify before landing).

2. portability-scope: declaration matches anywhere in the file, including strings/docs

The whole-file exemption is grep -qE 'portability-scope:' -- "$file" — an unconditional substring
search, so a file that merely mentions the string portability-scope: in a doc block or string
literal (not as a genuine declaration comment) would be wrongly exempted. This exact mechanism is
already shipped and accepted in the sibling check-skill-portability.sh (same one-line grep -qE
check) — hardening it here should probably land as a shared fix touching both gates, not a
one-off divergence between siblings.

3. awk operand disambiguation for a pathological filename

scan_file() passes "$TOKENS" "$file" positionally to awk. A changed file whose full repo-root
path is shaped like an identifier=value assignment (e.g. a top-level file literally named
FOO=bar.sh) would be parsed by awk as a -v-style command-line assignment instead of opened as a
file, silently dropping it from the scan (a fail-open on an extremely unlikely, arguably invalid,
filename shape). Low real-world risk — no file in this repo's corpus is shaped this way — but worth a
defensive fix (e.g. prefixing operands with ./ or using -v explicitly) given this gate's own
stated fail-closed posture.

Priority

All three are low-severity / low-likelihood relative to the near-miss #1491 fixes. Bundled here rather
than filed individually since they share one gate and one likely reviewer.

Activity

  1. added
    status: ready
    area: security
    on Jul 26, 2026
  2. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Triage

    Duplicate check against #1517: not a duplicate. Read both bodies in full. #1517 explicitly frames itself as "Second round" and states "#1513 already tracks the first deferred round" — the two are sequential, non-overlapping rounds of the same Codex-review precision sweep on scripts/check-shell-portability.sh, not the same gap filed twice. Confirmed by content: this issue's three items (additional sed -i spellings, portability-scope: substring-match imprecision, awk operand disambiguation) do not overlap #1517's five items (escape-class scope, line-continuation joining, realpath control-flow, the sed -i '' round-3 reversal, sort long forms). No duplicate action taken.

    Verification: confirmed against current scripts/check-shell-portability.sh / scripts/shell-portability-tokens.txt.

    • Item 1 (sed -i spellings): the active token only matches a space-delimited standalone -i; --in-place, -Ei/-iE combined clusters, and attached empty-suffix (-i'') are not covered, matching the claim.
    • Item 2 (portability-scope: anywhere in file): scan_file() uses grep -qE 'portability-scope:' -- "$file" — an unconditional substring search with no anchoring to a genuine declaration-comment shape. Confirmed.
    • Item 3 (awk operand disambiguation): scan_file() invokes awk '...' "$TOKENS" "$file" with $file passed as a bare positional operand, which awk would parse as a var=value assignment for a pathological IDENT=value.sh-shaped filename. Confirmed, low real-world likelihood (no such file exists in this repo today).

    Classification

    • Type: Task

    • Priority: priority: low (already applied; matches the issue's own "Priority: Low" assessment — all three items are low-severity/low-likelihood).

    • Target state: briefed, decision-defaulted. This is CI lint tooling, not the guardrails' runtime-blocking git-parsing logic — lower blast radius than the git-guard cluster, and each item has a well-scoped, low-risk default:

      • Item 1: implement the unambiguous --in-place long-form addition now; defer -Ei/-iE combined-cluster handling and the attached-empty-suffix case — the issue itself flags the latter as needing "real sed-dialect research before encoding," not a quick pattern tweak, and the -i combined-cluster case needs careful anchoring to sed specifically to avoid over-matching grep -i/sort -i.
      • Item 2: implement the anchoring fix, applied to both scripts/check-shell-portability.sh and the sibling scripts/check-skill-portability.sh (the issue notes the same one-line grep -qE mechanism is shared) — recommended as one PR touching both gates rather than a divergent one-off fix.
      • Item 3: implement the defensive awk operand fix (e.g. ./-prefix or explicit -v) — no real corpus risk today, but cheap and matches the gate's stated fail-closed posture.

      Decision defaulted: implement items 1 (unambiguous part only), 2 (both gates), and 3 now; defer the -Ei/-iE cluster and attached-empty-suffix sub-cases of item 1 pending sed-dialect research — veto before merge if a maintainer wants the full item 1 scope addressed in this pass instead.

    Labels applied: agent-ready (role label resolved from tracker defaults) + status: ready (already present). priority: low and area: security unchanged.

    Related: #1491, #1511 (origin PR), #1517 (round 2, distinct — see duplicate check above), #1510 (staged-class enable, distinct scope, not blocking).

  3. added
    agent-ready
    on Jul 26, 2026
  4. self-assigned this
    on Jul 26, 2026
  5. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor
    No description provided.
  6. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during work-loop execution.

    Autonomous work-loop dispatch (work-items:work-loop) picked up this item; the invoker's admission gate had already passed (triaged autonomous-eligible, verified against check-shell-portability.sh and shell-portability-tokens.txt). Claimed, implemented, and opened PR #1534.

  7. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    Two concrete reproductions for the backslash-continuation half of this issue, from #1544's fifth review round. Both exit 0 with "No unexcused GNU-only constructs":

    date \
      -d tomorrow +%s
    
    stat \
      -c %s "$f"

    The header at scripts/check-shell-portability.sh:54-56 already states this limitation abstractly and cites this issue. Worth carrying the reproductions here because #1544 activates date -d and stat -c, which makes the gap materially more likely to bite than it was for the regex-escape classes alone — a continued date/stat invocation is ordinary formatting in real scripts.

    Scope note for whoever picks this up: joining logical lines is a scanner-WIDE change, not a per-token one. It alters what "a line" means for every token, the reported line number, and the portability-ok: / portability-scope: annotation rules, which are all anchored to physical lines. #1544 demonstrated the hazard of changing a scanner-wide mechanism inside a class-activation PR: an earlier revision there re-derived command boundaries for every token and silently broke two unrelated classes, caught only by the existing suite.

    Priority argument, for consideration against the lexing work queued on #1562: a backslash continuation is far more common in real scripts than stat ${a:-x;y} -c or stat "$(f)" -c, so this is plausibly the highest-value of the three known fail-open gaps.

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

Metadata

Metadata

Assignees

Labels

agent-readyarea: securitystatus: ready

Type

No type

Fields

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