Repository navigation
fix(token-report): set CLICOLOR_FORCE=0 to defeat forced colors - #220
Merged
Merged
Conversation
In PRQL/prql's CI environment, `gh run list --json` emits ANSI color escape sequences even with NO_COLOR=1 (which the script sets) and even when piped to a non-TTY. The colored output (`\e[1;37m[\e[m\e[1;37m]\e[m` instead of `[]`) breaks the downstream jq parse, and with `set -euo pipefail` the script exits with `jq: parse error: Invalid numeric literal at line 1, column 5` — producing an empty token report. Reproduced in review-runs session 24233554789 (PRQL/prql, gh 2.89.0). The bot verified that NO_COLOR=1, CLICOLOR=0, GH_FORCE_TTY="" and GH_NO_COLOR=1 all fail to suppress the codes — something in that environment forces them on. The same gh version in tend's CI does not exhibit the issue, so the root cause is environmental. Fix: pipe through a small `strip_ansi` sed helper. It's a no-op when no codes are present (tend CI) and strips them when they are (PRQL/prql), so the script is robust across environments without needing to diagnose the originating env var. Verified by mocking gh to emit the exact colored output the bot saw: before the fix, the pipeline fails with the same jq parse error; after the fix, the JSON parses correctly and the script processes runs normally. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Owner
|
can we set env vars to disable color rather than stripping chars? |
PRQL/prql's .github/actions/tend-setup/action.yaml sets CLICOLOR_FORCE=1 via $GITHUB_ENV to force cargo/clippy colors. gh treats CLICOLOR_FORCE as higher priority than NO_COLOR, so NO_COLOR=1 alone didn't suppress colors in --json output. Setting CLICOLOR_FORCE=0 in the script overrides the inherited value and addresses the root cause directly — simpler and more transparent than the sed-based strip_ansi approach. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Collaborator
Author
|
Yes — pushed The reason the existing Verified against gh 2.89.0 in this env by simulating PRQL/prql's setup:
End-to-end: |
max-sixty
pushed a commit
that referenced
this pull request
Sep 16, 2026
Every `gh` reader in the repo's Python parses the response as JSON, and
each one ran `gh` on the environment it inherited. `gh` ranks a forced
colour setting above `NO_COLOR` and colorizes even when its output is a
pipe rather than a terminal — so under `CLICOLOR_FORCE=1`, a body
arrives wrapped in ANSI escapes and the parse fails. Each reader treats
a decode error as a transient blip, so under a forced colour setting the
fallback is permanent, and every one of them degrades quietly:
- `notifications_check.py` — `_notifications` and `_conflicts` catch
`json.JSONDecodeError` and return `0`. Every cycle reports no
notifications and no conflicted bot PRs, so the bot silently stops
draining its inbox and stops resolving conflicts on its own PRs.
- `mention_verify.py` — the relayed-dispatch readers catch it and fall
through to `verdict(False)`, printing `review N not found on PR M —
skipping`. Mentions on review events go unanswered.
- `checks.py` — `check_branch_protection` reads `rules/branches/<b>` and
`branches/<b>/protection` as plain JSON, and both decode handlers fall
through to `CheckResult(name, True, f"Branch '{branch}' is protected")`.
`tend check` reports the branch as protected without ever verifying that
the bot cannot merge its own PRs — the check
[`docs/security-model.md`](https://github.com/max-sixty/tend/blob/main/docs/security-model.md)
calls the primary security boundary. This is the worst of the set: a
false green on a security check, not a poll reporting zero.
- `shared/steps/_common.py` — `security_preflight`'s first read is
deliberately left to raise, so the gate goes red rather than quiet. It
gets the same guard anyway.
- `install_codex_subscription_auth._verify_secrets` — parses `gh secret
list --json name`; a painted body aborts provisioning with an uncaught
`JSONDecodeError`. Loud, same two lines.
The fix sets `NO_COLOR=1` and `CLICOLOR_FORCE=0` in the child's
environment. `CLICOLOR_FORCE=0` is the part that matters: `gh` treats a
forced value as higher priority than `NO_COLOR`, so `NO_COLOR` alone
loses to an inherited `CLICOLOR_FORCE=1`. This is the same two-line
guard `github_cli.run` and `refresh_consumers.github_json` already
carry; the readers here each kept their own `gh` — the two templates
because they're rendered inline into the generated workflow rather than
imported, the rest because they're separate deployment units that can't
share a helper.
`gh` paints a JSON object or array but leaves a scalar `--jq` result
alone. Checked against the `gh` on the runner (2.100.0) rather than
inferred: under `CLICOLOR_FORCE=1`, `--jq '{name}'` comes back
ANSI-wrapped and pretty-printed across lines while `--jq
.default_branch` prints `main` plain, and adding `NO_COLOR=1
CLICOLOR_FORCE=0` restores the compact single line. So the `gh api
--paginate … --jq '… | .id'` reaction-cleanup steps in the generated
workflows, and `check_branch_protection`'s own `.protected` read, are
genuinely unaffected and stay as they are.
One shell reader does parse a shape `gh` would paint:
[`.github/workflows/integration-secrets.yaml`](https://github.com/max-sixty/tend/blob/main/.github/workflows/integration-secrets.yaml)
slurps the integration repo's `deployment-branch-policies` with no
`--jq` and pipes the array into `jq`. It stays unguarded — that workflow
is hand-maintained here and its steps set their own `env:`, so no
adopter config and no shell reaches it.
Reachable from an adopter's own configuration: a
`workflow_extra`/`jobs.*` `env:` override, or a `setup:` step that
writes `CLICOLOR_FORCE=1` into `$GITHUB_ENV` in a workflow where setup
precedes the pre-check — and for `tend check` and the install script,
simply a shell that exports it. Forcing colour for `cargo`/`clippy`
output is a normal reason to set it, which is how the same interaction
previously broke `token-report.sh` (#220).
Each of the three gates that fails quietly gets a regression test that
drives it with `CLICOLOR_FORCE=1` against a fake `gh` mimicking the
precedence, and asserts it still does its job. The `colorize` helper
that models the precedence lives in `tests/__init__.py`'s `GH_PREAMBLE`
beside the `emit` it wraps, so one definition serves every fake and
stays inert unless a test sets `CLICOLOR_FORCE=1`. Each test fails with
its guard reverted: the notifications one on `count`, the mention one on
the verdict, and the `checks.py` one on the assume-OK message rather
than `(requires reviews)`.
The regenerated `_regtest_outputs` snapshots are the generated
notifications and mention workflows, which embed these scripts inline.
`.github/workflows/tend-notifications.yaml` and `tend-mention.yaml` are
deliberately untouched: tend's own workflows track the published release
and pick this up at the next one.
---------
Co-authored-by: tend-agent <[email protected]>
Co-authored-by: tend-agent <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
token-report.shwas exportingNO_COLOR=1butgh run list --jsonstill emitted ANSI color codes into its JSON in PRQL/prql's CI, breaking the downstreamjqpipeline with:…making the token report silently empty.
Root cause (updated)
PRQL/prql's
.github/actions/tend-setup/action.yamlsetsCLICOLOR_FORCE=1in$GITHUB_ENVto force cargo/clippy color output. gh's iostreams logic treatsCLICOLOR_FORCEas higher priority thanNO_COLOR, soNO_COLOR=1alone cannot suppress colors when something upstream setsCLICOLOR_FORCE=1.Verified against gh 2.89.0 in tend's own env:
CLICOLOR_FORCE=1 gh run list --json ...\e[1;37m[\e[m\e[1;37m]\e[mCLICOLOR_FORCE=1 NO_COLOR=1 gh run list --json ...\e[1;37m[\e[m...(still colored)CLICOLOR_FORCE=1 CLICOLOR=0 gh run list --json ...\e[1;37m[\e[m...(still colored)CLICOLOR_FORCE=0 gh run list --json ...[{...}](clean)Fix
Add
export CLICOLOR_FORCE=0next to the existingexport NO_COLOR=1at the top oftoken-report.sh. This overrides an inheritedCLICOLOR_FORCE=1from the ambient env and lets gh fall back to its normal non-TTY behavior (no colors).Verification
CLICOLOR_FORCE=1 NO_COLOR=1 gh run list --json databaseId --limit 2→ emits\e[1;37m[\e[m..., confirmed against tend's CI gh 2.89.0.CLICOLOR_FORCE=1 NO_COLOR=1 bash -c 'export CLICOLOR_FORCE=0; gh run list --json databaseId --limit 2'→ emits[{"databaseId":...}]cleanly.CLICOLOR_FORCE=1 ./plugins/tend-ci-runner/scripts/token-report.sh 2→ script parses successfully, downloads artifacts, outputs valid JSON.cd generator && uv run pytest→ 147/147 passed.bash -npasses.Scope
Only
token-report.sh, since that's the script the bug demonstrably broke.list-recent-runs.shhas the samegh run list --jsonpattern but is only invoked from the review-reviewers skill which runs on tend itself (where no upstream setsCLICOLOR_FORCE=1), so I'm leaving it alone rather than making speculative changes.