Skip to content

fix(ffi): replace removed std.atomic.Mutex with std.Thread.Mutex#291

Merged
hyperpolymath merged 1 commit into
mainfrom
fix/zig-thread-mutex
Jul 21, 2026
Merged

fix(ffi): replace removed std.atomic.Mutex with std.Thread.Mutex#291
hyperpolymath merged 1 commit into
mainfrom
fix/zig-thread-mutex

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

The failure

Zig FFI Tests has been failing on every PR:

src/catalogue.zig:16:22: error: root source file struct 'atomic' has no member named 'Mutex'

This was invisible until the repository's Actions policy was fixed — the workflow
was startup_failureing before any job ran, so the compile error never surfaced.

The cause

std.atomic.Mutex was removed from Zig's standard library. Nine files in
ffi/zig/src/ still carried a byte-identical hand-rolled wrapper around it
(all nine hash to the same value — one template copied nine times):

const Mutex = struct {
    state: std.atomic.Mutex = .unlocked,
    pub fn lock(m: *Mutex) void {
        while (!m.state.tryLock()) std.atomic.spinLoopHint();
    }
    pub fn unlock(m: *Mutex) void { m.state.unlock(); }
};

The fix

The wrapper's public surface — lock() / unlock(), instantiated as
var mutex: Mutex = .{} — is already exactly std.Thread.Mutex's. So the whole
struct collapses to a one-line alias, with no call-site changes:

const Mutex = std.Thread.Mutex;

Two things worth noting:

  • It's a behavioural improvement, not just a compile fix. The wrapper busy-waited
    via spinLoopHint, burning a core under contention. std.Thread.Mutex parks the
    waiting thread.
  • It converges on the in-tree norm. 81 other files in this repo already use
    std.Thread.Mutex directly, so this removes a divergent copy rather than adding a
    new pattern.

Files: sla, catalogue, sdp, loader, verisimdb, guardian, community,
federation, coprocessor.

Verification

Run locally against the exact CI pin (zig 0.15.2, per zig-test.yml) — all four
targets the workflow runs:

Target Result
zig build test PASS — 13 + 3 tests passed
zig build readiness PASS — 28/28 tests passed
zig build lib PASS — 2/2 steps
zig build bench PASS — 3/3 steps

Zero remaining code references to std.atomic.Mutex / std.atomic.spinLoopHint.

Note

.tool-versions pins zig 0.15.1 while zig-test.yml uses 0.15.2. Not changed
here, but the two should be reconciled.

`Zig FFI Tests` has been failing on every PR with:

    src/catalogue.zig:16:22: error: root source file struct 'atomic'
      has no member named 'Mutex'

`std.atomic.Mutex` was removed from the standard library. Nine files in
ffi/zig/src/ still carried a byte-identical hand-rolled wrapper around it
(verified: all nine hash to the same value — one template copied nine times):

    const Mutex = struct {
        state: std.atomic.Mutex = .unlocked,
        pub fn lock(m: *Mutex) void {
            while (!m.state.tryLock()) std.atomic.spinLoopHint();
        }
        pub fn unlock(m: *Mutex) void { m.state.unlock(); }
    };

The wrapper's public surface — `lock()` / `unlock()`, instantiated as
`var mutex: Mutex = .{}` — is already exactly `std.Thread.Mutex`'s, so the
whole struct collapses to a one-line alias with no call-site changes:

    const Mutex = std.Thread.Mutex;

This is also a behavioural improvement, not merely a compile fix: the wrapper
busy-waited via `spinLoopHint`, burning a core under contention, whereas
`std.Thread.Mutex` parks the waiting thread. 81 other files in this repo
already use `std.Thread.Mutex` directly, so this converges on the in-tree norm
rather than introducing a new one.

Files: sla, catalogue, sdp, loader, verisimdb, guardian, community,
federation, coprocessor.

Verified under the CI pin (zig 0.15.2, per .github/workflows/zig-test.yml) —
all four targets CI runs:

    zig build test       PASS  (13 + 3 tests passed)
    zig build readiness  PASS  (28/28 tests passed)
    zig build lib        PASS  (2/2 steps)
    zig build bench      PASS  (3/3 steps)

Note: `.tool-versions` pins 0.15.1 while the workflow uses 0.15.2. Not changed
here, but the two should be reconciled.

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

Copy link
Copy Markdown

🔍 Hypatia Security Scan

Findings: 228 issues detected

Severity Count
🔴 Critical 15
🟠 High 135
🟡 Medium 78

⚠️ Action Required: Critical security issues found!

View findings
[
  {
    "reason": "Action actions/checkout@v4 needs attention",
    "type": "unpinned_action",
    "file": "pages-deploy.yml",
    "action": "pin_sha",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Action actions/checkout@v4 needs attention",
    "type": "unpinned_action",
    "file": "pages.yml",
    "action": "pin_sha",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Action actions/checkout@v4 needs attention",
    "type": "unpinned_action",
    "file": "pages.yml",
    "action": "pin_sha",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Action actions/upload-pages-artifact@v3 needs attention",
    "type": "unpinned_action",
    "file": "pages.yml",
    "action": "pin_sha",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Action actions/deploy-pages@v4 needs attention",
    "type": "unpinned_action",
    "file": "pages.yml",
    "action": "pin_sha",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Issue in build.yml",
    "type": "missing_timeout_minutes",
    "file": "build.yml",
    "action": "flag",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Issue in pages-deploy.yml",
    "type": "missing_timeout_minutes",
    "file": "pages-deploy.yml",
    "action": "flag",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Issue in push-email-notify.yml",
    "type": "missing_timeout_minutes",
    "file": "push-email-notify.yml",
    "action": "flag",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Issue in scorecard-enforcer.yml",
    "type": "missing_timeout_minutes",
    "file": "scorecard-enforcer.yml",
    "action": "flag",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Issue in scorecard-enforcer.yml",
    "type": "scorecard_publish_with_run_step",
    "file": "scorecard-enforcer.yml",
    "action": "split_scorecard_publish_job",
    "rule_module": "workflow_audit",
    "severity": "high"
  }
]

Powered by Hypatia Neurosymbolic CI/CD Intelligence

@github-actions

Copy link
Copy Markdown

🏁 path-claims bench

Commit 5b34e73

Numbers
path-claims bench  (node v22.23.1)

  scenario                                              iters       ms        ns/op          ops/s
  --------------------------------------------------------------------------------------------------------------
  register: 10 active claims, 3 new paths               50000 iters    179 ms      3.60 µs/op    278.1k ops/s
  register: 100 active claims, 3 new paths              20000 iters    314 ms     15.73 µs/op     63.6k ops/s
  register: 1000 active claims, 3 new paths              5000 iters    982 ms    196.57 µs/op      5.1k ops/s
  register: 100 active claims, 20 new paths              5000 iters    328 ms     65.66 µs/op     15.2k ops/s

  pathsOverlap: deep diverge at segment 4             1000000 iters    141 ms     141.2 ns/op     7.08M ops/s
  pathsOverlap: short prefix match                    1000000 iters    115 ms     115.1 ns/op     8.69M ops/s

  refresh (existing claim)                             100000 iters     10 ms     103.7 ns/op     9.64M ops/s
  list (100 active claims)                              50000 iters    264 ms      5.29 µs/op    189.2k ops/s

  (Bench numbers depend on host; use deltas across commits, not absolute values.)

Host-dependent — compare deltas across commits, not absolute values.

@hyperpolymath
hyperpolymath marked this pull request as ready for review July 21, 2026 12:33
@hyperpolymath
hyperpolymath merged commit 123aa1f into main Jul 21, 2026
48 of 51 checks passed
@hyperpolymath
hyperpolymath deleted the fix/zig-thread-mutex branch July 21, 2026 12:36
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