Skip to content

feat(config): warn when env Discord token shadows config token (#274)#275

Merged
Yeachan-Heo merged 1 commit into
devfrom
clawhip-issue-274-token-precedence-warning
Jun 11, 2026
Merged

feat(config): warn when env Discord token shadows config token (#274)#275
Yeachan-Heo merged 1 commit into
devfrom
clawhip-issue-274-token-precedence-warning

Conversation

@Yeachan-Heo

Copy link
Copy Markdown
Owner

Closes #274.

Problem

When a systemd user unit (or any environment) still exports CLAWHIP_DISCORD_BOT_TOKEN/DISCORD_TOKEN, env precedence silently overrides a newly configured config-file token. Startup and clawhip status only reported token_source: env, so the ignored config token was discovered only after a Discord 401 smoke failure.

Change

Keep env-over-config compatibility (env still wins), but make the override explicit and non-secret:

  • AppConfig::discord_token_env_shadow detects when an env token shadows a present config token and returns only the offending env var name — never a token value.
  • Daemon startup emits a warning: log line and a discord_token_env_shadow telemetry record.
  • health_payload gains token_precedence_warning (null unless shadowed), surfaced by clawhip status.

Safety

  • No raw token values are ever printed or stored; only source/precedence and the env var name.
  • Behavior is backward compatible: env still wins unless the operator unsets it.

Tests

  • discord_token_env_shadow_detected_when_env_overrides_config
  • discord_token_env_shadow_uses_legacy_config_token
  • discord_token_env_shadow_none_without_conflict
  • discord_token_shadow_warning_names_env_var_without_leaking_value
  • health_payload_includes_version_and_token_source extended to assert the warning field is null when no shadow.

cargo build, cargo clippy, and the full cargo test suite (623 tests) pass.

When both an environment Discord token (DISCORD_TOKEN or
CLAWHIP_DISCORD_BOT_TOKEN) and a config-file token are present, env still
wins, but the override was previously silent: startup and `clawhip status`
only reported `token_source: env`, leaving operators to discover the
ignored config token via a Discord 401 smoke failure.

Add a non-secret precedence diagnostic surfaced in both startup
telemetry/logs and the daemon health payload (consumed by
`clawhip status`):

- AppConfig::discord_token_env_shadow detects env-over-config conflicts
  and reports only the offending env var name, never token values.
- Daemon startup emits a `warning:` log line plus a
  `discord_token_env_shadow` telemetry record.
- health_payload gains `token_precedence_warning` (null unless shadowed).

Env-over-config compatibility is unchanged. Adds focused tests covering
the shadow detection, the legacy config token path, the no-conflict
cases, and that the warning text leaks no secret values.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 575c4b8fc2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/daemon.rs
"ok": true,
"version": VERSION,
"token_source": config.discord_token_source(),
"token_precedence_warning": config.discord_token_env_shadow().map(discord_token_shadow_warning),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add a positive status warning test

AGENTS.md says “Test coverage: flag new logic paths that lack corresponding tests.” This new health/status branch is only asserted for the null case, so the intended clawhip status behavior when an env token shadows a config token can regress without a test (for example, returning null or leaking the wrong string would not be caught). Please add a positive health/status test with a config token plus DISCORD_TOKEN/CLAWHIP_DISCORD_BOT_TOKEN set.

Useful? React with 👍 / 👎.

@Yeachan-Heo

Copy link
Copy Markdown
Owner Author

GJC red-team review: MERGE_READY.

Evidence checked:

  • CI green: Build, Clippy, Format, Test, Check pass; Release plan pass, publish/artifact jobs skipped as expected.
  • Dedicated GJC review session: clawhip-pr-275-token-precedence-review in /home/bellman/Workspace/clawhip-pr-275-token-precedence-review.
  • Review verified env token precedence remains unchanged (env wins), diagnostics are additive/non-secret, warning text only includes env var name/source, and focused token tests + cargo fmt --check passed in review.

Non-blocking nit: health positive-path wiring is indirectly covered through helper tests rather than a dedicated health-payload positive assertion. Low risk and not merge-blocking.


[repo owner's gaebal-gajae (clawdbot) 🦞]

@Yeachan-Heo
Yeachan-Heo merged commit 67d1230 into dev Jun 11, 2026
12 checks passed
@Yeachan-Heo
Yeachan-Heo deleted the clawhip-issue-274-token-precedence-warning branch June 11, 2026 03:48
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.

1 participant