Repository navigation
Conversation
…cation handles trigger and schedule return an invocation handle after the target durably accepts the invocation; the handle rebuilds from its ID and offers status, await and cancel, which the target authorizes for the recorded starter or a caller with management permission. One async invoke-and-await replaces the agent futures. All six SDKs, the bridges, fixtures, guides and snippets use the handles; Golem is pinned to the wasm-rquickjs revision that aborts imports. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
✅ Deploy Preview for golemcloud canceled.
|
|
📖 Docs preview: https://docs-n3l5lrpyk-golem-cloud.vercel.app Built from commit |
wasm-rquickjs 0.5.6 contains import-abort and the explicit names of keyword resource methods, so Golem uses the released version instead of the git revision of its pull request branch. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
An internal error after the Start of a trigger or schedule call now traps the call and leaves its Start incomplete for repair. Before, the error dropped the Cancellable call session, which recorded the call as Cancelled. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
… helpers - WasmRpcEntry holds a WasmRpcEntryPayload instead of a type-erased box, so the calls read it without downcasts. One downcast used unwrap, which aborts the executor on a mismatch. - DurableCallSession::recorded_denial_access reads the denial of the claimed Start beside the other recorded-Start readers. It replaces the oplog read in trigger.rs. - The ephemeral-target preparation moves from trigger.rs to ephemeral.rs, and the client activation helpers move to target.rs. Trigger, invoke-and-await and schedule import them from there. - FutureInvokeTaskResult is now RpcTaskResult, and a stale comment about a guest-owned task handle is corrected. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
RemoteCall holds what a live remote step sends on behalf of the calling agent: the RPC service, the creator account, the agent ID, the invocation context and the caller. interruptible waits for a short remote step and traps the call on an interrupt. suspendable waits for a long remote step as an RPC wait, so the agent can suspend. They replace six hand-written select blocks and the capture tuples in trigger, schedule, invoke-and-await, the ephemeral preparation and the invocation handle. Store reads that can follow an await in these calls now go through with_import_access, as attribution.rs requires. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
deliver_rpc_result holds the delivery tail that invoke-and-await and the invocation handle's await wrote three times: park when the recorded run discarded the completion, convert the result for the guest, then deliver it at the accessor terminal or suppress the delivery when the conversion fails. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
open_rpc_call holds the opening that both calls repeated: validate the request, check the target's authorization, start the durable call with its indexed request, restore the recorded span, and derive the idempotency key and the target. It returns the request's rejection, the live denial, or the open call. prepare_rpc_invocation takes an RpcCallKind instead of two flags that the callers always set to the same value. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
A guest schedule now validates the request as trigger does, through prepare_rpc_invocation, before it opens a durable call. An unknown method returns remote-agent-error(invalid-method). An input that does not match the method, and a method with streams, return protocol-error. Before, each of these trapped. The schedule result has an rpc-error channel, and the client knows the remote agent type when the guest calls schedule, so the error is known at schedule time. An invalid scheduled time still traps. A schedule may still target the calling agent. The target checks the invocation again when it runs it, against the agent's revision at that time. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
invoke-and-await, trigger and schedule now open the call, resolve it as a recorded replay or a live run, and deliver the result at one place. The live body of each call is split into named steps, and PendingWithdrawal is armed and disarmed once, around the wait for the RPC task. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
status and cancel run through one recorded operation, and await uses the same start and target observation. The outcome functions return their results without early exits. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
The answer is split into the authorization of the caller, one function for each operation and the final mapping of an owner's deletion. The order of the authorization and its error mapping do not change. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
vigoo
marked this pull request as ready for review
November 27, 2026 16:40
A module with submodules lives in its own directory as mod.rs, as in the rest of the repository. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
The shard assign and revoke requests have a required executor_count since main delivers the executor count with shard leases. The invocation_reads lifecycle test and the interrupted open input session test, which main added in parallel, did not set it, so the test crate did not compile after the merge. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
RpcCall and RemoteCall keep their fields private. RpcCall gives read access to what its callers need, and owns the dispatch target, the retry properties, the lending of the scope card and the missing-origin error. RemoteCall sends the demand, the invocation and the schedule on behalf of the calling agent, so the call sites no longer unpack it. The open call is a struct variant of RpcCallOpening, CompletedReplay reports its denial through a method, and the resource table entries keep their fields private to the rpc module. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
The executor RPC module and the items that the invocation handles add elsewhere use private or plain pub visibility instead of pub(super) and pub(crate). An item used only in its own file is private. Items of existing modules that use a restricted visibility throughout, and a function that takes a crate-private type, keep their visibility. The handle-management test authorization keeps its flag private. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
RpcCall keeps the kind that opened it, so its retry properties and the preparation of its target use that kind and callers cannot pass another one. RemoteCall::schedule derives the final invocation ID from the idempotency key. RemoteAgentType keeps its fields private and builds the payload of a durable client itself. The last restricted items in the RPC module and four items used only by their own module are private. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a20968-e35a-756a-a2f3-deaba79311e3
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves GOL-1053.
Summary
An agent can start a call on another agent and not wait for the result. Before this change, the agent then got one of three different objects:
invoke(fire and forget)async-invoke-and-awaitfuture-invoke-resultschedule-cancelable-invocationcancellation-tokenThis PR replaces all three with one object: the invocation handle.
triggerandschedulereturn a handle. The handle can:The handle has an ID. The agent can store the ID in its state and rebuild the handle later, in another invocation, even after a restart.
One async
invoke-and-awaitreplaces the synchronousinvoke-and-awaitand theasync-invoke-and-awaitfuture. All six SDKs, the CLI bridges, the test components, the docs and the skills use the new API.What it looks like
Rust
A scheduled call gives the same handle, so it can be cancelled:
TypeScript
The other SDKs
remote.m.trigger(input),remote.m.schedule(at, input)InvocationId.Invocation<A, E>InvocationId.get(id, Agent.methods.m)client.m.trigger(...),client.m.scheduleAt(...)Invocation[Out]Invocation.get[Out](id)def.M.Trigger(c, in),def.M.Schedule(c, at, in)(andMust…forms)*golem.Invocation[Out]def.M.Invocation(id)client.trigger_m(...),client.schedule_m(...)@rpc.Invocation[T]Client::get_m_invocation(id)Every SDK has the same four operations:
id,status, await (await_result,awaitResult,AwaitResult) andcancel.How a handle works
The lifecycle
The new WIT is in
wit/deps/golem-agent/host.wit:trigger: async func(method-name: string, input: schema-value-tree) -> result<invocation, rpc-error>; schedule: async func(scheduled-time: datetime, method-name: string, input: schema-value-tree) -> result<invocation, rpc-error>; resource invocation { get: static func(id: invocation-id) -> invocation; // local, no remote call id: func() -> invocation-id; // local status: async func() -> result<invocation-status, rpc-error>; %await: async func() -> result<option<schema-value-tree>, rpc-error>; cancel: async func() -> result<bool, rpc-error>; }rpc-errorgets two typed cases:cancelled(the awaited invocation was withdrawn before it started) andcannot-cancel-running. They replace the old convention, where a cancellation was aninvalid-inputerror with aninvocation-cancelled:text prefix."Accepted" means durably accepted
triggerandschedulereturn only when the target has recorded the invocation. If the call returns a handle, the invocation exists, and the target runs it once. If the call returns an error, the target did not accept the invocation.This is why
triggeris now async in every SDK. Migration trap in Rust:counter.trigger_increment();without.awaitnow sends nothing; rustc warns about the unused future.The ID is a locator, not a permission
Anyone can know an invocation ID. The ID only says where the invocation is. The target checks every
status,awaitandcancel. It answers only:Viewforstatusandawait,CancelInvocationforcancel.Other callers get
denied. Some edge cases follow from this rule:not-found).denied, and a manager getsnot-found.denied.invalid-request. A guestinvocation.getof such an ID traps, becausegethas no error channel.Dropping a handle does not cancel
A handle is only a way to look at the invocation. Dropping the handle, or abandoning an
await, releases local resources only. The invocation keeps running. Two handles of the same invocation do not affect each other.Abandoning an awaited call (
invoke-and-await) is different. It withdraws the invocation on a best-effort basis while the invocation has not started:AbortSignalFuturecannot be cancelledUse
triggerpluscancel()when you need a definite answer.Cancelling a running invocation
cancel()on a running invocation fails withcannot-cancel-running. This is the interim answer. GOL-1061 replaces it with cooperative cancellation of running work.Durability of the handle operations
All handle operations are durable host calls:
triggerandschedulerecord aStart. TheEndrecords the accepted invocation ID. Replay rebuilds the handle from theEndand does not contact the target.statusandawaitareReadRemote.cancelisWriteRemote. A completed call replays its recorded answer, without the target and without a new authorization check. A call that crashed before itsEndsends the same ID-addressed request again on recovery. Anawaitthat was waiting attaches to the same invocation again.get,idand dropping a handle are local and record nothing.triggerderives from the index of its ownStart. So recovery after a crash sends the same request, and the target runs the invocation once.Example of what replay returns: an agent reads
status()and getspending. Later the target completes the invocation, and the caller restarts. Replay returnspendingagain for that recorded read, and a newstatus()call returnscompleted.Design decisions
awaitimplementation does not useawait_invocation_result, because that function starts a pending target. The handle observer follows the agent across generations: after an operator interrupt, it waits for the resumed generation's result and does not resume the agent itself.triggersets the new admission flagrequires_own_record(InvokeAgentRequestandInvocationStartin the worker-executor protocol). Awaited calls keep the cache.canceluses the same decision as the public cancel endpoint (Worker::cancel_invocation). See the behaviour changes below for what this changes in the public endpoint.false. Suppose a guest cancel crashes after the target withdrew the invocation, but before the caller recorded the answer. Recovery then finds a cancelled invocation and recordsfalse. The target has no record of which caller withdrew an invocation. Sotruewould also tell a second canceller that it withdrew the work. The WIT doc and the SDK docs say this.triggerrecords an error that exhausted its retry policy, asinvoke-and-awaitdoes.scheduletraps on a transient error, so recovery retries it with the same key.schedulerecords only a permanent refusal.Behaviour changes
triggerreturns after durable acceptance, not immediately.rpc-errorthat the guest can handle. Before, it trapped the caller.schedulevalidates its request astriggerdoes. An unknown method is aremote-agent-errorwithinvalid-method. An input that does not match the method, or a method with streams, is aprotocol-error. The guest gets these errors as the result, and the call records nothing. Before, they trapped the caller. An invalid time still traps.409 cannot-cancel-runningfor an ephemeral agent whose execution began. Before, it withdrew the only method of that ephemeral agent, so its constructor ran for nothing. The Durable StreamsDELETEalso maps this answer to 409. GOL-1061 replaces this answer.awaitreports how the invocation ended.trigger, itsCancelledentry now closes the span of itsStart. Before, the span stayed open.Startentries in either order. The awaited call now appends itsStartfrom a spawned task, as other concurrent host calls already do. Replay is not affected: it finds each call by its execution identity, not by its position in the oplog. Tests must find a call by its recorded request, not bystarts[0].Invocation<T>is now the handle. The completed value with its metadata isInvocationOutput<T>(also in MoonBit and Scala).Removed
invoke,async-invoke-and-await,schedule-invocation,schedule-cancelable-invocation,future-invoke-result,cancellation-tokenand the receipt records.Rpc::cancel_scheduled_invocationdown to the worker service, andscheduled_invocation_cancellation.proto. Thescheduledfield of bothCancelInvocationRequestmessages is nowreserved.CancellationToken, receipts,scheduleCancelable*, Rustpending_*, GoCallAsyncandFuture.The wasm-rquickjs dependency
The TypeScript and Effect SDKs need two changes from wasm-rquickjs#241:
wasm-rquickjs:import-abortgiveswithSignal(signal, fn). An async host import that starts insidefntakes the signal. When the signal aborts, the import's promise rejects and the import's subtask is dropped. Golem uses this to withdraw an awaited call when itsAbortSignalaborts or its Effect fiber is interrupted.%awaitmethod ofinvocationwas exposed asawaitwhile the.d.tssaidawait_.The Scala SDK also uses
await_(). wasm-rquickjs 0.5.6 contains both changes. The rootCargo.toml, the CI workflows, thecheck-published-sdksaction default and thegolem-scala-base-imageskill pin 0.5.6.Tests
New executor tests, by file:
rpc/guest_invocation_handles.rs: guest handles through a probe agent. The tests cover a deleted target, withdrawal across a restart, schedule fromscheduledtocompleted, a cancel that races the scheduled start, two observers, rebuild after a snapshot restore, crash prefixes ofawaitandschedule, two concurrent awaits with reverse completion, a failed invocation, the stream and read-only restrictions, invalid schedule requests, and a replayed intermediate status.invocation_reads/: theinvocation_handlegRPC operation, including authorization, deletion, operator interrupts, reverts, retired generations, storage outages and old result indexes.readonly.rs: a trigger of a read-only method with a warm cache, and next to an equivalent awaited call in flight.rpc/replay_barrier_probe.rs: two awaited calls that complete in reverse order across a real restart.rpc/held_response_restart.rs: a schedule held after the target committed it.hot_update.rs: a handle reads a completed result after an update removed its method.tool_streaming: a tool owner refuses handle operations.Caller tests of the changed shared contracts (WIT, worker-executor gRPC, SDK runtimes, CLI bridges) that ran:
rpc::,scheduled_durable::,scheduled_ephemeral::,invocation_reads::,readonly::andtool_streaming::standalonetests, and the executor lib tests ofdurable_host::rpc,services::rpcanddurable_host::concurrent.api::scheduled,api::guest_schedule, and inintegration-tests/tests/api/streaming_rpc.rsinternal_invocation_handle_scheduled_rpc_cross_executorandguest_invocation_handles_reach_a_target_on_another_executor(sqlite and postgres). The worker-service lib anddurable_streamstests.bridge_genlib and integration tests for all six languages, andapp::uuid_interop::uuid_values_cross_every_bridge.rpc::ts_invocation_handles,rpc::ts_invocation_handle_cannot_cancel_running,rpc::ts_collected_invocation_handle_does_not_cancel_its_invocation; the Effectcallerintegration case; the ScalaTriggerCallerintegration spec;agent_sdk_go::rpc::go_invocation_handlesandgo_collected_invocation_handle_does_not_cancel_its_invocation;agent_sdk_moonbitmoonbit_invocation_handleson wasm and wasm-gc. The unit suites of all six SDKs.Could not run:
cargo make component-size-reportstops at its export-contract check ("new import interface:wasi:cli/environment") on current main too, because theemptyretention fixture imports the stdwasi:cliinterfaces. The retention test (cargo test -p golem-size-analysis --test retention) ran separately. The broad CLI integration suite did not run.For the reviewer
golem-worker-executor/src/durable_host/rpc/,services/rpc/{direct,invocation_handle,remote}.rs,worker/ingress.rsand the await observer inworker/.Startoftriggerandscheduletrap for repair; before, they dropped the call, which recordedCancelled. The later commits make the executor RPC code easier to read, and each one is a separate step:call.rsopensinvoke-and-awaitandtriggerthrough one function (open_rpc_call). Each host function then resolves the call as a recorded replay or a live run, and delivers the result at one place.remote_call.rsholds the captures of a remote step and its two waits:interruptiblefor a short acceptance andsuspendablefor a long wait that lets the agent suspend.ephemeral.rsholds the creation of the instance of an ephemeral target.schedulecreates this instance inside its own call and records no preparation child, because the key of the schedule derives from itsStartand the target deduplicates the creation by that key.invocation/mod.rsrunsstatus,awaitandcancelthrough one body.services/rpc/invocation_handle.rsholds the local answer to a handle operation. It establishes the authority of the caller first, then answers the operation, then maps a deletion of the owner.RpcCallandRemoteCallkeep their fields private.RpcCallowns the dispatch target, the retry properties and the scope card that the call lends.RemoteCallsends the demand, the invocation and the schedule on behalf of the calling agent. The executor code of this PR uses only private and plainpubitems. A few items keep a restricted visibility. They are part of a struct or module onmainthat uses that visibility for all its items, or apubitem would expose a crate-private type.AGENTS.mdguides in the test components are refreshed by the same rebuild.ToolPrincipalis{issuer, environment_id, tool_name}. Under the starter rule, all standalone invocations of one tool share one starter identity. So one external user can await or cancel an agent invocation that another user started through the same tool, if that user knows the ID. The ID cannot be guessed. Is this intended?