Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: a working paid solver is warned as having no API key whenever it does not handle the current page (PIN-089)

Luigi Agosti94c8073b65d3
diff --git a/internal/autosolver/autosolver.go b/internal/autosolver/autosolver.go
index 4bacc118..478bbceb 100644
--- a/internal/autosolver/autosolver.go
+++ b/internal/autosolver/autosolver.go
@@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"sort"
+ "sync"
"time"
"github.com/pinchtab/pinchtab/internal/htmltrim"
@@ -18,6 +19,8 @@ type AutoSolver struct {
semantic SemanticEngine
llm LLMProvider
config Config
+
+ warnedMissingKey sync.Map
}
// New creates an AutoSolver with the given configuration.
@@ -216,9 +219,10 @@ func (as *AutoSolver) orderSolvers(matching []Solver) []Solver {
}
// reportMissingSolvers splits the configured-but-unavailable names by whether the
-// operator can act on them. A key-gated solver named without its API key is a
-// misconfiguration the config deliberately accepts, so it warns and names the key
-// to set; anything else is not a config error and stays at debug.
+// operator can act on them. Only an unset API key is actionable, and the names
+// here are absent from THIS page's matching set, which a working solver is too
+// whenever it does not handle this challenge — so the registry decides, never the
+// caller's slice.
func (as *AutoSolver) reportMissingSolvers(missing []string, running []Solver) {
if len(missing) == 0 {
return
@@ -227,10 +231,13 @@ func (as *AutoSolver) reportMissingSolvers(missing []string, running []Solver) {
unactionable := make([]string, 0, len(missing))
for _, name := range missing {
gated, ok := keyGatedSolverNamed(name)
- if !ok {
+ if !ok || as.isRegistered(name) {
unactionable = append(unactionable, name)
continue
}
+ if _, warned := as.warnedMissingKey.LoadOrStore(name, struct{}{}); warned {
+ continue
+ }
slog.Warn(fmt.Sprintf("autosolver: %s is configured but its API key is not set, so it never runs", gated.Name),
"solver", gated.Name,
"config_key", gated.ConfigKey,
@@ -245,6 +252,14 @@ func (as *AutoSolver) reportMissingSolvers(missing []string, running []Solver) {
}
}
+func (as *AutoSolver) isRegistered(name string) bool {
+ if as.registry == nil {
+ return false
+ }
+ _, ok := as.registry.Get(name)
+ return ok
+}
+
func solverNamesOf(solvers []Solver) []string {
names := make([]string, 0, len(solvers))
for _, s := range solvers {
diff --git a/internal/autosolver/autosolver_test.go b/internal/autosolver/autosolver_test.go
index a94e1e4c..f7ff7e2f 100644
--- a/internal/autosolver/autosolver_test.go
+++ b/internal/autosolver/autosolver_test.go
@@ -1163,6 +1163,9 @@ func TestOrderSolversWarnsWhenAKeyGatedSolverHasNoAPIKey(t *testing.T) {
recorder := captureLogs(t)
as := New(Config{Solvers: []string{"cloudflare", gated.Name}}, nil, nil)
+ if _, registered := as.Registry().Get(gated.Name); registered {
+ t.Fatalf("%s is registered, so this test is not covering the unset-key case", gated.Name)
+ }
got := solverNamesOf(as.orderSolvers([]Solver{
&mockSolver{name: "cloudflare", priority: 10},
&mockSolver{name: "jschallenge", priority: 20},
@@ -1186,6 +1189,54 @@ func TestOrderSolversWarnsWhenAKeyGatedSolverHasNoAPIKey(t *testing.T) {
}
}
+// orderSolvers receives THIS page's matching set, which a registered, working
+// solver is absent from whenever it does not handle this challenge. Diagnosing
+// that as an unset API key names a config key the operator has already filled in.
+func TestOrderSolversDoesNotWarnWhenAKeyGatedSolverIsRegisteredButDoesNotHandleThePage(t *testing.T) {
+ for _, gated := range KeyGatedSolvers() {
+ t.Run(gated.Name, func(t *testing.T) {
+ recorder := captureLogs(t)
+
+ as := New(Config{Solvers: []string{"cloudflare", gated.Name}}, nil, nil)
+ as.Registry().MustRegister(&mockSolver{name: gated.Name, priority: 200})
+ if _, registered := as.Registry().Get(gated.Name); !registered {
+ t.Fatalf("precondition: %s must be registered, meaning its API key IS set", gated.Name)
+ }
+
+ as.orderSolvers([]Solver{&mockSolver{name: "cloudflare", priority: 10}})
+
+ for _, rec := range recorder.records {
+ if rec.Level >= slog.LevelWarn {
+ t.Errorf("keyed %s absent from this page's matching set logged at %s: %q", gated.Name, rec.Level, rec.Message)
+ }
+ }
+ })
+ }
+}
+
+// Solve loops up to MaxAttempts and calls orderSolvers each time, so an unset
+// key stated once per attempt would repeat one static config fact all run.
+func TestOrderSolversWarnsOncePerUnregisteredKeyGatedSolver(t *testing.T) {
+ recorder := captureLogs(t)
+
+ gated := KeyGatedSolvers()[0]
+ as := New(Config{Solvers: []string{"cloudflare", gated.Name}}, nil, nil)
+ matching := []Solver{&mockSolver{name: "cloudflare", priority: 10}}
+ for i := 0; i < 5; i++ {
+ as.orderSolvers(matching)
+ }
+
+ warnings := 0
+ for _, rec := range recorder.records {
+ if rec.Level >= slog.LevelWarn && strings.Contains(rec.Message, gated.Name) {
+ warnings++
+ }
+ }
+ if warnings != 1 {
+ t.Errorf("five orderSolvers calls produced %d warnings for %s, want 1", warnings, gated.Name)
+ }
+}
+
func captureLogs(t *testing.T) *levelRecorder {
t.Helper()
recorder := &levelRecorder{}