feat(monitor): wire isolated target recovery

Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
ZeusinaandGPT-6 Bot committed 2026-10-10 09:45:34 +03:00
1 parent 2d4e4878ae
commit 5f3a6953ee
16 files changed
+1919 -73

No files matched your search

+64 -34
View File
@@ -8,32 +8,78 @@ import (
"fmt"
"io"
"os"
"strings"
)
// Only complete, well-formed non-passing measurements permit scan fallback.
var errCandidateNonpass = errors.New("saved scenario did not pass both TLS protocols")
func revalidateGooglevideo(ctx context.Context, db *sql.DB, host string, stderr io.Writer, check cacheCheck) (string, []byte, error) {
rows, err := db.Query(`SELECT id FROM strategy_candidates WHERE strategy_group = 'googlevideo' ORDER BY id DESC`)
if err != nil {
return "", nil, err
// Rechecks exact saved args using runCombinedBlockcheckForHost's cacheCheck
// contract. The caller supplies a fresh temporary artifact path; artifacts are
// retained, but no stored definition or evidence is updated. A fresh GGC host
// is allowed only as an exact endpoint, never as wildcard qualification.
func revalidateCandidate(ctx context.Context, c storedCandidate, group, host, path string, stderr io.Writer, check cacheCheck) ([]byte, error) {
if err := ctx.Err(); err != nil {
return nil, err
}
var ids []int64
for rows.Next() {
var id int64
if err := rows.Scan(&id); err != nil {
rows.Close()
return "", nil, err
if (group != "frontend" && group != "googlevideo") || c.Group != group || !c.Qualified || path == "" || check == nil {
return nil, fmt.Errorf("invalid candidate revalidation request")
}
definition := candidate{Group: c.Group, Domains: append([]string(nil), c.Endpoints...), Args: c.Args}
if err := definition.validate(); err != nil {
return nil, err
}
if !validDomain(host) || host != strings.ToLower(host) {
return nil, fmt.Errorf("invalid revalidation endpoint")
}
if group == "googlevideo" {
if !discoveryHostname(host) || !strings.HasSuffix(host, ".googlevideo.com") {
return nil, fmt.Errorf("invalid exact cache scope")
}
} else {
inScope := false
for _, endpoint := range c.Endpoints {
inScope = inScope || endpoint == host
}
if !inScope {
return nil, fmt.Errorf("frontend endpoint outside candidate scope")
}
ids = append(ids, id)
}
err = rows.Err()
closeErr := rows.Close() // Release the store's single connection before candidate reads.
if err == nil {
err = closeErr
fmt.Fprintln(stderr, "Rechecking saved candidate:", c.ID, "exact endpoint:", host, "Blockcheck artifacts:", path)
// A checker that writes nothing must not reuse an earlier measurement.
if err := os.Remove(path + ".combined.json"); err != nil && !errors.Is(err, os.ErrNotExist) {
return nil, err
}
var raw bytes.Buffer
err := check(ctx, "blockcheckw", path, c.Args, host, &raw, &raw)
if e := os.WriteFile(path+".stdout", raw.Bytes(), 0600); e != nil {
return nil, e
}
if err != nil {
return "", nil, err
// Only our report parser may issue the nonpass authorization.
if errors.Is(err, errCandidateNonpass) {
return nil, fmt.Errorf("candidate checker failed: %v", err)
}
return nil, err
}
if err := ctx.Err(); err != nil {
return nil, err
}
report, err := os.ReadFile(path + ".combined.json")
if err != nil {
return nil, err
}
_, err = selectBlockcheckEvidence(bytes.NewReader(report), c.Args, group, host, true)
if contextErr := ctx.Err(); contextErr != nil {
return nil, contextErr
}
return report, err
}
func revalidateGooglevideo(ctx context.Context, db *sql.DB, host string, stderr io.Writer, check cacheCheck) (string, []byte, error) {
ids, err := qualifiedCandidateIDs(db, "googlevideo")
if err != nil {
return "", nil, &managedRecoveryFatal{Err: err}
}
for _, id := range ids {
if err := ctx.Err(); err != nil {
@@ -41,7 +87,7 @@ func revalidateGooglevideo(ctx context.Context, db *sql.DB, host string, stderr
}
c, err := readStrategyCandidate(db, id)
if err != nil {
return "", nil, err
return "", nil, &managedRecoveryFatal{Err: err}
}
if !c.Qualified {
continue
@@ -54,23 +100,7 @@ func revalidateGooglevideo(ctx context.Context, db *sql.DB, host string, stderr
if err := artifact.Close(); err != nil {
return "", nil, err
}
fmt.Fprintln(stderr, "Rechecking saved candidate:", id, "exact endpoint:", host, "Blockcheck artifacts:", path)
var raw bytes.Buffer
err = check(ctx, "blockcheckw", path, c.Args, host, &raw, &raw)
if e := os.WriteFile(path+".stdout", raw.Bytes(), 0600); e != nil {
err = e
}
if err != nil {
return "", nil, err
}
if err := ctx.Err(); err != nil {
return "", nil, err
}
report, err := os.ReadFile(path + ".combined.json")
if err != nil {
return "", nil, err
}
_, err = selectBlockcheckEvidence(bytes.NewReader(report), c.Args, "googlevideo", host, true)
report, err := revalidateCandidate(ctx, c, "googlevideo", host, path, stderr, check)
if errors.Is(err, errCandidateNonpass) {
continue
}