Documentation
¶
Overview ¶
Package recovery is init's recover and check phases: one session per capability, read-only over the repo, or one per share, one after another, when its sources are more than one session holds, at most Concurrency capabilities at once. Each capability the walk found reads its area, its files and the PRs and changes placed with it, and every session is given the product's promise as init's record holds it. Each capability's text, split into its folder, goes through the map check and the path lint and back to the same session with the problems, up to MaxRetries times, before failing entries are dropped. Sessions read their sources whole, with no appetite and no circuit breaker: init is never bounded (design 10 Q6). It writes the store, never the repo.
Index ¶
Constants ¶
const ( // Concurrency is the most sessions running at once. Concurrency = 3 // MaxRetries is how many times a capability's text with problems goes back // to its session before the failing entries are dropped. MaxRetries = 2 )
Each number below is a first guess, to be tuned from real runs (measure-before-budget).
const ( StatusRecovered = "recovered" StatusNotYet = "not yet recovered" StatusFailed = "failed" )
The values of Outcome.Status, as the store keeps them.
Variables ¶
var ErrNoWalk = errors.New("nothing walked and placed yet; run physa init --areas, --walk and --place first")
ErrNoWalk is returned by Run when nothing is walked and placed.
Functions ¶
This section is empty.
Types ¶
type Outcome ¶
type Outcome struct {
Name string `json:"name"`
Status string `json:"status"`
File string `json:"file"`
Terms string `json:"terms"`
Counts recovering.Counts `json:"counts"`
Dropped []recovering.Dropped `json:"dropped"`
Problems []string `json:"problems"`
Attempts int `json:"attempts"`
SessionID string `json:"session_id"`
Model string `json:"model"`
Tokens adapter.Tokens `json:"tokens"`
Error string `json:"error,omitempty"`
}
Outcome is how one capability's recovery ended. File is the capability's single text, front matter included, which mapfolder.Split makes its folder of, and Terms its glossary terms, both empty unless Status is StatusRecovered; Counts says what they hold. Dropped lists the entries, terms and overview taken out, each with its reasons. Problems is what failed the capability: what the check found outside any entry, or why the answer could not be read. Error is any other reason it failed: the agent's error, or the check's. Attempts counts the session's turns, the first and each retry, and Tokens is what they used together. Shares is how many shares its sources were read in, one session each, when they were more than one session holds; 0 is one session. SessionID is the id assigned to the session, empty when none started. Without its File and Terms, it is the JSON form of initrecord.Recovered's Details.
type Report ¶
type Report struct {
From string `json:"from"`
Used adapter.Tokens `json:"used"`
Capabilities []Outcome `json:"capabilities"`
}
Report is how one run ended: its source (always "walk", kept so readers of --json keep the key), what its sessions used together, and one outcome per capability, in run order.
func Run ¶
Run is init's recover and check phases end to end, from the walk and the placements (a new gather, new areas or a new walk clears the later ones, so both are of the current gather). For each capability of s.Only, or of the walk, it runs one session, read-only in s.Root, with the recovering skill on its sources, whole, and the product's promise the stored areas state (productpromise.NoPromise when none is), checks the text it writes, sends problems back up to MaxRetries times, then drops what is still at fault; its row replaces the capability's earlier one.
No walk with its placements (ErrNoWalk, saying so when the record holds rows an earlier physa recovered from a proposal), and a name in s.Only the walk lacks, are errors that resolve no agent and store nothing. A capability that fails, or that a cancelled run never reaches or cuts short, is not an error: the Report says so. A cancelled run still stores every capability's row, the recovered ones kept, and then returns ctx's error.
type Session ¶
type Session struct {
// Agent resolves the agent to recover with, once, and only when nothing
// refuses the run first.
Agent func() (adapter.Adapter, error)
// Only names the capabilities to recover, in the order to run them; empty
// means all of the walk's, in recovery's seeded order.
Only []string
// Root is the repo's root, where sessions read and `from <path>` anchors
// resolve. Nothing is written under it.
Root string
// PRExists tells whether a PR exists, asked only for numbers the gather
// does not hold. Nil checks #N anchors for form only.
PRExists func(context.Context, int) (bool, error)
// OpenRepo opens Root's version control, as the part mapcheck reads, to
// resolve commit anchors. Nil leaves each unresolved, a problem.
OpenRepo func(context.Context, string) (mapcheck.Repo, error)
// Progress receives one line before the sessions start and one as each
// capability ends; nil drops them.
Progress io.Writer
// Now dates questions and stored rows; nil means time.Now.
Now func() time.Time
}
Session says how Run runs its sessions.
type Store ¶
type Store interface {
Gathered(ctx context.Context) (store.Gather, bool, error)
Areas(ctx context.Context) (initrecord.Areas, bool, error)
Walk(ctx context.Context) (initrecord.Walk, bool, error)
Place(ctx context.Context) (initrecord.Place, bool, error)
RecoverSeed(ctx context.Context) (uint64, bool, error)
PutRecoverSeed(context.Context, uint64, time.Time) error
PutRecovered(context.Context, []initrecord.Recovered) error
Recovered(ctx context.Context) ([]initrecord.Recovered, error)
}
Store is what Run needs of the store: the gather, the areas (for the product's promise), the walk and placements, the seed of recovery's order, and what was recovered.