Skip to content

Conversation

@MaxGhenis
Copy link
Contributor

Summary

  • Treat empty string token same as None (fixes CI with missing secrets)
  • Check os.isatty(0) before prompting - return None in non-interactive environments instead of hanging on getpass
  • Update return type to str | None

Problem

When Dependabot opens a PR in repos using policyengine-core, it doesn't have access to repository secrets. The HUGGING_FACE_TOKEN secret gets passed as an empty string "", which causes:

  1. get_or_prompt_hf_token() checks if token is None: - but "" is not None
  2. Returns empty string ""
  3. hf_hub_download tries to use Bearer header (empty token)
  4. httpx fails with Illegal header value b'Bearer '

Solution

# Before
if token is None:
    token = getpass(...)

# After  
if not token:  # Catches both None and ""
    if os.isatty(0):  # Only prompt if interactive
        token = getpass(...)
    else:
        return None  # CI can handle None gracefully

Related

Test plan

  • CI passes
  • Manually verify empty token returns None in non-interactive mode
  • Verify interactive prompt still works when running locally

🤖 Generated with Claude Code

- Treat empty string same as None (fixes CI with missing secrets)
- Check os.isatty(0) before prompting - return None in non-interactive
  environments instead of hanging on getpass
- Update return type to str | None

This fixes the 'httpx.LocalProtocolError: Illegal header value b'Bearer ''
error that occurs when Dependabot PRs run without access to secrets.

Closes PolicyEngine/policyengine-uk#1479

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@MaxGhenis MaxGhenis force-pushed the fix/empty-huggingface-token branch from 10272f3 to 1e709ba Compare January 17, 2026 18:09
@codecov
Copy link

codecov bot commented Jan 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.41%. Comparing base (58c2fca) to head (1e709ba).
⚠️ Report is 29 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #422      +/-   ##
==========================================
+ Coverage   81.14%   82.41%   +1.27%     
==========================================
  Files         197      201       +4     
  Lines       10228    10517     +289     
  Branches     1057     1064       +7     
==========================================
+ Hits         8299     8668     +369     
+ Misses       1640     1574      -66     
+ Partials      289      275      -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MaxGhenis MaxGhenis merged commit 49eabd7 into PolicyEngine:master Jan 17, 2026
16 checks passed
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