Documentation
¶
Overview ¶
Package workerstate persists worker-side UI state that must survive a disconnect or process restart. It deliberately has no dependency on the TUI so recovery policy can be tested independently from rendering.
Index ¶
- Variables
- func RebindIdentity(ctx context.Context, path, oldGatewayID, newGatewayID, workerID string) error
- type CorruptRecord
- type CorruptRecordsError
- type Identity
- type Record
- type Scope
- type Store
- func (store *Store) Bind(ctx context.Context, gatewayID, workerID string) error
- func (store *Store) Close() error
- func (store *Store) Delete(ctx context.Context, scope Scope, kind string) error
- func (store *Store) Identities(ctx context.Context) ([]Identity, error)
- func (store *Store) List(ctx context.Context) ([]Record, error)
- func (store *Store) Put(ctx context.Context, scope Scope, kind string, payload json.RawMessage) (Record, error)
Constants ¶
This section is empty.
Variables ¶
var ( // been bound yet. State must remain invisible until gateway Hello. ErrIdentityUnavailable = errors.New("worker state identity is not established") // ErrIdentityConflict prevents one Store instance from switching subjects // after it has exposed or mutated a namespace. ErrIdentityConflict = errors.New("worker state is bound to a different authenticated identity") )
Functions ¶
func RebindIdentity ¶
RebindIdentity validates and rewrites an offline staged state database for a restored gateway path. Every correctness row must belong to the declared old identity; a mixed archive is rejected rather than partially rewritten.
Types ¶
type CorruptRecord ¶
CorruptRecord describes one row which List could not safely decode. Other healthy rows are still returned.
type CorruptRecordsError ¶
type CorruptRecordsError struct {
Records []CorruptRecord
}
CorruptRecordsError reports isolated row corruption. Callers may use the records returned alongside this error; none of the corrupt rows are included in that result.
func (*CorruptRecordsError) Error ¶
func (err *CorruptRecordsError) Error() string
func (*CorruptRecordsError) Unwrap ¶
func (err *CorruptRecordsError) Unwrap() error
type Identity ¶
Identity is one authenticated gateway/worker namespace present in a state database. Tokens are deliberately excluded.
type Record ¶
type Record struct {
Scope Scope `json:"scope"`
Kind string `json:"kind"`
Payload json.RawMessage `json:"payload"`
UpdatedAt time.Time `json:"updated_at"`
// CreatedRevision is assigned once when the scope/kind row is inserted;
// Revision changes on every Put. Both are database-local monotonic values and
// are the only safe causal ordering source when wall clocks jump or tie.
CreatedRevision int64 `json:"created_revision"`
Revision int64 `json:"revision"`
}
Record is one durable value. UpdatedAt is assigned by Store.Put and is always returned in UTC.
type Scope ¶
type Scope struct {
CallerID string `json:"caller_id"`
WorkspaceKey string `json:"workspace_key,omitempty"`
TaskID string `json:"task_id,omitempty"`
SessionKey string `json:"session_key"`
Tier completion.CapabilityTier `json:"tier"`
}
Scope is the correctness namespace for one piece of worker state. SessionKey is opaque: completion.Assignment.SessionKey contains a NUL separator and must not be treated as a path or a printable stable key.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a single-process SQLite state store. SQLite access is serialized so concurrent Put/Delete/List calls share one transactional order.
func Open ¶
Open opens or creates a state database. A newly created parent directory is mode 0700 and the database is always mode 0600. Existing parent directories must already be private; Open never changes permissions on a caller-owned directory.
func (*Store) Bind ¶
Bind selects the only authenticated correctness namespace this Store instance may access. It is idempotent for credential rotation because tokens are deliberately absent; a different gateway or worker subject is rejected.
func (*Store) Delete ¶
Delete removes one exact scope/kind value. Deleting an absent value is successful, making cleanup idempotent across recovery attempts.
func (*Store) Identities ¶
Identities inspects namespace metadata without exposing any draft payload. It is intended for offline backup verification; ordinary TUI reads still require Bind and List.
func (*Store) List ¶
List returns every healthy record in deterministic update/key order. Bad rows are isolated in CorruptRecordsError rather than hiding healthy state.
func (*Store) Put ¶
func (store *Store) Put( ctx context.Context, scope Scope, kind string, payload json.RawMessage, ) (Record, error)
Put transactionally inserts or replaces a value in one scope. Payload is copied before Put returns, so later caller mutation cannot change the value represented by the returned Record.