proactive: survive transient engine walls instead of losing the run

A run at 00:37 died at 00:40: DuckDuckGo served its 'anomaly' page, Bing reset
its connection, Google Jobs was throttled. All three were disabled for the
remaining ~150 queries, and Google Jobs still cost ~20s per query (12s selector
wait + retries) while returning nothing — discovery alone would have taken
~50 minutes to produce nothing.

- An anti-bot wall now cools down 120s and retries once. The wall is temporary:
  the same queries answered normally a few minutes later.
- Discovery stops as soon as every enabled engine is blocked, instead of
  iterating the remaining queries with no engine and paying the per-query
  politeness delay.
- DuckDuckGo's delay is 3-6s (was 2-5s) and Bing's 2.5-5s, so the cadence is
  less likely to trip the wall in the first place.
- The between-query jitter is a fixed 0.8-2.2s rather than reusing DuckDuckGo's
  delay, which would have doubled the pause after every query.
main
I Luk Kim 2 weeks ago
parent e76deae20d
commit 73d88fdc34

@ -54,6 +54,11 @@ _ATS_HOST_MARKERS = (
"jobvite.com",
)
#: How long to pause after an anti-bot wall before retrying that engine once.
#: DuckDuckGo's "anomaly" page clears within minutes; disabling the only useful
#: web engine for the remaining 150 queries costs far more than this pause.
_BLOCK_COOLDOWN_SECONDS = 120
#: How many times an engine may fail before it is skipped for the rest of the
#: run. A single query costs ~4s in politeness delay, so a dead engine with 400
#: queries would otherwise burn half an hour of the run doing nothing.
@ -714,8 +719,23 @@ class ProactiveEngine:
seen_urls: set[str] = set()
blocked_engines: set[str] = set()
engine_failures: dict[str, int] = {}
for query in queries:
engine_blocks: dict[str, int] = {}
for q_index, query in enumerate(queries):
# All engines blocked: the remaining queries cannot discover
# anything, and the per-query politeness delay would burn minutes
# doing nothing. Stop discovery and let verification use the
# candidates already found.
if blocked_engines >= set(plan.enabled_engines()):
result.warnings.append(
f"discovery stopped early: every engine is blocked "
f"({len(queries) - q_index} query/queries skipped)"
)
logger.warning(
"[proactive] All engines blocked — stopping discovery early "
"and verifying what was already found"
)
break
for engine_name in self._engines_for_query(query, plan):
if engine_name in blocked_engines:
continue # circuit breaker: skip engines blocked this run
@ -768,7 +788,42 @@ class ProactiveEngine:
seen_urls.add(canon)
discovered.append(r)
except EngineBlockedError as e:
# Engine anti-bot wall — not a real error; skip engine for rest of run
# An anti-bot wall is usually temporary: DuckDuckGo served
# its "anomaly" page at 00:40 and answered normally again a
# few minutes later. Disabling the engine for the remaining
# ~150 queries on the first hit loses most of the run, so
# cool down once and retry before giving up on it.
block_count = engine_blocks.get(engine_name, 0) + 1
engine_blocks[engine_name] = block_count
if block_count == 1 and engine_name != "googlejobs":
cooldown = _BLOCK_COOLDOWN_SECONDS
logger.info(
f"[proactive] {engine_name} blocked ({e}) — cooling "
f"down {cooldown}s and retrying once"
)
result.warnings.append(
f"{engine_name} blocked, cooled down {cooldown}s"
)
time.sleep(cooldown)
try:
results = engine.search(
page, query, cfg.max_results_per_query
)
except Exception:
results = []
if results:
result.queries_run += 1
result.engine_queries[engine_name] = (
result.engine_queries.get(engine_name, 0) + 1
)
for r in results:
r.url = resolve_url("https://www.google.com", r.url)
canon = canonical_lead_url(r.url)
if not canon or canon in seen_urls:
continue
seen_urls.add(canon)
discovered.append(r)
continue
blocked_engines.add(engine_name)
result.engine_blocks += 1
logger.info(
@ -795,7 +850,11 @@ class ProactiveEngine:
"rest of this run (other engines continue)"
)
self._politeness_delay(cfg.delay_min_ms, cfg.delay_max_ms)
self._politeness_delay(plan.engine_config("duckduckgo").delay_min_ms, 3000)
# Per-engine delays already pace the individual requests; this is
# only a small jitter between queries so the overall cadence is not
# machine-perfect. Using DuckDuckGo's delay here too would double
# the pause after every query.
self._politeness_delay(800, 2200)
# Direct ATS boards — hidden jobs not indexed by search engines
if plan.boards.enabled:

@ -13,12 +13,16 @@ engines:
duckduckgo:
enabled: true
max_results_per_query: 30
delay_min_ms: 2000
delay_max_ms: 5000
# DuckDuckGo's HTML endpoint serves an "anomaly" wall when hammered
# (measured 2026-11-23: after 29 queries at 2-5s spacing). A slower
# cadence costs wall-clock, not coverage. A wall also triggers a 120s
# cooldown + one retry in the engine loop before the engine is dropped.
delay_min_ms: 3000
delay_max_ms: 6000
bing:
enabled: true
max_results_per_query: 30
delay_min_ms: 2000
delay_min_ms: 2500
delay_max_ms: 5000
googlejobs:
enabled: true

Loading…
Cancel
Save