Skip to content

1bit comfy: run the checked binary; fetch the submodule when missing - #66

Merged
bong-water-water-bong merged 2 commits into
mainfrom
comfy-hardening
Sep 25, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
comfy-hardening

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Follow-up to #65: fixes both things PR-Agent flagged there (#65 was merged before this commit went up).

Running the binary safely:

  • 1bit comfy opens the binary once and checks it through that open file: a regular file, executable, and not writable by other users.
  • It then runs that same file with fexecve, so nothing can swap it between the check and the run.
  • ONEBIT_COMFYUI must be an absolute path, and relative PATH entries are skipped.

Tested on strixhalo:

  • a normal run gives the same image (50.6 dB against ComfyUI);
  • a relative path, a world-writable binary, a missing binary and a non-executable file each fail with a clear message (exit 127).

Submodule: CMake (-DONEBIT_COMFYUI=ON) and scripts/build-comfyui.sh fetch third_party/comfyui.cpp themselves when it's missing. In a fresh clone with no submodules, configuring fetched it at the pinned 4a08238.

🤖 Generated with Claude Code

…fetch the submodule when missing

PR-Agent review on #65: the binary is opened once, checked through the descriptor (regular,
executable, not writable by others) and run with fexecve, so no swap between check and exec;
ONEBIT_COMFYUI must be absolute and relative PATH entries are skipped. CMake and
build-comfyui.sh fetch third_party/comfyui.cpp themselves when it is not initialised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@context7

context7 Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Docs7 for 1bit-monster/engine

Result Status Action
Deployment ➖ Not used —
Content review ➖ Did not run. This site has no agent runs available this month. Wait for the monthly reset or check your Docs7 plan. —

Commit 9a5ad41

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 9a5ad41)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

65 - Partially compliant

Compliant requirements:

  • Brings ComfyUI.cpp into the engine
  • Pinned submodule third_party/comfyui.cpp at 4a08238
  • Build with -DONEBIT_COMFYUI=ON runs scripts/build-comfyui.sh
  • Run with 1bit comfy <workflow.json> looks for binary in $ONEBIT_COMFYUI, then build's, then PATH
  • License compliance: ComfyUI.cpp is GPL-3.0, engine is Apache-2.0, runs as separate program
  • Docs updated in docs/comfyui.md, README, and NOTICE

Non-compliant requirements:

  • None

Requires further human verification:

  • Verification that the binary runs correctly on strixhalo hardware with the specified PSNR measurements
  • Confirmation that the submodule fetching works correctly in a fresh clone without submodules
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Security: Potential race condition in binary execution

The code uses fexecve to execute the binary after checking its properties, which is good for preventing file swapping attacks. However, the check for world-writable permissions (st.st_mode & S_IWOTH) is done after opening the file descriptor, but before fexecve. If another process modifies the file between the check and execution, it could lead to a security issue. While fexecve ensures the same file is executed, the check for world-writable permissions should be atomic with the execution to prevent any race condition.

if (st.st_mode & S_IWOTH) {
    ::close(fd);
    throw std::runtime_error(bin + " is writable by other users; refusing to run it");
}
Submodule fetching logic

The script fetches the submodule only if CMakeLists.txt is missing and if the repository is a git repository. This logic might not cover all edge cases, such as when the directory exists but is not a valid git repository or when the submodule is corrupted. It's important to ensure that the submodule is properly initialized and at the correct commit.

# Fetch the pinned submodule when it is missing (not its own third_party/ComfyUI:
# that pin is only for the parity check).
if [ ! -f "$src/CMakeLists.txt" ] && git -C "$root" rev-parse --git-dir > /dev/null 2>&1; then
    echo "fetching third_party/comfyui.cpp"
    git -C "$root" submodule update --init third_party/comfyui.cpp
fi
[ -f "$src/CMakeLists.txt" ] || { echo "third_party/comfyui.cpp is empty and could not be fetched: git submodule update --init third_party/comfyui.cpp"; exit 1; }

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 9a5ad41

@bong-water-water-bong
bong-water-water-bong merged commit 9f1dda3 into main Sep 25, 2026
3 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the comfy-hardening branch September 25, 2026 09:49
bong-water-water-bong pushed a commit that referenced this pull request Oct 2, 2026
…512 tokens, deterministic flash attention

llama.cpp fork since cebcd70 (balanced mode, figures from each PR):
- #66 MUL_MAT_ID at multiples of 32 plus a decode-loader stride fix; #67 ADD_ID and SWIGLU_OAI on HRX;
  #73 a placement guard for the CPU/HRX split bug (engine #286). gpt-oss-20b MXFP4: pp512 25.8 -> ~1000,
  tg128 12.6 -> ~35 tok/s, text correct, KLD vs CPU 0.029.
- #69 TQ1_0/TQ2_0 on HRX: Ternary-Bonsai-1.7B KLD vs CPU 0.000523; pp512/tg128 3542/113 and 4100/156.
- #70 MLA V transpose: GLM-4.7-Flash prompts of 512+ tokens gave garbage (PPL 315,664), now 5.916 (CPU 5.959).
- #71 llama-hadamard folds qwen3next's ssm_ba and refuses unfoldable stamped files.
- #72 masked flash-attention keys reach P*V as V = +0: identical requests now give identical logits
  (Qwen3-0.6B and Qwen3.8-27B bit-identical repeats); pp512 -4.7% on Qwen3-0.6B.

Docs: docs/hrx.md "Our patches". Registry regenerated (no mapping changes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bong-water-water-bong added a commit that referenced this pull request Oct 2, 2026
…tic FA, attention sinks) (#295)

* Pin llama.cpp 2bd7f58: gpt-oss on HRX, TQ1_0/TQ2_0, MLA prompts past 512 tokens, deterministic flash attention

llama.cpp fork since cebcd70 (balanced mode, figures from each PR):
- #66 MUL_MAT_ID at multiples of 32 plus a decode-loader stride fix; #67 ADD_ID and SWIGLU_OAI on HRX;
  #73 a placement guard for the CPU/HRX split bug (engine #286). gpt-oss-20b MXFP4: pp512 25.8 -> ~1000,
  tg128 12.6 -> ~35 tok/s, text correct, KLD vs CPU 0.029.
- #69 TQ1_0/TQ2_0 on HRX: Ternary-Bonsai-1.7B KLD vs CPU 0.000523; pp512/tg128 3542/113 and 4100/156.
- #70 MLA V transpose: GLM-4.7-Flash prompts of 512+ tokens gave garbage (PPL 315,664), now 5.916 (CPU 5.959).
- #71 llama-hadamard folds qwen3next's ssm_ba and refuses unfoldable stamped files.
- #72 masked flash-attention keys reach P*V as V = +0: identical requests now give identical logits
  (Qwen3-0.6B and Qwen3.8-27B bit-identical repeats); pp512 -4.7% on Qwen3-0.6B.

Docs: docs/hrx.md "Our patches". Registry regenerated (no mapping changes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Pin llama.cpp 4485916: attention sinks on HRX (gpt-oss)

#68 runs gpt-oss's sink logits on HRX as an exact post-correction of the flash-attention output.
Docs: docs/hrx.md "Our patches". Registry pin updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Pin llama.cpp f5b7f4a: PrismML tile bytes (PQ2_0 small-model decode)

#74: the low-token SwiGLU read every PQ2_0 / PTQ1_0 row from row 0; Ternary-Bonsai-1.7B PQ2_0 now
matches the CPU. Found by the release format matrix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: bong-water-water-bong <bong-water-water-bong@1bit.gg>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant