The indexer hears the runner's run-started and pipeline-ended on their own streams and writes candidates.run-<id>: one pull per member, its repository and directory from its registration, its manifest and fingerprint from a take-in of its commit read through the seat git, over its branch's revision view when its registration watches the branch, else the trunk's. The state runs keeps each run's members and ended modules, so a restart between two ends still drops the candidate. The try candidates, the checker's checks consumer, checker_tries and the three try tools go; IsTryGroup takes run-<id> beside try-<digits>. Builds: design 47 G §64, §190, §321, §66, A-160, A-174 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
114 lines
6.9 KiB
Go
114 lines
6.9 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-indexer/takein"
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
)
|
|
|
|
// PendingTools are the indexer's tools of what waits for a take-in (novox/hq ADR 0633 §5): indexer_pending reads the
|
|
// pending state, and indexer_take_in_pending and indexer_drop_pending steer it by an ask in takeins, as indexer_take_in
|
|
// does. pending is the pending state as the tools bundle reads it; ask writes an ask and waits for the indexer's answer.
|
|
func PendingTools(pending, ownBuild Store, ask func(key string, value []byte) (TakeInAsk, error), now func() time.Time) []stdio.Tool {
|
|
str := func(args map[string]any, k string) string { s, _ := args[k].(string); return s }
|
|
hand := func(drop bool) func(map[string]any) (any, error) {
|
|
return func(args map[string]any) (any, error) {
|
|
key, value, err := NewPendingAsk(str(args, "key"), str(args, "why"), stdio.CallerOf(args), drop, args["abandon"] == true, now())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
a, err := ask(key, value)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return a.Result, nil
|
|
}
|
|
}
|
|
merge := func(args map[string]any) (any, error) {
|
|
seq, _ := args["sequence"].(float64)
|
|
key, value, err := NewMergeAsk(str(args, "repository"), str(args, "merge"), uint64(seq), str(args, "why"), stdio.CallerOf(args), now())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
a, err := ask(key, value)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return a.Result, nil
|
|
}
|
|
return []stdio.Tool{
|
|
{Name: PendingTool,
|
|
Description: "What waits for a take-in (ADR 0633): merges the indexer holds in its pending state instead of taking them in. " +
|
|
"A revision (what revision, its key its oldest merge's m.<sequence>) waits for the build of the indexer it names " +
|
|
"(waits-for): the running indexer wrote only what building and moving that indexer needs, and the new indexer takes " +
|
|
"it in at its start. A group (what group, key g.<group>) is a delivery group whose members are gathered until the " +
|
|
"forge bridge says its end; a merge in one of its members' repositories waits behind it (behind). Each names its " +
|
|
"merges, since when it waits, the modules it holds back (holds), the merges whose message the forge bridge's stream no " +
|
|
"longer holds (lost: they are not taken in; indexer_drop_pending drops them) and the last take-in event said of it. Empty waits: " +
|
|
"every merge is taken in. The watchman raises take-in-waits past 60 minutes for a revision, 30 for a group; " +
|
|
"indexer_take_in_pending and indexer_drop_pending steer a wait. own-build says which build the indexer knows it runs and own-build-since since when; own-build-unknown, when set, says the indexer cannot learn the build it " +
|
|
"runs (since when): it fixes it once at its start, so every merge waits (a take-in.pending that says so) until the module is started again.",
|
|
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
|
Run: func(map[string]any) (any, error) {
|
|
var unread []string
|
|
entries, err := ReadPending(context.Background(), pending, func(format string, args ...any) {
|
|
unread = append(unread, fmt.Sprintf(format, args...))
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
answer := takein.PendingAnswer{Waits: PendingWaits(entries), Unread: unread}
|
|
// Whether this indexer knows the build it runs: when it does not, every merge waits, and this says since when and why.
|
|
if ownBuild != nil {
|
|
if v, _, found, err := ownBuild.Get(context.Background(), OwnBuildKey); err == nil && found {
|
|
var o OwnBuild
|
|
if json.Unmarshal(v, &o) == nil {
|
|
answer.OwnBuildSince = o.Since
|
|
if o.Known {
|
|
answer.OwnBuild = o.FP
|
|
} else {
|
|
answer.OwnBuildUnknown = o.Why
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return answer, nil
|
|
}},
|
|
{Name: TakeInPendingTool,
|
|
Description: "Take a wait in by hand with the running indexer and its judge (ADR 0633 §5): the revision under its m. key, " +
|
|
"whatever build of the indexer it names, or a delivery group under its g. key with the members gathered so far. For " +
|
|
"when the named indexer can never run, or a group's end never comes. A hand act: who and why are said in the " +
|
|
"indexer's journal and on the take-in.taken event, which clears take-in-waits. indexer_pending names the keys.",
|
|
Input: map[string]any{"type": "object", "required": []string{"key", "why"}, "properties": map[string]any{
|
|
"key": map[string]any{"type": "string", "description": "the wait's key, m.<sequence> or g.<group>, as indexer_pending names it"},
|
|
"why": map[string]any{"type": "string", "description": "why it is taken in by hand, in plain words"}}},
|
|
Run: hand(false)},
|
|
{Name: DropPendingTool,
|
|
Description: "Drop one pending merge by hand, abandoned because a later merge replaced it (ADR 0633 §5): it is removed from " +
|
|
"the pending state and nothing of it is taken in; what waited with it is worked out again. A merge no later pending merge " +
|
|
"and no taken merge of its repository covers is refused, naming indexer_take_in_pending, which reads its message again; " +
|
|
"abandon: true drops it all the same. A hand act: who and why are said in the journal and on the take-in.taken event (dropped).",
|
|
Input: map[string]any{"type": "object", "required": []string{"key", "why"}, "properties": map[string]any{
|
|
"key": map[string]any{"type": "string", "description": "the pending merge's key, m.<sequence>, as indexer_pending names its merges' wait"},
|
|
"why": map[string]any{"type": "string", "description": "why it is dropped, in plain words"},
|
|
"abandon": map[string]any{"type": "boolean", "description": "drop it though no later merge covers it; its changes are then never taken in"}}},
|
|
Run: hand(true)},
|
|
{Name: TakeInMergeTool,
|
|
Description: "Take one merge in by hand (ADR 0633 §5, issue 1585): the indexer asks the forge bridge for the merge's merged message " +
|
|
"(bridge_merged_message) and runs it through the take-in as a delivered merged message, so it is held for the " +
|
|
"indexer its revision names or taken in. For a merge the take-in did not take in (indexer_heard names its sequence " +
|
|
"and why). A hand act: who and why are said in the indexer's journal. The bridge's own words answer when it cannot " +
|
|
"build the message (the gate holds no such merge, the forge does not answer).",
|
|
Input: map[string]any{"type": "object", "required": []string{"repository", "merge", "sequence", "why"}, "properties": map[string]any{
|
|
"repository": map[string]any{"type": "string", "description": "the repository, owner/name"},
|
|
"merge": map[string]any{"type": "string", "description": "the merge commit, 40 hex digits"},
|
|
"sequence": map[string]any{"type": "integer", "description": "the merge's sequence on the forge bridge's stream, as indexer_heard names it"},
|
|
"why": map[string]any{"type": "string", "description": "why it is taken in by hand, in plain words"}}},
|
|
Run: merge},
|
|
}
|
|
}
|