Sign approval decisions
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:
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}Then it parks a deploy and decides it signed:
_, 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 sideif 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 backif err != nil { return err}resume, err := s.DecideSigned(ctx, signed) // verified, then recorded, then resumedif err != nil { return err}res, err := resume.Wait()if err != nil { return err}fmt.Fprintln(w, "resumed:", res.Text())unsigned: true | requires signed: truechallenge: request e_a4 run s_signed-t1 key ops-1 | nonce: true | expires: 2026-10-18T10:00:00Zresumed: 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).
Sign a decision
Section titled “Sign a decision”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:
_, err = thread.Open(ctx, st, "s_signed", agent) // no keyring: the header's rule cannot be metfmt.Fprintln(w, "open without a keyring:", err)
again, err := thread.Open(ctx, st, "s_signed", agent, ids("", "b"), thread.WithKeyring(ring)) // no RequireSigned passedif err != nil { return err}fmt.Fprintln(w, "requires signed:", again.RequiresSigned(), "| header:", again.Meta()["weft.require_signed"])open without a keyring: thread: RequireSigned needs WithKeyring: without a keyring no decision could be verifiedrequires signed: true | header: trueCreate 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 field | Holds |
|---|---|
ID | The request entry’s id: this occurrence of the call. Empty on the request an Approver is handed. |
Session | The session the request lives in. |
CallID, Tool | The pending call’s id and tool name. |
Args, ArgsSHA256 | The arguments as the model wrote them, and their hex SHA-256. |
RunID | The run that parked the call. |
Reason | Why it parked. |
Expiry, Created | When it lapses (zero: never) and when it was persisted. |
Nonce, KeyID | The challenge and the key it was minted under; set by Request only. |
Child | The 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 withthread.ErrUnknownKeywhen 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 underQuorumit 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 keyreq.KeyIDnames. An emptyd.Whois 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 field | Holds |
|---|---|
Session, RequestID, RunID | The occurrence the challenge was minted for. |
CallID, Tool, ArgsSHA256 | The call it answers, and the arguments hash the signer approved. |
Expiry | The request’s expiry as the challenge stated it; it must equal the request’s own. |
Kind, Reason, Content, Always | The decision: the outcome, a deny reason, a resolve payload, approve-and-always-allow. |
Who | A label for the audit trail; the identity is KeyID. |
Nonce, KeyID, MAC | The 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:
| Check | Error |
|---|---|
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.
Security properties
Section titled “Security properties”No refusal records a decision from the signer:
_, err = s.DecideSigned(ctx, signed) // the same bytes againfmt.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 := challengestranger.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 lateif 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) }}replayed: trueforged: true | still pending: 1unknown key: trueexpired: trueaudit: signed refused call_1 | replayedaudit: signed refused call_2 | bad signatureaudit: signed refused call_2 | expiredThe 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_1cannot approve a later turn’scall_1(ErrNotPending). The challenge domain isweft/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. RequireSignedis durable. It lives in the header: everyOpenenforces 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
Branchback 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
ErrBadSignatureand cost the same time, soDecideSignedtells a caller nothing about which ids exist. Onlyring.Sign, on the ring holder’s side, saysErrUnknownKey. - Refusals are audited, within bounds. A refused signature leaves a
StepSignedaudit 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.
Complete example
Section titled “Complete example”sessions/signed.go decides signed, then shows each refusal and a reopen:
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 on GitHub · run it from docs-site/examples:
go run ./sessions signedgo test ./sessions== signed decisionunsigned: true | requires signed: truechallenge: request e_a4 run s_signed-t1 key ops-1 | nonce: true | expires: 2026-10-18T10:00:00Zresumed: Prod is live.== refusalsreplayed: trueforged: true | still pending: 1unknown key: trueexpired: trueaudit: signed refused call_1 | replayedaudit: signed refused call_2 | bad signatureaudit: signed refused call_2 | expired== reopenopen without a keyring: thread: RequireSigned needs WithKeyring: without a keyring no decision could be verifiedrequires signed: true | header: trueStderr 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).
Best practices & gotchas
Section titled “Best practices & gotchas”- 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.
Requestwrites nothing for a live request, and each nonce answers one decision; a reused signature isErrReplay. (Source:thread/signing.go:408-420) - Pass
WithKeyringon everyOpen. A session created withRequireSignedcannot 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 whateverWhoit 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
KeyIDandWho. The signed decision’s key id rides the resumed run asweft.approval.actor. (Source:thread/approval.go:157-166)
See also
Section titled “See also”- Approvals in sessions:
Pending,Decide, grants, quorum and expiry - Require human approval for a tool: the core boundary
- Operate sessions in production: key rotation and the approvals runbook
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