Skip to content
API reference

background-replay

Import
import * as api from "@fungi.computer/puffball/background-replay";
Kind Export Description
type alias BackgroundOrigin Origin evidence, never a retained grant or credential.
type alias ClaimedJobAdmission A claim either passes origin admission or refuses before binding effects.
type alias BackgroundBinding Host-minted replay port; an App cannot declare this binding.
type alias BackgroundWake A host wake cannot confer authority without fresh directory and method admission.
type alias BackgroundMember A retained identity eligible for member-only replay.
type alias BackgroundSyncRefusal One available App’s member-lane cleanup, delivered with zero binding grants.
type alias BackgroundRefusalCode Closed, durable refusal reasons for the affected member lane.
type alias BackgroundAdmission Existing method admission outcomes interpreted by the replay owner.
type alias BackgroundReplayPorts Directory resolution and fresh continuation admission remain host-owned.
type alias BackgroundReplayDecision A refused wake settles its lane; retry uses the existing Carrier backoff.
constant backgroundOriginSchema The caller’s single lightweight grammar for a host-sealed enqueue origin.
constant claimedJobAdmissionSchema The closed result of checking a claimed job’s origin in a fresh replay frame.
constant backgroundWakeSchema Identity and observed revisions only. Unknown fields, including bearer material, refuse.
constant backgroundRefusalCodeSchema The App can settle a refused lane without receiving any binding authority.
constant backgroundSyncRefusalSchema Cleanup payload for one refused member lane; contains no actor or authority.
function backgroundOriginKey() Derive a non-extractable host signing key; no secret is sent to an App.
function sealBackgroundOrigin() Seal only host-verified Instance, member lane and foreground method attribution.
function admitClaimedOrigin() Verify origin evidence against this frame’s fresh admission; guest input never throws.
function actorLane() A queue lane is an actor identity, never a credential or grant.
function mayDefer() Only ordinary member calls may enqueue background work; ancestry is host-held.
function backgroundContext() Host-only projection: replace incoming eligibility with the verified write’s sealed origin.
function mayEnqueueBackground() App-side eligibility reads only the host-attested context; it never invents ancestry.
function readmitBackground() Resolve then re-admit. Observed revisions are evidence, never equality pins.

BackgroundOrigintype alias

Section titled “BackgroundOrigin”
Signature
type BackgroundOrigin = z.output<typeof backgroundOriginSchema>;

Origin evidence, never a retained grant or credential.


ClaimedJobAdmissiontype alias

Section titled “ClaimedJobAdmission”
Signature
type ClaimedJobAdmission = z.output<typeof claimedJobAdmissionSchema>;

A claim either passes origin admission or refuses before binding effects.


BackgroundBindingtype alias

Section titled “BackgroundBinding”
Signature
type BackgroundBinding = Readonly<{
admit: (origin) => Promise<ClaimedJobAdmission>;
}>;

Host-minted replay port; an App cannot declare this binding.


BackgroundWaketype alias

Section titled “BackgroundWake”
Signature
type BackgroundWake = z.output<typeof backgroundWakeSchema>;

A host wake cannot confer authority without fresh directory and method admission.


BackgroundMembertype alias

Section titled “BackgroundMember”
Signature
type BackgroundMember = BackgroundWake["actor"];

A retained identity eligible for member-only replay.


BackgroundSyncRefusaltype alias

Section titled “BackgroundSyncRefusal”
Signature
type BackgroundSyncRefusal = z.output<typeof backgroundSyncRefusalSchema>;

One available App’s member-lane cleanup, delivered with zero binding grants.


BackgroundRefusalCodetype alias

Section titled “BackgroundRefusalCode”
Signature
type BackgroundRefusalCode = z.output<typeof backgroundRefusalCodeSchema>;

Closed, durable refusal reasons for the affected member lane.


BackgroundAdmissiontype alias

Section titled “BackgroundAdmission”
Signature
type BackgroundAdmission =
| Readonly<{
kind: "admitted";
context: AppMethodCallContext;
}>
| Readonly<{
kind: "refused";
code:
| "level_too_low"
| "requires_not_granted"
| "not_approved"
| "denied"
| "unavailable"
| "stale_authority";
}>;

Existing method admission outcomes interpreted by the replay owner.


BackgroundReplayPortstype alias

Section titled “BackgroundReplayPorts”
Signature
type BackgroundReplayPorts<Principal> = Readonly<{
resolve: (actor) => Promise<Principal | null>;
admit: (principal, wake) => Promise<BackgroundAdmission>;
}>;

Directory resolution and fresh continuation admission remain host-owned.

Type Parameter
Principal

BackgroundReplayDecisiontype alias

Section titled “BackgroundReplayDecision”
Signature
type BackgroundReplayDecision =
| Readonly<{
kind: "admitted";
context: AppMethodCallContext;
}>
| Readonly<{
kind: "refused";
code: BackgroundRefusalCode;
}>
| Readonly<{
kind: "retry";
}>;

A refused wake settles its lane; retry uses the existing Carrier backoff.

backgroundOriginSchemaconstant

Section titled “backgroundOriginSchema”
Signature
const backgroundOriginSchema: ZodMiniLazy<
ZodMiniObject<
{
method: ZodMiniString<string>;
seal: ZodMiniString<string>;
},
$strict
>
> = appMethodCallerSchema.shape.backgroundOrigin.def.innerType;

The caller’s single lightweight grammar for a host-sealed enqueue origin.


claimedJobAdmissionSchemaconstant

Section titled “claimedJobAdmissionSchema”
Signature
const claimedJobAdmissionSchema: ZodLazy<
ZodUnion<
readonly [
ZodObject<
{
kind: ZodLiteral<"admitted">;
},
$strict
>,
ZodObject<
{
kind: ZodLiteral<"refused">;
code: ZodLiteral<"access_changed">;
},
$strict
>,
]
>
>;

The closed result of checking a claimed job’s origin in a fresh replay frame.


backgroundWakeSchemaconstant

Section titled “backgroundWakeSchema”
Signature
const backgroundWakeSchema: ZodLazy<
ZodObject<
{
installationId: ZodString;
actor: ZodObject<
{
kind: ZodMiniLiteral<"member">;
memberId: ZodMiniString<string>;
},
$strict
>;
lane: ZodString;
originMethod: ZodString;
observed: ZodObject<
{
authorityVersion: ZodLazy<ZodNumber>;
artifactDigest: ZodCustom<Sha256Digest, Sha256Digest>;
membershipVersion: ZodOptional<ZodLazy<ZodNumber>>;
},
$strict
>;
epoch: ZodLazy<ZodNumber>;
},
$strict
>
>;

Identity and observed revisions only. Unknown fields, including bearer material, refuse.


backgroundRefusalCodeSchemaconstant

Section titled “backgroundRefusalCodeSchema”
Signature
const backgroundRefusalCodeSchema: ZodEnum<{
access_changed: "access_changed";
installation_unavailable: "installation_unavailable";
}>;

The App can settle a refused lane without receiving any binding authority.


backgroundSyncRefusalSchemaconstant

Section titled “backgroundSyncRefusalSchema”
Signature
const backgroundSyncRefusalSchema: ZodObject<
{
lane: ZodString;
code: ZodEnum<{
access_changed: "access_changed";
installation_unavailable: "installation_unavailable";
}>;
},
$strict
>;

Cleanup payload for one refused member lane; contains no actor or authority.

backgroundOriginKey()function

Section titled “backgroundOriginKey()”
Signature
function backgroundOriginKey(secret): Promise<CryptoKey>;

Derive a non-extractable host signing key; no secret is sent to an App.

Parameter Type
secret string

Promise<CryptoKey>


sealBackgroundOrigin()function

Section titled “sealBackgroundOrigin()”
Signature
function sealBackgroundOrigin(
key,
claims,
): Promise<{
method: string;
seal: string;
}>;

Seal only host-verified Instance, member lane and foreground method attribution.

Parameter Type
key CryptoKey
claims Readonly<{ instanceId: string; lane: string; method: string; }>

Promise<{ method: string; seal: string; }>


admitClaimedOrigin()function

Section titled “admitClaimedOrigin()”
Signature
function admitClaimedOrigin(
key,
frame,
raw,
): Promise<
| {
kind: "admitted";
}
| {
kind: "refused";
code: "access_changed";
}
>;

Verify origin evidence against this frame’s fresh admission; guest input never throws.

Parameter Type
key CryptoKey
frame Readonly<{ instanceId: string; lane: string; admitted: readonly string[]; }>
raw unknown

Promise< | { kind: "admitted"; } | { kind: "refused"; code: "access_changed"; }>


Signature
function actorLane(actor): string;

A queue lane is an actor identity, never a credential or grant.

Parameter Type
actor | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; }

string


Signature
function mayDefer(context, ancestry): boolean;

Only ordinary member calls may enqueue background work; ancestry is host-held.

Parameter Type Description
context { computerId: string | null; actor: | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; }; backgroundLane?: string; backgroundOrigin?: { method: string; seal: string; }; role?: "member" | "owner"; soleMember?: true; workflow?: { workflowId: string; runId: string; nodeId: string; armedBy: | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; }; }; idempotencyKey?: string; } -
context.computerId string | null -
context.actor | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; } -
context.backgroundLane? string Host-attested enqueue eligibility for this ordinary write; absent otherwise.
context.backgroundOrigin? { method: string; seal: string; } Host-sealed foreground method for durable jobs; paired with backgroundLane.
context.backgroundOrigin.method string -
context.backgroundOrigin.seal string -
context.role? "member" | "owner" Team role attested by the host, never selected by App method input.
context.soleMember? true The host attests that this member is currently the Team’s only member. Present only on a member’s own call; never on an Agent, Team key or Workflow node, and never selected by App method input.
context.workflow? { workflowId: string; runId: string; nodeId: string; armedBy: | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; }; } Present only on a Workflow node invocation admitted by its host.
context.workflow.workflowId string Published Workflow selected by the run owner.
context.workflow.runId string Run identity held by the run owner.
context.workflow.nodeId string Node selected by the stored published Workflow.
context.workflow.armedBy | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; } Actor that armed the run, re-admitted by the host at dispatch.
context.idempotencyKey? string The host’s stable key for this logical call (for example one Workflow node), the same on every retry. A method with side effects uses it to do its work at most once. Absent when the caller supplies its own request id.
ancestry readonly string[] -

boolean


backgroundContext()function

Section titled “backgroundContext()”
Signature
function backgroundContext(context, ancestry, method, origin): object;

Host-only projection: replace incoming eligibility with the verified write’s sealed origin.

Parameter Type Description
context { computerId: string | null; actor: | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; }; backgroundLane?: string; backgroundOrigin?: { method: string; seal: string; }; role?: "member" | "owner"; soleMember?: true; workflow?: { workflowId: string; runId: string; nodeId: string; armedBy: | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; }; }; idempotencyKey?: string; } -
context.computerId string | null -
context.actor | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; } -
context.backgroundLane? string Host-attested enqueue eligibility for this ordinary write; absent otherwise.
context.backgroundOrigin? { method: string; seal: string; } Host-sealed foreground method for durable jobs; paired with backgroundLane.
context.backgroundOrigin.method string -
context.backgroundOrigin.seal string -
context.role? "member" | "owner" Team role attested by the host, never selected by App method input.
context.soleMember? true The host attests that this member is currently the Team’s only member. Present only on a member’s own call; never on an Agent, Team key or Workflow node, and never selected by App method input.
context.workflow? { workflowId: string; runId: string; nodeId: string; armedBy: | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; }; } Present only on a Workflow node invocation admitted by its host.
context.workflow.workflowId string Published Workflow selected by the run owner.
context.workflow.runId string Run identity held by the run owner.
context.workflow.nodeId string Node selected by the stored published Workflow.
context.workflow.armedBy | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; } Actor that armed the run, re-admitted by the host at dispatch.
context.idempotencyKey? string The host’s stable key for this logical call (for example one Workflow node), the same on every retry. A method with side effects uses it to do its work at most once. Absent when the caller supplies its own request id.
ancestry readonly string[] -
method Readonly<{ name: string; effect: AppApi["methods"][string]["effect"]; }> -
origin | { method: string; seal: string; } | undefined -
Name Type Default value Description
computerId string | null - -
actor | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; } hostActorSchema -
backgroundLane? string - Host-attested enqueue eligibility for this ordinary write; absent otherwise.
backgroundOrigin? object - Host-sealed foreground method for durable jobs; paired with backgroundLane.
backgroundOrigin.method string - -
backgroundOrigin.seal string - -
role? "member" | "owner" - Team role attested by the host, never selected by App method input.
soleMember? true - The host attests that this member is currently the Team’s only member. Present only on a member’s own call; never on an Agent, Team key or Workflow node, and never selected by App method input.
workflow? object - Present only on a Workflow node invocation admitted by its host.
workflow.workflowId string identity Published Workflow selected by the run owner.
workflow.runId string identity Run identity held by the run owner.
workflow.nodeId string identity Node selected by the stored published Workflow.
workflow.armedBy | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; } hostActorSchema Actor that armed the run, re-admitted by the host at dispatch.
idempotencyKey? string - The host’s stable key for this logical call (for example one Workflow node), the same on every retry. A method with side effects uses it to do its work at most once. Absent when the caller supplies its own request id.

mayEnqueueBackground()function

Section titled “mayEnqueueBackground()”
Signature
function mayEnqueueBackground(context): boolean;

App-side eligibility reads only the host-attested context; it never invents ancestry.

Parameter Type Description
context { computerId: string | null; actor: | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; }; backgroundLane?: string; backgroundOrigin?: { method: string; seal: string; }; role?: "member" | "owner"; soleMember?: true; workflow?: { workflowId: string; runId: string; nodeId: string; armedBy: | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; }; }; idempotencyKey?: string; } -
context.computerId string | null -
context.actor | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; } -
context.backgroundLane? string Host-attested enqueue eligibility for this ordinary write; absent otherwise.
context.backgroundOrigin? { method: string; seal: string; } Host-sealed foreground method for durable jobs; paired with backgroundLane.
context.backgroundOrigin.method string -
context.backgroundOrigin.seal string -
context.role? "member" | "owner" Team role attested by the host, never selected by App method input.
context.soleMember? true The host attests that this member is currently the Team’s only member. Present only on a member’s own call; never on an Agent, Team key or Workflow node, and never selected by App method input.
context.workflow? { workflowId: string; runId: string; nodeId: string; armedBy: | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; }; } Present only on a Workflow node invocation admitted by its host.
context.workflow.workflowId string Published Workflow selected by the run owner.
context.workflow.runId string Run identity held by the run owner.
context.workflow.nodeId string Node selected by the stored published Workflow.
context.workflow.armedBy | { kind: "member"; memberId: string; } | { kind: "agent"; agentId: string; } | { kind: "team-key"; keyId: string; } Actor that armed the run, re-admitted by the host at dispatch.
context.idempotencyKey? string The host’s stable key for this logical call (for example one Workflow node), the same on every retry. A method with side effects uses it to do its work at most once. Absent when the caller supplies its own request id.

boolean


readmitBackground()function

Section titled “readmitBackground()”
Signature
function readmitBackground<Principal>(
input,
ports,
): Promise<BackgroundReplayDecision>;

Resolve then re-admit. Observed revisions are evidence, never equality pins.

Type Parameter
Principal
Parameter Type
input unknown
ports BackgroundReplayPorts<Principal>

Promise<BackgroundReplayDecision>

Re-exports backgroundSyncAllowed