Skip to content

Sign approval decisions

View as Markdown

A signed decision is an approval that crossed a process boundary, a web UI or a chat integration, and can be checked: the session mints a challenge over one pending request with s.Request(callID), the signing side signs a decision over it with ring.Sign or key.Sign, and s.DecideSigned verifies it before anything is recorded. thread.RequireSigned() refuses every unsigned decision, for the session’s whole life.

sessions/signed.go builds a keyring and a session that requires signed decisions:

sessions/signed.go
ring, err := thread.NewKeyring(thread.Key{
ID: "ops-1", // only the id is ever written to the session
Secret: []byte("held by the approval service only"), // never written anywhere by thread
Active: true, // new challenges are minted under it
})
if err != nil {
return err
}
s, err := thread.Create(ctx, st, agent, ids("s_signed", "a"), thread.Clock(c.now),
thread.WithKeyring(ring),
thread.RequireSigned(), // stored in the header: every Open enforces it
thread.RequestExpiry(time.Hour))
if err != nil {
return err
}

sessions/signed.go on GitHub

Then it parks a deploy and decides it signed:

sessions/signed.go
_, err = s.Decide(ctx, thread.Approve("call_1"))
fmt.Fprintln(w, "unsigned:", errors.Is(err, thread.ErrSignatureRequired), "| requires signed:", s.RequiresSigned())
challenge, err := s.Request("call_1") // a fresh challenge; travels to the signing side
if err != nil {
return err
}
fmt.Fprintln(w, "challenge: request", challenge.ID, "run", challenge.RunID, "key", challenge.KeyID,
"| nonce:", challenge.Nonce != "", "| expires:", challenge.Expiry.Format(time.RFC3339))
signed, err := ring.Sign(challenge, thread.Approve("call_1")) // travels back
if err != nil {
return err
}
resume, err := s.DecideSigned(ctx, signed) // verified, then recorded, then resumed
if err != nil {
return err
}
res, err := resume.Wait()
if err != nil {
return err
}
fmt.Fprintln(w, "resumed:", res.Text())

sessions/signed.go on GitHub

unsigned: true | requires signed: true
challenge: request e_a4 run s_signed-t1 key ops-1 | nonce: true | expires: 2026-10-18T10:00:00Z
resumed: Prod is live.

The unsigned Decide was refused with thread.ErrSignatureRequired. The challenge names the request entry and the run that parked the call, and the signed approval resumed the session as Decide would (Approvals in sessions).

The keyring. A thread.Keyring holds HMAC-SHA256 keys by id. thread.NewKeyring(keys...) needs at least one thread.Key: each a non-empty, unique ID, a non-empty Secret of any length, and Active on at most one. Every key verifies; the active key is the one new challenges are minted under. A ring with no active key is verify-only: it checks decisions over earlier challenges and mints none. A ring is immutable and safe for concurrent use. Keys never touch the session file, only key ids do, so a leaked file cannot forge a decision.

The session. thread.WithKeyring(r) makes the session verify under r and mint challenges from its active key. A ring is configuration, not state: pass it at every Create and Open. RequireSigned adds the rule that only signed decisions count. Create writes it into the header as the metadata key weft.require_signed, so every later Open enforces it whether or not it passes the option, a Fork inherits it (with the origin’s keyring unless given its own), and pool children inherit it. Nothing loosens it. s.RequiresSigned() reports it, for a caller that must know before it promises a decision:

sessions/signed.go
_, err = thread.Open(ctx, st, "s_signed", agent) // no keyring: the header's rule cannot be met
fmt.Fprintln(w, "open without a keyring:", err)
again, err := thread.Open(ctx, st, "s_signed", agent, ids("", "b"), thread.WithKeyring(ring)) // no RequireSigned passed
if err != nil {
return err
}
fmt.Fprintln(w, "requires signed:", again.RequiresSigned(), "| header:", again.Meta()["weft.require_signed"])

sessions/signed.go on GitHub

open without a keyring: thread: RequireSigned needs WithKeyring: without a keyring no decision could be verified
requires signed: true | header: true

Create and Open fail when RequireSigned is in force and the session has no keyring, or a ring with no active key: no call it parked could ever be decided. Under the rule the session’s own machinery still records, each with its audit entry: grants, the Approver, expiry, an interrupting Send’s denial, a pool delegation’s resolution.

The challenge. s.Request(callID) returns the pending thread.Request with a fresh nonce and the active key’s id. For a live request it writes nothing and may be called any number of times, each call minting another valid challenge. It fails with ErrNotPending for a call that is not pending, ErrDelegated for a call that delegates to a pool child, ErrExpired for a request past its expiry, and an error when the session has no keyring with an active key.

A lapsed request is swept before ErrExpired returns, as every other path sweeps it. Request records the expiry’s denial, so Pending stops offering it, and, under AutoResume (the default), resumes the boundary when that completes it. Under RequireSigned no unsigned Decide comes to sweep it. Once any path has denied it, Request, Decide and DecideSigned for it fail with ErrNotPending, not ErrExpired (expiry). The Pending() view of the same request carries no nonce.

Request fieldHolds
IDThe request entry’s id: this occurrence of the call. Empty on the request an Approver is handed.
SessionThe session the request lives in.
CallID, ToolThe pending call’s id and tool name.
Args, ArgsSHA256The arguments as the model wrote them, and their hex SHA-256.
RunIDThe run that parked the call.
ReasonWhy it parked.
Expiry, CreatedWhen it lapses (zero: never) and when it was persisted.
Nonce, KeyIDThe challenge and the key it was minted under; set by Request only.
ChildThe pool child session a mirrored request parks in; empty on an ordinary request.

The signature. The signing side signs with what it holds, and each returns a thread.SignedDecision:

  • ring.Sign(req, d) for a process holding the whole ring: it looks up the key the challenge names, and fails with thread.ErrUnknownKey when the ring does not hold it.
  • key.Sign(req, d) for an approver holding a key of their own: the signature names that key, whichever key minted the challenge, so under Quorum it counts as this approver. The verifying ring must hold the key (ExampleQuorum).
  • thread.SignDecision(secret, req, d) for a signer with a bare secret, the key req.KeyID names. An empty d.Who is signed as the key’s id.

ring.Sign and key.Sign fail on a request without a nonce, the Pending view; key.Sign also on a key with no id or secret. Both arrived in thread 0.9.0, replacing a hand-kept map of secrets passed to SignDecision. The MAC covers the challenge and the decision together, so neither can be altered in flight:

SignedDecision fieldHolds
Session, RequestID, RunIDThe occurrence the challenge was minted for.
CallID, Tool, ArgsSHA256The call it answers, and the arguments hash the signer approved.
ExpiryThe request’s expiry as the challenge stated it; it must equal the request’s own.
Kind, Reason, Content, AlwaysThe decision: the outcome, a deny reason, a resolve payload, approve-and-always-allow.
WhoA label for the audit trail; the identity is KeyID.
Nonce, KeyID, MACThe challenge answered, the signing key, and the HMAC-SHA256 over every field above.

The verification. s.DecideSigned(ctx, sd) records no decision until every check passes (the expiry sweep’s own denials and a refusal’s audit entry may still land), then records the decision with Via signed, its nonce and key id, and resumes when the boundary completes, as Decide does. The checks, in order:

CheckError
The MAC under the key sd.KeyID names (constant-time), an outcome that is one of the four, this session, a non-empty nonce. An unknown key id fails the same way, in the same words.ErrBadSignature
The nonce has not answered a recorded decision.ErrReplay
The request is not past its own expiry, by the session’s clock.ErrExpired
A pending call with that id, and the occurrence signed (request entry and run).ErrNotPending
A nonce the ring minted for this request, and the request’s own expiry.ErrBadSignature
The arguments hash is the request’s.ErrArgsChanged
The tool is the request’s.ErrBadSignature

A signature that passes every check but names a call delegating to a pool child fails with ErrDelegated, unrecorded. DecideSigned without a keyring fails. The package example is ExampleSession_DecideSigned.

Rotation. Build a new ring with the new key active and the old keys still in it, and hand it to sessions as they open: requests challenged under an old key keep verifying. Drop an old key only when nothing minted under it can still be pending; after that a decision signed with it is ErrBadSignature.

No refusal records a decision from the signer:

sessions/signed.go
_, err = s.DecideSigned(ctx, signed) // the same bytes again
fmt.Fprintln(w, "replayed:", errors.Is(err, thread.ErrReplay))
parked, err = s.Send(ctx, weft.User("Deploy to prod again."))
if err != nil {
return err
}
if _, err := parked.Wait(); err != nil {
return err
}
challenge, err = s.Request("call_2")
if err != nil {
return err
}
forged, err := thread.Key{ID: "ops-1", Secret: []byte("a guess")}.Sign(challenge, thread.Approve("call_2"))
if err != nil {
return err
}
_, err = s.DecideSigned(ctx, forged)
fmt.Fprintln(w, "forged:", errors.Is(err, thread.ErrBadSignature), "| still pending:", len(s.Pending()))
stranger := challenge
stranger.KeyID = "ops-9" // a key this ring does not hold
_, err = ring.Sign(stranger, thread.Approve("call_2"))
fmt.Fprintln(w, "unknown key:", errors.Is(err, thread.ErrUnknownKey))
late, err := ring.Sign(challenge, thread.Approve("call_2")) // genuine, but signed too late
if err != nil {
return err
}
c.advance(2 * time.Hour) // past the request's own expiry
_, err = s.DecideSigned(ctx, late)
fmt.Fprintln(w, "expired:", errors.Is(err, thread.ErrExpired))
if _, err := parked.Next().Wait(); err != nil { // the session denied it and resumed
return err
}
for _, e := range s.Audit() {
if a, ok := e.(thread.ApprovalAuditEntry); ok && a.Step == thread.StepSigned {
fmt.Fprintln(w, "audit:", a.Step, a.Outcome, a.CallID, "|", a.Detail)
}
}

sessions/signed.go on GitHub

replayed: true
forged: true | still pending: 1
unknown key: true
expired: true
audit: signed refused call_1 | replayed
audit: signed refused call_2 | bad signature
audit: signed refused call_2 | expired

The forged signature left the call pending. The unknown key was refused on the signer’s side, by ring.Sign. The expired request was then denied by the session itself, with its stated reason, and the parked turn’s Next resumed it. What the signing guarantees, as of thread 0.9.0:

  • A signature answers one occurrence. The challenge signs the request entry’s id and the run id beside the call id, and both are checked against the pending request, so a signature for one turn’s call_1 cannot approve a later turn’s call_1 (ErrNotPending). The challenge domain is weft/approval-challenge/v2; no v1 signature verifies, so a challenge minted before thread 0.9.0 must be requested again.
  • A nonce is the session’s. An empty nonce is a bad signature, and the nonce must carry a tag only a ring key can compute for that request, so a nonce made up elsewhere or lifted from another challenge fails. Nonces are recorded on decision entries, so the replay guard survives restarts.
  • The request’s expiry rules. The session enforces the request’s own expiry, by its clock, on every path that records a decision or arms a resume (Decide, DecideSigned, Resume, Send, the runner’s pickup), never the expiry the signer stated.
  • RequireSigned is durable. It lives in the header: every Open enforces it, a fork and a pool child inherit it, and it does not block the session’s own denials and resolutions.
  • A decision is spent by its resume. After a Branch back to a decided boundary the calls are pending again and need new signatures.
  • Quorum counts keys. One key that signs as two Whos is one approver; give every approver their own key.
  • Key ids stay private. An unknown key id and a bad MAC both read ErrBadSignature and cost the same time, so DecideSigned tells a caller nothing about which ids exist. Only ring.Sign, on the ring holder’s side, says ErrUnknownKey.
  • Refusals are audited, within bounds. A refused signature leaves a StepSigned audit entry naming the reason, the call and, when the ring holds it, the key; at most 16 per request, and nothing for a signature that fails its MAC and names no pending call (the audit trail).

What it does not cover: s.Grant stays an in-process, unsigned call, so whoever can call it can pre-approve; the audit trail is plain appended lines, not tamper-evidence; and a signed decision’s Who is a label, its key the identity.

sessions/signed.go decides signed, then shows each refusal and a reopen:

sessions/signed.go
package main
import (
"context"
"errors"
"fmt"
"io"
"time"
"github.com/weftgo/weft"
"github.com/weftgo/weft/thread"
"github.com/weftgo/weft/thread/jsonl"
"github.com/weftgo/weft/wefttest"
)
// demoSigned is the page "Sign approval decisions".
func demoSigned(ctx context.Context, w io.Writer, dir string) error {
agent := weft.New(wefttest.Script(
deployCall("call_1", "prod"), wefttest.Say("Prod is live."),
deployCall("call_2", "prod"), wefttest.Say("The second deploy lapsed."),
), deployTool())
st, err := jsonl.Open(dir)
if err != nil {
return err
}
c := &clock{t: base}
fmt.Fprintln(w, "== signed decision")
ring, err := thread.NewKeyring(thread.Key{
ID: "ops-1", // only the id is ever written to the session
Secret: []byte("held by the approval service only"), // never written anywhere by thread
Active: true, // new challenges are minted under it
})
if err != nil {
return err
}
s, err := thread.Create(ctx, st, agent, ids("s_signed", "a"), thread.Clock(c.now),
thread.WithKeyring(ring),
thread.RequireSigned(), // stored in the header: every Open enforces it
thread.RequestExpiry(time.Hour))
if err != nil {
return err
}
parked, err := s.Send(ctx, weft.User("Deploy to prod."))
if err != nil {
return err
}
if _, err := parked.Wait(); err != nil {
return err
}
_, err = s.Decide(ctx, thread.Approve("call_1"))
fmt.Fprintln(w, "unsigned:", errors.Is(err, thread.ErrSignatureRequired), "| requires signed:", s.RequiresSigned())
challenge, err := s.Request("call_1") // a fresh challenge; travels to the signing side
if err != nil {
return err
}
fmt.Fprintln(w, "challenge: request", challenge.ID, "run", challenge.RunID, "key", challenge.KeyID,
"| nonce:", challenge.Nonce != "", "| expires:", challenge.Expiry.Format(time.RFC3339))
signed, err := ring.Sign(challenge, thread.Approve("call_1")) // travels back
if err != nil {
return err
}
resume, err := s.DecideSigned(ctx, signed) // verified, then recorded, then resumed
if err != nil {
return err
}
res, err := resume.Wait()
if err != nil {
return err
}
fmt.Fprintln(w, "resumed:", res.Text())
fmt.Fprintln(w, "== refusals")
_, err = s.DecideSigned(ctx, signed) // the same bytes again
fmt.Fprintln(w, "replayed:", errors.Is(err, thread.ErrReplay))
parked, err = s.Send(ctx, weft.User("Deploy to prod again."))
if err != nil {
return err
}
if _, err := parked.Wait(); err != nil {
return err
}
challenge, err = s.Request("call_2")
if err != nil {
return err
}
forged, err := thread.Key{ID: "ops-1", Secret: []byte("a guess")}.Sign(challenge, thread.Approve("call_2"))
if err != nil {
return err
}
_, err = s.DecideSigned(ctx, forged)
fmt.Fprintln(w, "forged:", errors.Is(err, thread.ErrBadSignature), "| still pending:", len(s.Pending()))
stranger := challenge
stranger.KeyID = "ops-9" // a key this ring does not hold
_, err = ring.Sign(stranger, thread.Approve("call_2"))
fmt.Fprintln(w, "unknown key:", errors.Is(err, thread.ErrUnknownKey))
late, err := ring.Sign(challenge, thread.Approve("call_2")) // genuine, but signed too late
if err != nil {
return err
}
c.advance(2 * time.Hour) // past the request's own expiry
_, err = s.DecideSigned(ctx, late)
fmt.Fprintln(w, "expired:", errors.Is(err, thread.ErrExpired))
if _, err := parked.Next().Wait(); err != nil { // the session denied it and resumed
return err
}
for _, e := range s.Audit() {
if a, ok := e.(thread.ApprovalAuditEntry); ok && a.Step == thread.StepSigned {
fmt.Fprintln(w, "audit:", a.Step, a.Outcome, a.CallID, "|", a.Detail)
}
}
if err := s.Close(ctx); err != nil {
return err
}
fmt.Fprintln(w, "== reopen")
_, err = thread.Open(ctx, st, "s_signed", agent) // no keyring: the header's rule cannot be met
fmt.Fprintln(w, "open without a keyring:", err)
again, err := thread.Open(ctx, st, "s_signed", agent, ids("", "b"), thread.WithKeyring(ring)) // no RequireSigned passed
if err != nil {
return err
}
fmt.Fprintln(w, "requires signed:", again.RequiresSigned(), "| header:", again.Meta()["weft.require_signed"])
return again.Close(ctx)
}

View sessions/signed.go on GitHub

View on GitHub · run it from docs-site/examples:

Terminal window
go run ./sessions signed
go test ./sessions
== signed decision
unsigned: true | requires signed: true
challenge: request e_a4 run s_signed-t1 key ops-1 | nonce: true | expires: 2026-10-18T10:00:00Z
resumed: Prod is live.
== refusals
replayed: true
forged: true | still pending: 1
unknown key: true
expired: true
audit: signed refused call_1 | replayed
audit: signed refused call_2 | bad signature
audit: signed refused call_2 | expired
== reopen
open without a keyring: thread: RequireSigned needs WithKeyring: without a keyring no decision could be verified
requires signed: true | header: true

Stderr also carries the no-window WARN line once per Session value that runs a turn: once here, since the reopened session runs none. sessions/sessions_test.go also pins that a forged signature records no decision and resolves nothing, and that RequireSigned survives a reopen that does not pass it. weft’s thread/examples/approvals runs the same flow across a restart (the approvals example).

  • Keep secrets in the signing process. The session needs the ring to verify; the session file never holds key bytes, only ids. (Source: thread/signing.go:23-25; ADR 0021 §3)
  • Mint a fresh challenge per signature. Request writes nothing for a live request, and each nonce answers one decision; a reused signature is ErrReplay. (Source: thread/signing.go:408-420)
  • Pass WithKeyring on every Open. A session created with RequireSigned cannot be opened without a ring that has an active key. (Source: thread/signing.go:171-188; thread-operations §11)
  • Give each approver their own key under Quorum. A key is one identity whatever Who it signs. (Source: thread/approval.go:1437-1451; CHANGELOG.md:3642)
  • Keep old keys through a rotation. Drop one only when nothing it challenged can still be pending. (Source: thread-operations §11)
  • Put an opaque id in KeyID and Who. The signed decision’s key id rides the resumed run as weft.approval.actor. (Source: thread/approval.go:157-166)

Symbols used: thread.NewKeyring · thread.Keyring · Keyring.Sign · thread.Key · Key.Sign · thread.SignDecision · thread.SignedDecision · thread.WithKeyring · thread.RequireSigned · thread.Request · Session.Request · Session.DecideSigned · Session.RequiresSigned · Session.Audit · thread.RequestExpiry · thread.Clock · thread.ErrBadSignature · thread.ErrReplay · thread.ErrExpired · thread.ErrArgsChanged · thread.ErrUnknownKey · thread.ErrSignatureRequired · jsonl.Open