Skip to content

fix(s062): the MCP plug's authorize hook is a remote capture, so the release compiles - #62

Merged
HackTuah merged 2 commits into
mainfrom
fix/s062-prod-compile
Sep 22, 2026
Merged

HackTuah merged 2 commits into
mainfrom
fix/s062-prod-compile

Conversation

@HackTuah

Copy link
Copy Markdown
Member

The slice/062 tag fired the package workflow for the first time over slice 062, and all three
legs failed to compile the release (run 35786247006, linux / macOS / windows, one cause):

== Compilation error in file lib/trinity_web/endpoint.ex ==
** (ArgumentError) cannot escape #Function<0.132933281/1 in Trinity.MCP.Server.Plug.init/1>.

Plug.Builder calls a plug's init/1 at compile time when MIX_ENV=prod and escapes the result
into the compiled endpoint. Slice 062 replaced 061's authorize: &Auth.Local.authorize/1 with an
anonymous function closing over the process-dictionary key; a closure cannot be escaped. The hook is
now &__MODULE__.authorized/1, a public function with the same body and a typespec.

Nothing about the authorization behaviour changes: call/2 still authorizes before the transport
runs and the hook is still the transport's second look at what it decided.

  • Regression test: test/trinity/mcp/server_test.exs, "every option the plug's init returns can be
    escaped, as a compile-time init must be" — it runs Macro.escape/1 over Plug.init([]), the
    compile-time step that failed, and was demonstrated red against the closure with the same message
    CI printed.
  • Verified: MIX_ENV=prod mix compile exits 0 on this branch and exits 1 on main at 9859fbe.
  • Records: slice 062's NOTES.md (F5, with the reproduction) and PROOF.md carry appended
    corrections; neither is rewritten and the tag is not moved.

Follow-up for the owner, in NOTES: nothing in mix gate or the push-triggered CI compiles
:prod, and package.yml triggers on tags only, so this class of defect is invisible until after
approval. Either a MIX_ENV=prod mix compile step in the gate or a branches: trigger on
package.yml would close it; that is the gate's contract and every slice's, so it is not changed
here.

…release compiles

Plug.Builder calls init/1 at compile time under MIX_ENV=prod and escapes what it returns
into the endpoint; 062 had passed an anonymous function, which cannot be escaped, and all
three package legs failed to compile at the slice/062 tag (run 35786247006). The gate runs
in :test, where init/1 is called per request, so it was green over it. The regression test
runs Macro.escape/1 over Plug.init([]) and was demonstrated red against the closure.

Signed-off-by: Ayla Croft <aylacroft@proton.me>
Signed-off-by: Ayla Croft <aylacroft@proton.me>
@HackTuah
HackTuah merged commit 16be4d1 into main Sep 22, 2026
8 checks passed
@HackTuah
HackTuah deleted the fix/s062-prod-compile branch September 22, 2026 21:47
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