Skip to content

GOL-1268: Teach ctx.caller in the home page snippets - #4700

Open
Aditya1404Sal wants to merge 10 commits into
mainfrom
aditya/gol-1268-home-page-snippets-for-ctxcaller
Open

Aditya1404Sal wants to merge 10 commits into
mainfrom
aditya/gol-1268-home-page-snippets-for-ctxcaller

Conversation

@Aditya1404Sal

@Aditya1404Sal Aditya1404Sal commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of GOL-1268: the golem.cloud home page snippets. The docs, skills and templates are in #4691.

On the golem.cloud home page, the Artifacts "Log in" and "Sign in" examples and the Tools "Middleware" example show 1.6 code in all six languages: s.principal(), Principal.PrincipalSchema, Principal parameters (caller: Principal), golem.Principal fields and ctx.Principal(). None of it builds against the 2.0 SDKs.

What changes

The 18 snippets (3 features × 6 languages) read the caller the 2.0 way, as the docs in #4691 teach:

SDK         login / signin / middleware read
TypeScript  handler (input, ctx): ctx.caller.original; middleware { caller }
Effect      (yield* InvocationContext.InvocationContext).caller; middleware ctx.caller
Rust        ctx: InvocationContext parameter, ctx.caller().original()
Scala       ctx: InvocationContext parameter, ctx.caller.original; middleware context.caller.original
MoonBit     ctx : @agents.InvocationContext / @tool.InvocationContext, ctx.caller().original
Go          ctx.Caller() on *golem.Context[S] and the middleware context
  • Log in: the agent stores ctx.caller.original.ref (a PrincipalRef) with each chart and compares it on read; anyone else gets a 404.
  • Sign in: the agent narrows ctx.caller.original to a signed-in user and reads its issuer and subject.
  • Middleware: the rate limit takes the original caller from the middleware's own context. In Rust, Scala and MoonBit the typed middleware gets that context through an InvocationContext parameter that the refund tool declares; the SDK supplies it and keeps it out of the tool's input and client.

The comments keep their text and order. Each snippet keeps its number of highlighted lines, some now on the caller lines, and all 18 stay within 68 columns and 31 lines. In Effect, Rust and MoonBit the login snippet's PNG type moved off-screen (it is shown in the "Files" snippet) to make room for the caller lines.

The six compile notes of the repo skill compiling-homepage-snippets describe the new code, the helpers the checks supply, and the negative controls.

Checks

The skill's compile harnesses are local and not committed; they were rebuilt for the three changed features in each language:

SDK         checks on the 3 changed snippets                          result
TypeScript  display rules, tsc per snippet, 3 negative controls       pass
Effect      style checks, tsc per snippet, 3 negative controls        pass
            (Middleware: with a types-only stand-in for
            Agents.Promises, a missing SDK part that
            effect.md records)
Rust        style + comments vs TS, cargo check and cargo build       pass
            (wasm32-wasip2), wasm-tools validate, native
            registration test, 3 negative controls
Go          style + comments vs TS, gofmt, go build and go vet        pass
            (wasip1), native definitions test, componentize-go
            components, wasm-tools validate, 3 negative controls
Scala       display rules, comments vs TS; NOT compiled               not compiled
MoonBit     display rules, comments vs TS, Golem codegen              partial
            (reexports, agents); moon build NOT completed

After the merge of main 663d3034c7 (a76bc49feb), the TypeScript and Effect rows ran again and pass. Main changed no SDK API that the other snippets use.

Each negative control plants one wrong caller read into one snippet and requires the build to fail with the expected error:

  • TypeScript: ctx.caller() in Log in (caller is a property), a wrong argument to the rate limit in Middleware, and the 1.6 field sub in Sign in.
  • Effect: caller.ref in Log in, the 1.6 ctx.principal in Middleware, and sub in Sign in.
  • Rust: the 1.6 ctx.principal() in Log in, the 1.6 parameter caller: Principal in Sign in, and the 1.6 parameter name caller in Middleware, which fails as an unknown name.
  • Go: the 1.6 ctx.Principal() in Log in and Middleware, and the 1.6 field Caller golem.Principal in Sign in.
  • Scala: the 1.6 ctx.principal, caller: Principal and caller; not run (see below).
  • MoonBit: not run (see below).

No control plants s.principal() or the 1.6 middleware principal. In Rust and Go, a Principal parameter or field now fails with the SDK's "Principal and Caller cannot appear …" error. In Rust that control needs cargo build: the error is a const panic that cargo check does not evaluate.

MoonBit is partial. With moonc at the release CI's pin (v0.10.18+6c83a7f62), the display rules, the comment comparison and the Golem codegen (which parses the files and validates the agent, tool and middleware declarations) pass. moon build --target wasm stops inside the SDK: in a fresh checkout golem_sdk/async-core is missing its generated bindings (stream_transfer.mbt finds no Stream), and regenerating them needs the Golem wit-bindgen fork. So the MoonBit snippets are not compiled, and their negative controls were not run. moonbit.md says the same.

Scala is not compiled. The 3 Scala snippets are edited from the SDK sources, and the display rules and the comment comparison with the TypeScript pass. The compile check did not complete: publishing the in-tree Scala SDK at this branch's base failed in the SDK itself, before the snippets. core does not compile: sdks/scala/core/js/src/main/scala/golem/host/OplogApi.scala:770-771 reads componentId and agentId from JsAgentId, which became a single UUID with the UUIDv8 agent IDs. Main fixes those two lines in #4695. The 3 Scala negative controls were not run. scala.md says the same.

🤖 Generated with Claude Code

@netlify

netlify Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for golemcloud canceled.

Name Link
🔨 Latest commit a76bc49
🔍 Latest deploy log https://app.netlify.com/projects/golemcloud/deploys/6b0cfc660c9b690164141bae

@Aditya1404Sal
Aditya1404Sal marked this pull request as ready for review November 29, 2026 21:25
@Aditya1404Sal
Aditya1404Sal requested a review from a team November 29, 2026 21:25

This branch has not been deployed

No deployments
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