Browse documentation
Fountain handbook

Background collaboration

Let an extension read native snapshots and make conditional changes to issues, Git refs, pull requests and reviews, either for the signed-in person or in the background under an approved binding.

On this page

Two ways to change native data

For the signed-in person In the background
Acts as The person using your page or panel A native user an administrator bound to your installation
Authorized by The live browser session, the declared capability and the person's current native permission The enrolled binding, a native personal access token and the actor's current native permission
Available During a page or panel request Any time the backend runs, with no browser
SDK entry point Methods on the request's Authority extensions.RuntimeBackgroundClient()

Both paths use the same conditional operation journal, so they share the same replay and recovery behavior.

How conditional operations behave

Every write carries an operation ID that you choose and store before sending. Fountain records each operation durably and applies these rules:

  • Idempotent replay. Repeating an operation with the same ID and identical intent returns the recorded result without repeating the change. Reusing an ID with a different intent is refused.
  • Expected revision. Background intents name the native revision they were prepared against. Read the revision with ReadNativeRevision before and after gathering your inputs; when both reads are equal and idle, bind that revision to the intent.
  • Deadline. Background intents carry a NotAfter deadline in Unix seconds. An operation that cannot be admitted before it is refused.
  • Separate outcomes. A record reports the effect state (pending, not_committed, committed or indeterminate), the cancellation status (none, pending, cancelled, too_late or indeterminate) and the completion state (pending, complete or needs_intervention). A committed change whose follow-up work, such as notifications, did not finish reports needs_intervention.
  • Lost replies. If a reply is lost, look the operation up by its saved ID. A not_observed lookup does not prove that the operation never happened or cannot still arrive.

Operation IDs are 1 to 128 characters from letters, digits, -, _, . and :.

Operations for the signed-in person

During a page or panel request, Authority methods prepare and perform changes as the signed-in person. Preparation methods return a snapshot with the exact identities, current permissions and an idle native revision. They change nothing and grant nothing. Each change has Submit, Get and Cancel methods and needs its own capability.

Change Prepare with Submit, get and cancel Capability
Comment on an issue or pull request RepositoryCommentSnapshot SubmitHumanComment, GetHumanComment, CancelHumanComment native.repository.comments.write
Edit a title or description RepositoryEditSnapshot SubmitHumanEdit, GetHumanEdit, CancelHumanEdit native.repository.discussions.edit
Close or reopen RepositoryStateSnapshot SubmitHumanState, GetHumanState, CancelHumanState native.repository.discussions.state
Lock or unlock a conversation RepositoryLockSnapshot SubmitHumanLock, GetHumanLock, CancelHumanLock native.repository.discussions.lock
Create an issue RepositoryIssueCreateSnapshot SubmitHumanIssueCreate, GetHumanIssueCreate, CancelHumanIssueCreate native.repository.issues.create
Create a pull request RepositoryPullCreateSnapshot SubmitHumanPullCreate, GetHumanPullCreate, CancelHumanPullCreate native.repository.pulls.create
Review a pull request RepositoryReviewSnapshot SubmitHumanReview, GetHumanReview, CancelHumanReview native.repository.reviews.write
Add an inline review comment RepositoryInlineSnapshot SubmitHumanInline, GetHumanInline, CancelHumanInline native.repository.reviews.write
Resolve or unresolve a review thread RepositoryThreadSnapshot SubmitHumanThread, GetHumanThread, CancelHumanThread native.repository.reviews.write
Request reviewers RepositoryReviewRequestSnapshot SubmitHumanReviewRequest, GetHumanReviewRequest, CancelHumanReviewRequest native.repository.reviews.write
Merge a pull request RepositoryMergeSnapshot SubmitHumanMerge, GetHumanMerge, CancelHumanMerge native.repository.merges.write
Mark a pull request as manually merged RepositoryManualMergeSnapshot SubmitHumanManualMerge, GetHumanManualMerge, CancelHumanManualMerge native.repository.merges.write

Preparation snapshots need native.repository.read; on a repository page with issues permission, a package that declares native.repository.issues.read can also prepare issue changes without code access. Build each operation ID with the matching helper, such as HumanCommentOperationID(actor, repository, command), from the native actor and repository IDs and your own command ID. Persist the ID and the intent before you submit.

Fountain rechecks the person's session, the package instance and native permission when the change commits, not only when it is submitted. Merges support the methods the repository allows: merge, rebase, rebase-merge, squash and fast-forward-only. Capabilities never replace native permission: a person who cannot merge in the forge cannot merge through an extension.

Approve background access

Background work needs an administrator's approval for each combination of installation, token, actor, repository and operation kind.

  1. Declare native.background.operations in the manifest. The host then delivers a background admission to the backend after it starts.

  2. Find the package's installation UUID. It is stable across replacement and changes only when the package is removed and installed again.

    fountain extensions installation hello
    
  3. Create a native personal access token for the acting user. Changes need the write:repository scope; snapshot reads need read:repository, plus read:issue for issue families. If the token is restricted to specific repositories, include the target repository. A token limited to public repositories cannot act on private ones.

  4. Look up the numeric IDs of the token, the user and the repository, for example with Forgejo's API: GET /api/v1/users/USERNAME/tokens, GET /api/v1/users/USERNAME and GET /api/v1/repos/OWNER/REPO.

  5. Enroll a binding for each operation kind the extension needs:

    fountain extensions bind \
      --installation 3f0c5c1e-7d1a-4c55-9a43-0b7f4c2e8d11 \
      --token-id 12 --actor-id 4 --repository-id 7 \
      --kind pull_request.create
    

bind, bindings and unbind use the live database and are safe while the forge runs. Binding the same values again is accepted without creating a duplicate. Enrollment checks that the token belongs to the actor and that the actor and repository exist; the token's secret, scopes, account state and permissions are checked again on every submission.

Command Purpose
extensions bind --installation UUID --token-id N --actor-id N --repository-id N --kind KIND Enroll one binding
extensions bindings --installation UUID List bindings as ID, token, actor, repository and kind; never secrets
extensions unbind --installation UUID --token-id N --actor-id N --repository-id N --kind KIND Revoke a binding; new submissions under it are refused

A binding for one kind grants nothing for another. Effective authority is always the intersection of the binding, the token's scopes and repository restrictions, and the actor's current native permission.

Operation kinds

Kind What it does
git.ref.publish Publish a Git ref
issue.comment.publish Publish an issue comment
issue.graph.mutate Create and edit issues and add or remove dependencies in one repository, as one packet
issue.lifecycle.apply Apply issue lifecycle changes
pull_request.create Create a pull request
pull_request.merge Merge an exact pull request candidate, fast-forward only
pull_request.review.request Request reviewers
pull_request.review.submit Submit a review
pull_request.review.thread.resolve Resolve a review thread

The bind command also accepts execution.launch, an enrollment-only kind used by controller execution grants; it is not a background operation kind.

An issue.graph.mutate packet holds at most 64 changes and 48 KiB of encoded payload. New issues use request-local keys, existing issues use database IDs, and a cycle, stale edit or invalid reference refuses the whole packet. A pull_request.merge intent names the exact pull request, head and base refs and expected commit IDs, with fast-forward-only as its only method.

Use the background client

client, err := extensions.RuntimeBackgroundClient()
if err != nil {
	return err // the capability is not declared or the host has not delivered admission
}
supported, err := client.ReadOperations(ctx)
Method Purpose
ReadOperations The installation, a stable generation and the operation kinds this forge supports. Submit only listed kinds.
ReadNativeRevision One observation of the native revision and whether it is idle
ReadSnapshot Native snapshots for selected families of one repository
ReadCreations Recover the native records an earlier operation created
SubmitOperation Submit an OperationIntent
GetOperation Look up an operation by ID
CancelOperation Request cancellation of an operation by ID

Calls that read or write native data take an extensions.CredentialFile: the path of a file holding the personal access token. The file must be a regular file of at most 4096 bytes that other users cannot access. The SDK reads it for each call and sends the secret over the private socket; the host never reads the path.

Snapshot families are repository_writers, repository_issues, issue, comments, dependencies, pull, reviews, review_threads, merge_eligibility, checks, refs and ancestry. A repository_writers read reports the current code-write permission of up to eight actors; it is an observation, not authority.

Services outside the backend

A separate service process can obtain a background client too, through the shared service callback socket. Declare native.service.bridge, configure SERVICE_CALLBACK_PATH and map the service's Unix user ID to your package with SERVICE_BRIDGE_PEERS (see the Extension configuration reference). The service then calls extensions.BootstrapServiceBackground with the socket path and the forge's expected Unix user ID. The host admits only the mapped peer.

Recovery

If the forge stops while an operation holds the native write reservation, an operator reconciles it offline; see Native operation recovery. Recovery never replays a write.

Continue

Look up each capability string in the Capabilities reference.