Documentation
¶
Overview ¶
Package store is the log of record (SP2 §4): one gapless, append-only sequence per room, in PostgreSQL. The database enforces the invariants too (migrations/20260927120000_rooms.sql), so a bug or a stolen broker credential cannot rewrite history.
Index ¶
- Constants
- Variables
- func IsDataError(err error) bool
- func Migrate(ctx context.Context, dsn string, log *slog.Logger) (int, error)
- type Approval
- type NewRoom
- type Queued
- type RoomState
- type SlackCode
- type SlackLink
- type Store
- func (s *Store) Append(ctx context.Context, d envelope.Draft) (envelope.Event, bool, error)
- func (s *Store) AppendAsBridge(ctx context.Context, bridgeRun string, d envelope.Draft) (envelope.Event, bool, error)
- func (s *Store) AppendAsDriver(ctx context.Context, driver string, epoch int64, d envelope.Draft) (envelope.Event, bool, error)
- func (s *Store) Approval(ctx context.Context, id string) (Approval, error)
- func (s *Store) BriefSources(ctx context.Context, roomID string) ([]envelope.Event, error)
- func (s *Store) BriefSourcesThrough(ctx context.Context, roomID string, seq int64) ([]envelope.Event, error)
- func (s *Store) ChangeDriver(ctx context.Context, roomID string, expect int64, to, reason string, ...) (envelope.Event, bool, error)
- func (s *Store) ClaimBridge(ctx context.Context, roomID, runID string, ...) (string, bool, error)
- func (s *Store) Close()
- func (s *Store) CloseRoom(ctx context.Context, roomID, reason string) error
- func (s *Store) Cursor(ctx context.Context, roomID, originClient string) (int64, error)
- func (s *Store) Decide(ctx context.Context, approvalID, decision, by, reason string, d envelope.Draft) (envelope.Event, Approval, error)
- func (s *Store) Deliveries(ctx context.Context, roomID, runID string, after, through int64, limit int) ([]envelope.Event, error)
- func (s *Store) Disable(ctx context.Context, sub string) error
- func (s *Store) DriverSeen(ctx context.Context, roomID, principal string, acted bool) error
- func (s *Store) Enqueue(ctx context.Context, d envelope.Draft, author, text string) (envelope.Event, error)
- func (s *Store) EnsureRoom(ctx context.Context, r NewRoom) (bool, error)
- func (s *Store) ExpireDriver(ctx context.Context, roomID string, expect int64, to string, d envelope.Draft) (envelope.Event, bool, error)
- func (s *Store) ExpireDue(ctx context.Context) ([]envelope.Event, error)
- func (s *Store) ExpiredVerdicts(ctx context.Context, before time.Time, limit int) ([]envelope.Event, error)
- func (s *Store) Failed(ctx context.Context, sub string) (failures int, err error)
- func (s *Store) Fork(ctx context.Context, src string, upTo int64, r NewRoom, d envelope.Draft, ...) (envelope.Event, error)
- func (s *Store) Lagging(ctx context.Context, sub string, limit int) ([]string, error)
- func (s *Store) LapsedDrivers(ctx context.Context) ([]RoomState, error)
- func (s *Store) LastAck(ctx context.Context, roomID, runID string) (int64, error)
- func (s *Store) LastEventAt(ctx context.Context, ids []string) (map[string]time.Time, error)
- func (s *Store) LastHarnessEnd(ctx context.Context, roomID, runID string) (string, error)
- func (s *Store) LastHarnessStatus(ctx context.Context, roomID, runID string) (string, error)
- func (s *Store) LastTaskState(ctx context.Context, roomID string, after int64) (json.RawMessage, error)
- func (s *Store) LinkSlack(ctx context.Context, codeSHA256 []byte, team, sub string, now time.Time) (SlackCode, error)
- func (s *Store) Listen(ctx context.Context, ready func(), fn func(roomID string, seq int64)) error
- func (s *Store) MintSlackCode(ctx context.Context, codeSHA256 []byte, c SlackCode, now time.Time) error
- func (s *Store) OldestPending(ctx context.Context) (time.Duration, int, error)
- func (s *Store) OpenApprovals(ctx context.Context, roomID string) ([]Approval, error)
- func (s *Store) PendingApprovals(ctx context.Context, roomID string) (int, error)
- func (s *Store) PendingRuns(ctx context.Context, roomID string, within time.Duration) ([]string, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) PromoteQueued(ctx context.Context, roomID string, ref int64, driver string, epoch int64, ...) (envelope.Event, error)
- func (s *Store) Prompters(ctx context.Context, roomID, runID string) ([]string, error)
- func (s *Store) PurgeExpired(ctx context.Context) (rooms, events int64, err error)
- func (s *Store) Queue(ctx context.Context, roomID string) ([]Queued, error)
- func (s *Store) Range(ctx context.Context, roomID string, afterSeq int64, limit int) ([]envelope.Event, error)
- func (s *Store) RecordRunRequest(ctx context.Context, d envelope.Draft, runID string, refs []int64, ...) (envelope.Event, error)
- func (s *Store) RemoveQueued(ctx context.Context, roomID string, ref int64, d envelope.Draft) (envelope.Event, error)
- func (s *Store) RequestApproval(ctx context.Context, a Approval, d envelope.Draft) (Approval, envelope.Event, error)
- func (s *Store) Room(ctx context.Context, id string) (RoomState, error)
- func (s *Store) SchemaReady(ctx context.Context) (bool, error)
- func (s *Store) SetQueued(ctx context.Context, roomID string, ref int64, to, runID string) error
- func (s *Store) SetWebhookCursor(ctx context.Context, sub, room string, seq int64) error
- func (s *Store) SlackCode(ctx context.Context, codeSHA256 []byte, now time.Time) (SlackCode, error)
- func (s *Store) SlackLink(ctx context.Context, team, user string) (sub string, found bool, err error)
- func (s *Store) SlackLinksOf(ctx context.Context, sub string) ([]SlackLink, error)
- func (s *Store) Stored(ctx context.Context, d envelope.Draft) (envelope.Event, bool, error)
- func (s *Store) Subscriber(ctx context.Context, sub string, generation int) (failures int, disabled bool, err error)
- func (s *Store) Succeeded(ctx context.Context, sub string) error
- func (s *Store) SupersedeAnswered(ctx context.Context) ([]envelope.Event, error)
- func (s *Store) TaskReasons(ctx context.Context, after map[string]int64) (map[string]string, error)
- func (s *Store) TaskStateAt(ctx context.Context, roomID string, after, upTo int64) (json.RawMessage, error)
- func (s *Store) TouchBridge(ctx context.Context, roomID, runID string) (bool, error)
- func (s *Store) Unfinished(ctx context.Context, clientPrefix string, first, last int64) ([]envelope.Event, error)
- func (s *Store) UnlinkSlack(ctx context.Context, team, user, sub string) (gone bool, err error)
- func (s *Store) UnpostedVerdicts(ctx context.Context, since time.Time, limit int, exclude []string) ([]envelope.Event, error)
- func (s *Store) WebhookCursor(ctx context.Context, sub, room string) (int64, error)
Constants ¶
const ( ApprovalPending = "pending" ApprovalApproved = "approved" ApprovalDenied = "denied" ApprovalExpired = "expired" ApprovalSuperseded = "superseded" )
An approval's states: pending, then closed once (SP2 §6).
const ( // MaxSlackCodes bounds the live codes in all: each Slack user holds one at most. MaxSlackCodes = 1000 // MaxSlackLinks bounds the Slack users one ZITADEL account holds. MaxSlackLinks = 5 )
The Slack self-serve link's bounds (docs/superpowers/specs/2026-10-28-slack-self-serve-link-design.md).
const ListenApplication = "room-broker-listen"
ListenApplication is the listener connection's application_name, so an operator can find it in pg_stat_activity.
const MinRetention = 24 * time.Hour
MinRetention is the schema's floor on a room's retention (rooms.retention >= 1 day), like the Room CRD's <n>d.
const VerdictsClient = "broker:verdicts"
VerdictsClient is the origin of the leader's verdict_posted and verdict_not_posted records. Their origin_seq is the verdict's seq, so the idempotency key is the record, and a new leader writes nothing twice.
Variables ¶
var ( // ErrAlreadyDecided is a decision on an approval that is no longer pending: // the first valid decision won, or its call already has a result, or its run ended. ErrAlreadyDecided = errors.New("already_decided") // ErrApprovalExpired is a human decision on an approval past its deadline: // the deadline decides, so a late decision never wins over the expiry sweep. ErrApprovalExpired = errors.New("approval_expired") // ErrNoApproval is an approval id the room log does not hold. ErrNoApproval = errors.New("no such approval") // ErrBadDecision is a human decision other than approved or denied. ErrBadDecision = errors.New("a decision is approved or denied") // ErrTooLarge is an approval whose request event would exceed the payload cap: // stored as an oversize stub, it would not be the request the row records. ErrTooLarge = errors.New("the approval request exceeds the payload cap") )
var ( // ErrStaleEpoch is a driver change whose expected epoch the room has moved past. ErrStaleEpoch = errors.New("stale_epoch") // ErrInvalidDriver is a change to no principal, or to the current holder. ErrInvalidDriver = errors.New("the next driver is a principal other than the holder") // ErrNotLapsed is a lease expiry of a holder who is not a lapsed human, or to // another principal than the room's fallback. ErrNotLapsed = errors.New("the holder is no lapsed human") )
var ( // ErrNotQueued is a state move from a state the queued message is no longer in. ErrNotQueued = errors.New("not_queued") // ErrNotAQueuedMessage is an Enqueue whose draft is not the queued message it // records: not a message, not delivery queued, another text or another author. ErrNotAQueuedMessage = errors.New("the draft is not this queued message by its actor") // ErrBadMove is a queue move the state machine has no edge for. ErrBadMove = errors.New("a queued message moves once, out of queued; promoted and consumed name their run") // ErrNotAuthor is a removal by neither the message's author nor the driver (§2). ErrNotAuthor = errors.New("only the author or the driver removes a queued message") )
var ( ErrCodeInvalid = errors.New("the link code is unknown, expired or used") ErrTooManyCodes = errors.New("too many link codes are waiting") ErrTooManyLinks = errors.New("the account holds the most Slack users it may") // ErrAlreadyLinked is a Slack user linked to another account: a link is never moved silently, // it is unlinked first. ErrAlreadyLinked = errors.New("the Slack user is linked to another account") )
The link's refusals, each a reason the page names.
var ( ErrNoRoom = errors.New("no such room") ErrSealed = errors.New("room is sealed") ErrLeaseLost = errors.New("the bridge lease is held by another run") ErrInvalidRetention = errors.New("retention must be at least a day") // ErrNoBridgeRun is AppendAsBridge without a run: it would append unfenced. ErrNoBridgeRun = errors.New("a bridge append names its run") // ErrKeyConflict is an idempotency key already stored for another kind of event: // a replay of it would report a change that never happened. ErrKeyConflict = errors.New("idempotency key already used by another event type") )
The store's sentinel errors; callers compare with errors.Is.
var ErrBadSeq = errors.New("bad_seq")
ErrBadSeq is a fork point outside the source room's log.
var ErrForkTooLarge = errors.New("fork prefix over the caps")
ErrForkTooLarge is a prefix over MaxForkEvents or MaxForkBytes.
Functions ¶
func IsDataError ¶
IsDataError reports a value PostgreSQL refuses outright (SQLSTATE class 22, such as 22P05 for a NUL in jsonb). Retrying cannot help, so the caller stores a stub instead.
Types ¶
type Approval ¶
type Approval struct {
ID, RoomID, RunID, EventID, CallID, Class, State string
Action json.RawMessage
Prompters []string
RequestedSeq int64
RequestedAt, ExpiresAt time.Time
}
Approval is one row of the approvals projection.
type NewRoom ¶
type NewRoom struct {
ID string
Driver string // spec.driver: the initial holder, and the system fallback
Retention time.Duration
}
NewRoom is what EnsureRoom needs from a Room CR.
type RoomState ¶
type RoomState struct {
ID string
LastSeq int64
Driver string
DriverEpoch int64
// FallbackDriver is the system holder a lapsed human driver falls back to, or "".
FallbackDriver string
Sealed bool
ClosedAt *time.Time
LastEventAt time.Time
}
RoomState is a room's row as the broker reads it.
type SlackCode ¶
SlackCode is what a code binds: the Slack user it was minted for, as the App saw them (their handle and display name, display only), and when it expires.
type Store ¶
type Store struct {
MaxEvents int64
MaxBytes int64
// MaxForkEvents and MaxForkBytes cap a fork's prefix. The copy is one
// transaction inside an act's 15 s, and its time grows faster than its
// length: 5,000 events took 2.5 s on a local Postgres, 20,000 took 28.6 s.
MaxForkEvents int64
MaxForkBytes int64
// Now stamps event timestamps. Lease freshness and close dates use the
// database's now() instead: one clock for every broker replica.
Now func() time.Time
// ListenPing is how long Listen waits for a notification before it pings,
// so a half-open connection after a failover is noticed (default 30 s).
ListenPing time.Duration
// contains filtered or unexported fields
}
Store is the room log over a PostgreSQL pool, connected as rooms_broker.
func Open ¶
Open connects with every session bounded, so no statement, lock queue or abandoned transaction holds a room's row lock for long, and the pool capped at 8 connections. A value set in the URL wins.
func (*Store) Append ¶
Append adds d to its room's log, for writers that hold no bridge lease (humans, the broker, system callers). dup is true for a replayed idempotency key; a key stored for another event type is ErrKeyConflict.
func (*Store) AppendAsBridge ¶
func (s *Store) AppendAsBridge(ctx context.Context, bridgeRun string, d envelope.Draft) (envelope.Event, bool, error)
AppendAsBridge appends for the bridge of bridgeRun, and refuses with ErrLeaseLost once another run holds the room's bridge lease (ruling P17, review I7).
func (*Store) AppendAsDriver ¶
func (s *Store) AppendAsDriver(ctx context.Context, driver string, epoch int64, d envelope.Draft) (envelope.Event, bool, error)
AppendAsDriver appends a driver-only action for driver, and refuses with ErrStaleEpoch unless driver still holds the token at epoch (§2): the check runs under the room's row lock, so it holds across broker replicas.
func (*Store) BriefSources ¶
BriefSources returns what the next run's brief may quote from the log: the room's latest agent handoff and latest agent review_verdict, in seq order (review 4.4 M3 and I3). Only agents wrote them; no window of the log is read.
func (*Store) BriefSourcesThrough ¶
func (s *Store) BriefSourcesThrough(ctx context.Context, roomID string, seq int64) ([]envelope.Event, error)
BriefSourcesThrough is BriefSources as the log stood at seq: what a fork at seq bases its run on (§5).
func (*Store) ChangeDriver ¶
func (s *Store) ChangeDriver(ctx context.Context, roomID string, expect int64, to, reason string, d envelope.Draft) (envelope.Event, bool, error)
ChangeDriver moves the token only if the room's epoch is still expect, the fence that makes a give, a take and a lease expiry safe across replicas (§2). d carries the actor, origin and idempotency key; the store fills the type and the DriverPayload. A replayed key returns the stored event, dup true, and moves nothing.
func (*Store) ClaimBridge ¶
func (s *Store) ClaimBridge(ctx context.Context, roomID, runID string, live func(ctx context.Context, runID string) bool) (string, bool, error)
ClaimBridge takes the room's bridge lease for runID (ruling P17). It lives in the room's row, so every broker replica agrees (review I7). Another run keeps it for as long as live(holder) is true, however long since its bridge was seen: a quiet or cut-off bridge may still have a harness at work, and two runs must never execute in one room (ruling SBB, F15). A run that ended frees it at once. live may call the Kubernetes API, so it runs outside any transaction, and the takeover that follows is a compare-and-swap on the holder it asked about.
func (*Store) CloseRoom ¶
CloseRoom seals the log with a final state_changed{room_phase: Closed}. Its retention clock starts now (OD-17). Closing twice is a no-op.
func (*Store) Cursor ¶
Cursor is the highest origin_seq stored for originClient in the room, 0 if none: where a reconnecting writer resumes.
func (*Store) Decide ¶
func (s *Store) Decide(ctx context.Context, approvalID, decision, by, reason string, d envelope.Draft) (envelope.Event, Approval, error)
Decide records a human's decision, approved or denied, and appends approval_decided in one transaction. UPDATE … WHERE state = 'pending' under the room's row lock is the whole race (§2): the first valid decision wins, and every later one, a supersede included, is ErrAlreadyDecided. A decision on a call that already has a result closes the approval as superseded and is ErrAlreadyDecided too. One past the deadline, read in the same transaction, closes it as expired and is ErrApprovalExpired, as is any decision on an expired approval. Like the driver's acts, d's key is checked first: a replayed decision returns its stored event, and a key stored for anything else is ErrKeyConflict.
func (*Store) Deliveries ¶
func (s *Store) Deliveries(ctx context.Context, roomID, runID string, after, through int64, limit int) ([]envelope.Event, error)
Deliveries returns up to limit of the run's deliveries in (after, through], in seq order, through events_deliveries: a stream's replay reads only what it may send, never the room's whole log (review I3).
func (*Store) DriverSeen ¶
DriverSeen is the holder's heartbeat (every ping) and, with acted, its last action. Anyone but the holder is a no-op.
func (*Store) Enqueue ¶
func (s *Store) Enqueue(ctx context.Context, d envelope.Draft, author, text string) (envelope.Event, error)
Enqueue appends a queued message and its FIFO row in one transaction (§2). author is always d's actor, and text its payload's: anything else is ErrNotAQueuedMessage. A replayed key returns the stored event and adds no row; a key stored for anything but a queued message is ErrKeyConflict.
func (*Store) EnsureRoom ¶
EnsureRoom inserts the room's row once. created is false when it already existed. fallback_driver is the system holder a lapsed human driver falls back to (§2); a room that starts with a human driver has none until a system principal holds it. A retention under MinRetention is refused with ErrInvalidRetention before the database, whose check (Ruling AE) would refuse it as a bare 23514.
func (*Store) ExpireDriver ¶
func (s *Store) ExpireDriver(ctx context.Context, roomID string, expect int64, to string, d envelope.Draft) (envelope.Event, bool, error)
ExpireDriver is the lease sweeper's ChangeDriver to the room's fallback, with the reason lease_expired. It moves the token only if a human still holds it at expect and is still lapsed under the row lock (ErrNotLapsed otherwise): one who came back between the sweep's read and this write keeps it.
func (*Store) ExpireDue ¶
ExpireDue closes every pending approval past its deadline as expired (§6 Timeouts), in open rooms: a sealed room takes no event. It returns the events it appended; one a human decided meanwhile is skipped.
func (*Store) ExpiredVerdicts ¶
func (s *Store) ExpiredVerdicts(ctx context.Context, before time.Time, limit int) ([]envelope.Event, error)
ExpiredVerdicts are the verdicts UnpostedVerdicts no longer returns: stamped at or before before, oldest first, with no outcome yet (review 3.5 m2b).
func (*Store) Fork ¶
func (s *Store) Fork(ctx context.Context, src string, upTo int64, r NewRoom, d envelope.Draft, fields map[string]any) (envelope.Event, error)
Fork creates room r from events 1..upTo of src, copied with their seq, id and idempotency key (§5), then appends d as state_changed{forked_from}: fields, plus the source room and seq. The copy is the fork's own, so it outlives src's purge, and a copied key deduplicates the Room controller's seq-1 Open. It runs as the broker's role, under the grants and triggers every append meets: the row starts empty, and nothing in src changes, a sealed src included. A prefix over MaxForkEvents or MaxForkBytes is refused with ErrForkTooLarge.
The fork also carries the source's queue as it stood at upTo: the messages queued by then and not yet taken out of the queue, each queued again in the fork. One gap: a row consumed through POST /v1/rooms/{id}/queue/consume (Store.SetQueued) leaves no event to date it, so it is carried only while it is still queued; consumed that way after upTo and before the fork, it is not.
func (*Store) Lagging ¶
Lagging lists up to limit rooms whose last_seq is past the subscriber's cursor, newest activity first. The emitter asks on each reconnect of Listen, since notifications sent while the listener was down are gone.
func (*Store) LapsedDrivers ¶
LapsedDrivers lists human holders disconnected over 2 min or idle over 15 min, in open rooms that have a system holder to fall back to.
func (*Store) LastAck ¶
LastAck is where a bridge's deliveries resume: the highest ref the run's bridge acknowledged as delivered, interrupted, undeliverable or decision_applied, 0 if none. A ref that is not a seq, or not a delivery of this run, is skipped.
func (*Store) LastEventAt ¶
LastEventAt is when each room's log last moved, for the rooms in ids that exist. One query: the room list reads it for every row it shows.
func (*Store) LastHarnessEnd ¶
LastHarnessEnd is the run's last loop end reason the bridge recorded (harness_end), "" for none.
func (*Store) LastHarnessStatus ¶
LastHarnessStatus is the run's last execution_status the bridge mirrored (ruling P15).
func (*Store) LastTaskState ¶
func (s *Store) LastTaskState(ctx context.Context, roomID string, after int64) (json.RawMessage, error)
LastTaskState is the payload of the room's highest-seq state_changed{kind:task} above seq after, or nil when the factory wrote none there. The seq decides, so a late or replayed write cannot win. A fork passes its fork point: the facts at or below it are its source's.
func (*Store) LinkSlack ¶
func (s *Store) LinkSlack(ctx context.Context, codeSHA256 []byte, team, sub string, now time.Time) (SlackCode, error)
LinkSlack uses a live code of team once and links its Slack user to sub. A Slack user linked to another account is ErrAlreadyLinked, and an account past MaxSlackLinks ErrTooManyLinks; either leaves the code unused. A link to the same account is refreshed.
func (*Store) Listen ¶
Listen holds one LISTEN session on a dedicated connection, outside the pool, so neither starves the other. It calls ready once LISTEN is in place, then fn for every notification, from its own goroutine: fn must not block, or PostgreSQL's notification queue backs up and every append fails. It returns nil when ctx ends and an error when the connection is lost; the caller reconnects and catches up, since notifications sent meanwhile are gone.
func (*Store) MintSlackCode ¶
func (s *Store) MintSlackCode(ctx context.Context, codeSHA256 []byte, c SlackCode, now time.Time) error
MintSlackCode stores a code by its hash for c's Slack user, replacing that user's earlier code, after purging every expired or used one. It refuses once MaxSlackCodes are live.
func (*Store) OldestPending ¶
OldestPending is the age of the oldest pending approval in an open room, and how many there are, on the database's clock.
func (*Store) OpenApprovals ¶
OpenApprovals lists the room's pending approvals, oldest first, for the state frame: a page's tail of 500 events may not reach back to a request.
func (*Store) PendingApprovals ¶
PendingApprovals counts the room's undecided approvals; a sealed room has none anyone can decide.
func (*Store) PendingRuns ¶
func (s *Store) PendingRuns(ctx context.Context, roomID string, within time.Duration) ([]string, error)
PendingRuns lists the runs requested in the room within the last within whose run has not joined yet (review 4.4 I2): a rendered claim not applied, or a factory run the watch has not seen.
func (*Store) PromoteQueued ¶
func (s *Store) PromoteQueued(ctx context.Context, roomID string, ref int64, driver string, epoch int64, runID string, d envelope.Draft) (envelope.Event, error)
PromoteQueued turns a queued message into steering for runID, in one transaction fenced on the driver token (§2): the row moves to promoted and the steering message, caused by it, is appended together, or neither is. d carries the actor, origin and key; the store fills the type, the cause and the payload.
func (*Store) Prompters ¶
Prompters are the humans who prompted a run, whom OD-16's four-eyes rule keeps from deciding its approvals: whoever requested it, steered it, or wrote a queued message its brief consumed or that was promoted to it.
func (*Store) PurgeExpired ¶
PurgeExpired deletes every expired room's log, then its row, one room per transaction, so each stays bounded by the room limits (100 000 events). Each transaction runs under its own purgeStatementTimeout (SET LOCAL), not the session's statement_timeout. It runs as rooms_retention; the broker's role holds no DELETE and fails. Every table referencing rooms (queue, approvals, and webhook_cursors when the migration ran) is deleted before the room's row.
func (*Store) Range ¶
func (s *Store) Range(ctx context.Context, roomID string, afterSeq int64, limit int) ([]envelope.Event, error)
Range returns up to limit events of the room after afterSeq, in seq order.
func (*Store) RecordRunRequest ¶
func (s *Store) RecordRunRequest(ctx context.Context, d envelope.Draft, runID string, refs []int64, fields map[string]any) (envelope.Event, error)
RecordRunRequest records the request of runID in d's room as state_changed{run_requested}, and moves the queued messages its brief quoted (refs) to consumed by runID, in one transaction: a brief's messages are consumed exactly when its run is on the record. The store fills d's type and payload: fields, plus runId and consumed, the refs it moved (one removed meanwhile stays removed). A replayed key returns the stored record and moves nothing; a key stored for anything else is ErrKeyConflict.
func (*Store) RemoveQueued ¶
func (s *Store) RemoveQueued(ctx context.Context, roomID string, ref int64, d envelope.Draft) (envelope.Event, error)
RemoveQueued withdraws a queued message for d's actor, its author or the driver (ErrNotAuthor otherwise), and records state_changed{queued_removed} in the same transaction. The store fills d's type and payload.
func (*Store) RequestApproval ¶
func (s *Store) RequestApproval(ctx context.Context, a Approval, d envelope.Draft) (Approval, envelope.Event, error)
RequestApproval records a pending approval and appends approval_requested in one transaction, fenced on the run's bridge lease like its other appends (Ruling Y). It is idempotent per (room, run, eventId): a bridge that re-sends the request, after a restart too, gets the stored approval back and no event.
func (*Store) SchemaReady ¶
SchemaReady backs /startupz: the Atlas migration has run.
func (*Store) SetQueued ¶
SetQueued moves a queued message out of queued: ErrNotQueued when it is no longer queued, ErrSealed once its room is sealed. A row moves once; promoted and consumed name the run (the steered one, or the one whose brief took it), removed names none: any other move is ErrBadMove.
func (*Store) SetWebhookCursor ¶
SetWebhookCursor moves the subscriber's cursor in room to seq; it never moves back.
func (*Store) SlackCode ¶
SlackCode reads a live code without using it: ErrCodeInvalid when it is unknown, expired or used.
func (*Store) SlackLink ¶
func (s *Store) SlackLink(ctx context.Context, team, user string) (sub string, found bool, err error)
SlackLink is the ZITADEL sub a Slack user is linked to; found is false when none is.
func (*Store) SlackLinksOf ¶
SlackLinksOf lists the account's Slack users, oldest link first.
func (*Store) Stored ¶
Stored returns the event already stored under d's idempotency key, if any. An act whose side effect lies outside the log, such as a run request, checks it first, so a replayed key never repeats that effect.
func (*Store) Subscriber ¶
func (s *Store) Subscriber(ctx context.Context, sub string, generation int) (failures int, disabled bool, err error)
Subscriber registers a webhook subscriber and returns where it stands (R17, R18), in one transaction. On the name's first insert only, every existing room gets a cursor at its last_seq, so no history is replayed; a re-added name keeps its row and its cursors. A new generation re-enables the subscriber.
func (*Store) SupersedeAnswered ¶
SupersedeAnswered closes as superseded every pending approval whose call has a tool_result (5.2 contract 5: the harness ran or rejected it), then every one whose run has ended: neither is left for approvers, nor counted as pending, nor holds its room AwaitingHuman.
func (*Store) TaskReasons ¶ added in v0.30.1
TaskReasons is the reason code of each room's last task facts above its bound in after (a fork's fork point, as in LastTaskState), for the rooms that have facts there. One query: the room list reads it for every failed row it shows.
func (*Store) TaskStateAt ¶
func (s *Store) TaskStateAt(ctx context.Context, roomID string, after, upTo int64) (json.RawMessage, error)
TaskStateAt is the payload of the room's highest-seq state_changed{kind:task} with after < seq <= upTo, or nil when there is none: the task facts as they stood at upTo. after is a fork's fork point, as in LastTaskState.
func (*Store) TouchBridge ¶
TouchBridge reports whether runID still holds the room's lease. held is false when another run took it: that bridge is displaced, and its appends fail with ErrLeaseLost.
func (*Store) Unfinished ¶
func (s *Store) Unfinished(ctx context.Context, clientPrefix string, first, last int64) ([]envelope.Event, error)
Unfinished returns the opening event of every idempotency scope the broker writes, named clientPrefix+<anything>, that stored its seq first but not its seq last, in the rooms still open. The prefix is literal. The caller owns what the scope and its seqs mean (runwatch: a run that joined and never left).
func (*Store) UnlinkSlack ¶
UnlinkSlack removes a Slack user's link: only when it is sub's, or whoever's it is when sub is "" (the Slack user's own request, through the App). gone is false when there was nothing to remove.
func (*Store) UnpostedVerdicts ¶
func (s *Store) UnpostedVerdicts(ctx context.Context, since time.Time, limit int, exclude []string) ([]envelope.Event, error)
UnpostedVerdicts are agents' review verdicts after since, oldest first, with no outcome yet (SP2 design §3), leaving out the event ids in exclude: the verdicts the poster holds in backoff, so they never starve the next ones.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package migrations is the schema, embedded for room-broker migrate (adoption 3b).
|
Package migrations is the schema, embedded for room-broker migrate (adoption 3b). |