Skip to content

fix(autoload): load rubix free functions despite Composer files dedupe#1118

Draft
ChristophWurst wants to merge 2 commits into
masterfrom
fix/1113-rubix-autoload-collision
Draft

fix(autoload): load rubix free functions despite Composer files dedupe#1118
ChristophWurst wants to merge 2 commits into
masterfrom
fix/1113-rubix-autoload-collision

Conversation

@ChristophWurst

@ChristophWurst ChristophWurst commented Jun 29, 2026

Copy link
Copy Markdown
Member

Fixes #1113

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@ChristophWurst ChristophWurst self-assigned this Jun 29, 2026
@ChristophWurst ChristophWurst force-pushed the fix/1113-rubix-autoload-collision branch 3 times, most recently from e2caedd to c8ccdca Compare June 29, 2026 14:44
Add a regression test that reproduces #1113 in a fresh subprocess: it
simulates another app (e.g. recognize, which ships a php-scoped copy of
rubix) winning Composer's "files" autoload dedupe race by pre-marking
rubix's file identifiers as loaded, then asserts that sigmoid activation -
which relies on the string callable 'Rubix\ML\sigmoid' - still works.

Without the fix the un-scoped rubix functions.php is skipped, so
'Rubix\ML\sigmoid' is never defined and inference crashes with
"Tensor\Matrix::map(): Argument #1 ($callback) must be of type callable,
string given". This test currently fails on purpose to demonstrate the
bug; the fix follows in a separate commit.

Assisted-by: ClaudeCode:claude-opus-4-8
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
@ChristophWurst ChristophWurst force-pushed the fix/1113-rubix-autoload-collision branch from c8ccdca to 714860a Compare July 3, 2026 07:21
rubix/ml and rubix/tensor expose free functions and constants through
Composer's "files" autoloader, which dedupes process-wide on a content-blind
identifier md5("<package>:<path>"). Several apps bundle rubix and register the
same identifier, so only the first to boot loads its copy:

  - recognize php-scopes rubix, so when it wins only prefixed symbols exist and
    our un-scoped Rubix\ML\sigmoid is missing -> login crashes with
    "Tensor\Matrix::map(): Argument #1 ($callback) must be of type callable";
  - mail ships rubix un-scoped, so it defines the same Rubix\ML\* symbols we do.

Load our rubix files from Application::register() via RubixBootstrap.php, but
only when the symbols are actually missing, guarding on a representative symbol
per file. Requiring unconditionally would fatal with "Cannot redeclare function
Rubix\ML\argmin()" whenever another un-scoped copy already loaded them
(require_once dedupes by realpath, not by symbol).

Fixes #1113

Assisted-by: ClaudeCode:claude-opus-4-8
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
@ChristophWurst ChristophWurst force-pushed the fix/1113-rubix-autoload-collision branch from 714860a to e4d5560 Compare July 3, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing bug Something isn't working regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suspicious login brakes NC 34 on login: Tensor\\Matrix::map(): Argument #1 ($callback) must be of type callable, string given

1 participant