Add Comfy-Usage-Source header to ComfyUI and cloud API requests#468
Conversation
📝 WalkthroughWalkthroughAdds CLI-identifying metadata and headers: ChangesClient identification across request paths
CI workflow pin update
Possibly related PRs
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
3fbae5b to
ff2d9e7
Compare
Codecov bricked their old keybase account; action versions before v6.0.2 fail signature verification of the uploader (codecov-action#1956).
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #468 +/- ##
=======================================
Coverage 83.25% 83.25%
=======================================
Files 45 45
Lines 6802 6804 +2
=======================================
+ Hits 5663 5665 +2
Misses 1139 1139
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/pytest.yml:
- Line 41: The pinned SHA in the workflow uses line
(codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f) does not match
the inline comment label "# v6.0.2"; either update the uses value to the actual
commit SHA for tag v6.0.2 (replace fb8b... with
8cad3ba95e5920c42f44492e54bc9639cba47959) or change the inline comment to
reflect the true SHA you intend to pin (or simply use the tag form
codecov/codecov-action@v6.0.2 if you want the tag instead); edit the line that
contains codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f and the
adjacent comment to make them consistent.
In `@tests/comfy_cli/command/test_run.py`:
- Around line 201-207: The test test_queue_sends_usage_source_header is
asserting the wrong header casing; update the assertion to match the exact
header name used in run.py ("Comfy-Usage-Source") so it reads assert
req.get_header("Comfy-Usage-Source") == "comfy-cli" (or alternatively fetch
headers case-insensitively from req.header_items()), targeting the test function
test_queue_sends_usage_source_header and the code that calls
ex.queue()/urllib.request.Request to ensure casing matches.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 9a7ff5f2-dfc6-4674-aa75-8c0aad737f94
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
.github/workflows/pytest.ymlcomfy_cli/command/generate/client.pycomfy_cli/command/run.pytests/comfy_cli/command/test_run.py
| def test_queue_sends_usage_source_header(self, workflow): | ||
| ex = self._make_exec(workflow) | ||
| with patch("comfy_cli.command.run.request.urlopen") as mock_open: | ||
| mock_open.return_value.read.return_value = json.dumps({"prompt_id": "abc"}).encode() | ||
| ex.queue() | ||
| req = mock_open.call_args[0][0] | ||
| assert req.get_header("Comfy-usage-source") == "comfy-cli" |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify that urllib.request.Request.get_header() is case-insensitive
python -c "
import urllib.request
req = urllib.request.Request('http://example.com')
req.add_header('Comfy-Usage-Source', 'test-value')
# Test various casings
print('Exact match:', req.get_header('Comfy-Usage-Source'))
print('Lowercase u:', req.get_header('Comfy-usage-source'))
print('All lowercase:', req.get_header('comfy-usage-source'))
print('All uppercase:', req.get_header('COMFY-USAGE-SOURCE'))
# Check if all variants return the same value
variants = [
req.get_header('Comfy-Usage-Source'),
req.get_header('Comfy-usage-source'),
req.get_header('comfy-usage-source'),
req.get_header('COMFY-USAGE-SOURCE')
]
if all(v == 'test-value' for v in variants):
print('✓ get_header() is case-insensitive')
else:
print('✗ get_header() is case-sensitive - test may fail')
"Repository: Comfy-Org/comfy-cli
Length of output: 194
Align Comfy-* header casing in the test.
run.py sets "Comfy-Usage-Source", but the test asserts req.get_header("Comfy-usage-source"); urllib.request.Request.get_header() can require matching header-name casing (returns None otherwise), so this assertion is brittle. Update the test to use the exact same header name casing—case closed! 🎭
🧰 Tools
🪛 Pylint (4.0.5)
[convention] 201-201: Missing function or method docstring
(C0116)
[warning] 201-201: Redefining name 'workflow' from outer scope (line 21)
(W0621)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/comfy_cli/command/test_run.py` around lines 201 - 207, The test
test_queue_sends_usage_source_header is asserting the wrong header casing;
update the assertion to match the exact header name used in run.py
("Comfy-Usage-Source") so it reads assert req.get_header("Comfy-Usage-Source")
== "comfy-cli" (or alternatively fetch headers case-insensitively from
req.header_items()), targeting the test function
test_queue_sends_usage_source_header and the code that calls
ex.queue()/urllib.request.Request to ensure casing matches.
Adds a
Comfy-Usage-Source: comfy-cliheader (andextra_data.comfy_usage_source) when submitting workflows to a ComfyUI server, and the same header on cloud generate API requests. Allows partner node API usage to be attributed to the CLI.Used in Comfy-Org/ComfyUI#14404