Skip to content

fix: extension hosts read PHP# as it means, load project classes, and fit the timeout - #181

Merged
heyJordanParker merged 8 commits into
masterfrom
fix/extension-hosts
Oct 19, 2026
Merged

heyJordanParker merged 8 commits into
masterfrom
fix/extension-hosts

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Defects an extension host meets on a Laravel app, and the fixes #181's review asked for. Each has a test row seen failing before its fix.

A host loads the project's own classes, from a compile outside the project

Every command that starts hosts (mago compile, mago analyze, --watch, mago lint, mago extension) compiles the project for the hosts into a folder of mago's cache keyed by the project root, and gives each host SHARP_ROOT and SHARP_COMPILED. The engine reads a worker's compiled files, listener table and refusal report from there, so mago analyze writes nothing in the project and works on a read-only checkout, and .sharp/ holds only what mago compile accepted. That compile lowers every file that lowers, whatever the analysis says, so a host whose own typing makes a class correct can load it on a fresh tree. A file that can't lower gives the host the checker's own errors. A panic in lowering refuses only that file, so the release profile unwinds. --watch restarts the hosts' workers when a file they load changes. Precedent: Roslyn hands analyzers a compilation with errors, tsc emits despite type errors (noEmitOnError: false), rust-analyzer turns a panic into a failed request, and a dev server restarts a worker when a module it loaded changes.

  • a_typing_host_loads_a_class_only_its_typing_makes_correct_on_a_fresh_tree, a_host_sees_each_php_sharp_file_compiled_from_its_current_source, a_linter_host_sees_each_php_sharp_file_compiled_on_a_fresh_tree, a_watch_starts_the_hosts_again_when_a_php_sharp_file_changes (tests/compile.rs)
  • host_compiled.phpt (Zend/tests/sharp)

mago compile hides exactly what mago analyze hides

The same ignore entries and baseline filter the errors that refuse a file. A pragma, an ignore entry or the baseline hides a host rule's error and never one of the language's own, and the unsuppressible-error warning says so. Precedent: tsc and tsc --noEmit report the same errors; C#'s #pragma warning disable never hides a compiler error.

  • compile_hides_the_host_errors_an_ignore_entry_or_the_baseline_hides_from_analyze (tests/compile.rs)

Hosts read each PHP# call as the PHP that means it

Function-call hooks get global.max() and Pdf.render() after import Vendor.Pdf;, static hooks Calc.make() and Self.cap(), and instantiation hooks PaymentResult.Declined(…). The snapshot after analysis names Vendor\Pdf\render and Vendor\Pdf\DEFAULT_DPI at the member, the case class at a built case, and the enum alone at a data-case pattern. CallExpression reads a local's call twice(1) as naming no function, as $twice(1). No SDK method or signature changes. Precedent: a Roslyn analyzer registered for an operation kind receives each node the semantic model reads as that kind.

  • node_hooks_see_a_sharp_call_of_a_global_function_as_a_function_call_as_in_php, node_hooks_see_a_sharp_call_of_a_namespace_function_as_a_call_of_that_function, node_hooks_see_a_sharp_call_of_self_a_case_and_a_local_as_the_php_that_means_it (tests/external_analyzer_invocation.rs)
  • the_source_names_what_each_form_means (crates/names/tests/binder.rs)

request-timeout-ms bounds one file's hooks

The SDK's worker sends a progress frame naming each file as it starts the file's hooks. The deadline counts from the request's start and from each progress frame of the worker, so a batch lives while each file's hooks finish in time, and a hook that never finishes its file fails, whatever it asks Mago. The error names the host, the file and the option. Precedent: Jest's testTimeout bounds one test, not the run. A batch of 1s hooks under the default finishes in 97s (master: timeout at 30s); a 300ms-per-file batch under a 3s limit finishes in 30s (master: timeout at 3.3s).

  • a_batch_whose_every_file_runs_within_the_deadline_lives_past_it, a_hook_that_asks_for_metadata_but_never_finishes_its_file_fails_at_the_deadline, a_timeout_names_the_file_whose_hooks_made_no_progress (crates/extension/src/worker.rs)

Every plain PHP class the engine refuses at link stops mago compile

mago compile refuses a plain PHP class that extends or implements a PHP# type and doesn't satisfy it, now including one that extends a struct or replaces a PHP# method that is not virtual, static or not. A closed PHP# method lowers final, so the engine refuses the replacement too, and a test double (PHPUnit's createMock, Mockery) replaces only a PHP# class's virtual methods, as Mockito replaces only open Kotlin members. Every other error in a plain PHP file stays mago analyze's. Precedent: kotlinc checks a Java type only where it meets a Kotlin declaration, and emits a member that is not open as a final JVM method. Plain PHP errors name PHP# members as PHP writes them (getKey(), $label).

  • compile_refuses_a_plain_php_class_that_extends_a_struct_or_replaces_a_closed_method, compile_refuses_a_plain_php_class_that_does_not_satisfy_the_php_sharp_interface_it_implements, compile_leaves_every_other_error_in_a_plain_php_file_to_mago_analyze (tests/compile.rs)
  • closed_methods_final.phpt (Zend/tests/sharp)

Known gaps

  • An @mago-expect pragma in a plain PHP file still hides a link error against a PHP# type, as every pragma in a plain PHP file does today. The engine then refuses the class at load.
  • A linter rule that targets function calls still doesn't receive global.max(): the linter dispatches by syntax.

… fit the timeout

Five defects an extension host meets on a Laravel app.

Names. The SDK's getResolvedNames() gave names the PHP# source never
writes: the type parameters, local calls, pattern classes and `global`
itself that lowering adds, while `global.member` named nothing.
ResolvedNames keeps the lowered names for the checker and lowering and
gives the SDK the names the source writes, and `global.max()` reads as a
call of the global function `max` through CallExpression::isFunction(),
as Roslyn's semantic model gives a source generator the symbols the
source names.

Project classes. A host that loads a project class died on a fresh tree
and after any change, because the class's compiled file was missing or
stale. mago compile and mago analyze, --watch included, now compile each
stale .sharp file without the hosts before the hosts start, as a Roslyn
source generator sees the compilation's own symbols and a Kotlin
compiler plugin sees the module's own classes.

Pragmas. A pragma, an ignore entry or the baseline naming a host's rule
now hides its error in a .sharp file, while the language's own errors
stay unhideable, as C#'s #pragma warning disable hides an analyzer's
error but never the compiler's, and ESLint's eslint-disable-next-line
hides a plugin's rule. Spec section 27 runs it as an example.

Timeout. request-timeout-ms counted a request from its send, so a batch
of after-file hooks that asked for metadata for 30s timed out though it
made progress. The deadline now runs from the worker's start of the
request or its last frame for it, as an HTTP client's read timeout runs
from the last byte. A Laravel app's compile goes from a timeout at 55s
to done in 65s under the default.

Plain PHP. mago compile accepted a plain PHP class that implements a
PHP# interface it doesn't satisfy, and the engine died linking it. The
compile now refuses each such class's file, on the errors the analysis
reports at its declaration that name a PHP# declaration, whatever ignore
entry or baseline entry targets them. Every other error in a plain PHP
file stays mago analyze's, as kotlinc checks a Java type only where it
meets a Kotlin declaration and leaves every other Java error to javac.
The analysis names the class in each error of a plain PHP class's
declaration checks, and the missing-Defaults error names the interface.
…e the project

A host that loads a project class broke on a fresh clone when its own typing
made the class correct, made `mago analyze` write into the project (and fail
on a read-only checkout), let a file the checker refused run, gave a host
"isn't compiled" for a file with a language error, and left linter hosts
without the project's classes.

Every command that starts hosts (`mago compile`, `mago analyze`, `--watch`,
`mago lint`, `mago extension`) now compiles the project for the hosts into a
folder of mago's cache keyed by the project root, never into `.sharp/`. Each
enabled host gets `SHARP_ROOT` and `SHARP_COMPILED`, and the engine reads a
worker's compiled files, listener table and refusal report from that folder.
That compile lowers every file that parses and lowers, whatever the analysis
says of it, as Roslyn hands analyzers a compilation with errors and `tsc`
emits despite type errors (`noEmitOnError: false`). A file that can't lower
is in the folder's report.json, so the host gets the checker's own message.
A panic in lowering refuses only that file, as rust-analyzer turns a panic on
broken code into a failed request, so the release profile unwinds.

`mago compile` hides exactly what `mago analyze` hides: the same `ignore`
entries and baseline filter the errors that refuse a file, as `tsc` and
`tsc --noEmit` report the same errors. The language's own errors stay
unsuppressible, and the `unsuppressible-error` warning now says so.

`mago analyze --watch` starts the hosts' workers again when a file they load
changes, as a dev server restarts a worker when a module it loaded changes,
since a PHP worker can't redeclare a class.
…them

A batch of 32 files whose hooks take 1s each timed out at 30s under the
default, and a batch whose hooks read cached metadata timed out at 3s
under a 3s limit, though each file's hooks finished in time. A hook that
kept asking Mago for metadata lived forever, and the error named neither
the host nor the file nor the option.

The SDK's worker now sends a progress frame naming each file as it
starts the file's hooks. The deadline is the longest one file's hooks may
run, as Jest's testTimeout bounds one test rather than the run: it counts
from the request's start and again from each progress frame of the
worker, for any of its requests, since one PHP process runs one hook at a
time while the worker interleaves requests. Nested requests no longer
count as progress, so a hook that never finishes its file fails.

The error reads "extension host `slow` made no progress for 3000 ms on
the hooks of app/F3.php (worker 0): raise its `request-timeout-ms` for
hooks that run that long".
…ethods run final

Calls by meaning. Function-call hooks never received `global.max()`, and
the SDK read `Pdf.render("x")` after `import Vendor.Pdf;` as a static
call, `Self.cap(3)` as an instance call, `PaymentResult.Declined(…)` as a
static call, and `twice(1)` on a local as a call of a function `twice`.
Mago now sends each node analysis target the kind of node it means, as
the analyzer reads it, and the SDK's worker hands it to the hooks of that
kind: function-call hooks get `global.max()` and `Pdf.render()`, static
hooks `Calc.make()` and `Self.cap()`, instantiation hooks a built enum
case, as a Roslyn analyzer registered for an operation kind receives each
node the semantic model reads as that kind. The snapshot after analysis
names what only the codebase tells: `Vendor\Pdf\render` and
`Vendor\Pdf\DEFAULT_DPI` at the member and the namespace at `Pdf`, the
case class at a built case, and the enum alone at a data-case pattern.
CallExpression reads `Self`/`super` receivers as static, a built case as
neither call kind, and a local's call as naming no function, as
`$twice(1)` does.

Closed methods. The engine linked a plain PHP class that replaced a PHP#
method that is not `virtual`, and refused one that turned a static method
into an instance method while `mago compile` let it through, as it let
through a class that extends a struct. A closed PHP# method now lowers
`final`, as Kotlin emits a member that is not `open` as a final JVM
method, so the engine refuses the replacement at link and the compile
refuses it first; the struct error points at the struct, so the compile
refuses that class too. The plain PHP errors name PHP# members as PHP
writes them: `getKey()`, and the property `$label` rather than its hook.
…ge add

The analyzer's own tests now read a PHP# file's targets and names as a
host gets them: `Pdf.render("x")` as a function call, a built enum case
as `new`, the namespace and its members at `Pdf.render` and
`Pdf.DEFAULT_DPI`, the case class at a built case, the enum at a case
pattern, and nothing more in a plain PHP file. A plain PHP class missing
a PHP# interface's property is told of `$label`, as PHP writes it.
…ition

A case pattern's enum joins the condition that finds the case, as every
case class has its enum, and the analyzer's test sends a class target,
which means only itself, beside the two calls.
…nalysis

CallExpression checks the member it hands on is there, and the test hook
reads a function's name at the call's callee, which is the member of a
PHP# function call.
A closed PHP# method lowers `final`, so each fixture's PHP twin declares
those methods `final` too, and `opcodes.phpt` again compares the same
PHP: a call of a final method compiles to `DO_UCALL` on both sides.
`overrides.phpt` keeps the plain PHP test double that overrides a closed
property, and leaves the replaced method to `closed_methods_final.phpt`.
The slice 22 record answers its question 6 with the review's decision,
as Kotlin members that are not `open` are final JVM methods.
@heyJordanParker
heyJordanParker merged commit 92c9eae into master Oct 19, 2026
26 checks passed
@heyJordanParker
heyJordanParker deleted the fix/extension-hosts branch November 3, 2026 22:08
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