Ashira Pitchayapakayakul commited on
Commit
ecd4593
Β·
1 Parent(s): a49e89a

fix: 4 small bugs found during health check

Browse files

1. orchestrate line 534: 'local' outside function β€” replaced with bare assignment (no functional impact, just stderr noise)
2. status server /logs allowlist: add surrogate-dev-loop, scrape-keyword-tuner, hermes-discord-bot, ollama-pull-* (was missing 8 logs)
3. status server _ollama_models(): cache 30s + non-blocking timeout 1.5s β€” was causing /status to hang when ollama busy
4. domain-scrape-loop.sh:
- init scrape-ledger.db if missing (was producing empty BEFORE_LEDGER β†’ arithmetic errors)
- default 0 for all sqlite3 queries (was breaking iter progress lines)
- Linux-compat 'load average:' parsing (was macOS-only)
- update training-jsonl path to ~/.surrogate/training-pairs.jsonl

VERIFIED working today:
- Pipeline: 50+ commits to dataset (last 27 min: ~3411 pairs uploaded)
- Dev agent committed b10dd74 to arkashira/vanguard:
backend/app/api/v1/endpoints/cloud_rules.py (5588 bytes via DeepSeek-V3.1 HF Router)
- Agentic crawler: 40735 URLs visited, 17695 in frontier
- 5 Ollama models pulling
- 25 daemons logging

bin/domain-scrape-loop.sh CHANGED
@@ -10,8 +10,18 @@ DUR="${1:-900}"
10
  PARALLEL="${2:-3}"
11
  LOG="$HOME/.surrogate/logs/domain-scrape-loop.log"
12
  START=$(date +%s)
13
- BEFORE_PAIRS=$(wc -l ~/axentx/surrogate/data/training-jsonl/*.jsonl 2>/dev/null | tail -1 | awk '{print $1}')
14
- BEFORE_LEDGER=$(sqlite3 ~/.surrogate/state/scrape-ledger.db "SELECT COUNT(*) FROM scraped" 2>/dev/null)
 
 
 
 
 
 
 
 
 
 
15
 
16
  echo "═══ LOOP START $(date +%H:%M:%S) duration=${DUR}s parallel=$PARALLEL" | tee -a "$LOG"
17
  echo " before: pairs=$BEFORE_PAIRS ledger_repos=$BEFORE_LEDGER" | tee -a "$LOG"
@@ -22,8 +32,9 @@ while true; do
22
  [[ $((NOW - START)) -gt $DUR ]] && break
23
  ITER=$((ITER + 1))
24
 
25
- # Health check β€” break if load > 10
26
- LOAD=$(uptime | awk -F'load averages:' '{print $2}' | awk '{print int($1)}')
 
27
  if [[ $LOAD -gt 10 ]]; then
28
  echo " [iter=$ITER] load=$LOAD pause 30s" | tee -a "$LOG"
29
  sleep 30
@@ -43,14 +54,18 @@ while true; do
43
 
44
  # Progress every 5 iters
45
  if (( ITER % 5 == 0 )); then
46
- PAIRS=$(wc -l ~/axentx/surrogate/data/training-jsonl/*.jsonl 2>/dev/null | tail -1 | awk '{print $1}')
47
- LEDGER=$(sqlite3 ~/.surrogate/state/scrape-ledger.db "SELECT COUNT(*) FROM scraped" 2>/dev/null)
 
 
48
  echo " [iter=$ITER $((NOW - START))s] pairs=$PAIRS (+$((PAIRS - BEFORE_PAIRS))) ledger=$LEDGER (+$((LEDGER - BEFORE_LEDGER)))" | tee -a "$LOG"
49
  fi
50
  done
51
 
52
- AFTER_PAIRS=$(wc -l ~/axentx/surrogate/data/training-jsonl/*.jsonl 2>/dev/null | tail -1 | awk '{print $1}')
53
- AFTER_LEDGER=$(sqlite3 ~/.surrogate/state/scrape-ledger.db "SELECT COUNT(*) FROM scraped" 2>/dev/null)
 
 
54
  echo "═══ LOOP DONE $(date +%H:%M:%S)" | tee -a "$LOG"
55
  echo " iters: $ITER" | tee -a "$LOG"
56
  echo " pairs added: $((AFTER_PAIRS - BEFORE_PAIRS))" | tee -a "$LOG"
 
10
  PARALLEL="${2:-3}"
11
  LOG="$HOME/.surrogate/logs/domain-scrape-loop.log"
12
  START=$(date +%s)
13
+
14
+ # Initialize ledger if missing (creates the 'scraped' table)
15
+ LEDGER_DB="$HOME/.surrogate/state/scrape-ledger.db"
16
+ if [[ ! -f "$LEDGER_DB" ]] || ! sqlite3 "$LEDGER_DB" "SELECT 1 FROM scraped LIMIT 1" >/dev/null 2>&1; then
17
+ bash "$HOME/.surrogate/bin/scrape-ledger-init.sh" 2>>"$LOG"
18
+ fi
19
+
20
+ # Default 0 if query fails (was causing empty arithmetic in iter logs)
21
+ BEFORE_PAIRS=$(wc -l "$HOME/.surrogate/training-pairs.jsonl" 2>/dev/null | awk '{print $1}')
22
+ BEFORE_PAIRS=${BEFORE_PAIRS:-0}
23
+ BEFORE_LEDGER=$(sqlite3 "$LEDGER_DB" "SELECT COUNT(*) FROM scraped" 2>/dev/null)
24
+ BEFORE_LEDGER=${BEFORE_LEDGER:-0}
25
 
26
  echo "═══ LOOP START $(date +%H:%M:%S) duration=${DUR}s parallel=$PARALLEL" | tee -a "$LOG"
27
  echo " before: pairs=$BEFORE_PAIRS ledger_repos=$BEFORE_LEDGER" | tee -a "$LOG"
 
32
  [[ $((NOW - START)) -gt $DUR ]] && break
33
  ITER=$((ITER + 1))
34
 
35
+ # Health check β€” break if load > 10 (Linux: "load average:", macOS: "load averages:")
36
+ LOAD=$(uptime | sed -E 's/.*load average[s]?:[[:space:]]*//' | awk -F',' '{print int($1)}')
37
+ LOAD=${LOAD:-0}
38
  if [[ $LOAD -gt 10 ]]; then
39
  echo " [iter=$ITER] load=$LOAD pause 30s" | tee -a "$LOG"
40
  sleep 30
 
54
 
55
  # Progress every 5 iters
56
  if (( ITER % 5 == 0 )); then
57
+ PAIRS=$(wc -l "$HOME/.surrogate/training-pairs.jsonl" 2>/dev/null | awk '{print $1}')
58
+ PAIRS=${PAIRS:-0}
59
+ LEDGER=$(sqlite3 "$LEDGER_DB" "SELECT COUNT(*) FROM scraped" 2>/dev/null)
60
+ LEDGER=${LEDGER:-0}
61
  echo " [iter=$ITER $((NOW - START))s] pairs=$PAIRS (+$((PAIRS - BEFORE_PAIRS))) ledger=$LEDGER (+$((LEDGER - BEFORE_LEDGER)))" | tee -a "$LOG"
62
  fi
63
  done
64
 
65
+ AFTER_PAIRS=$(wc -l "$HOME/.surrogate/training-pairs.jsonl" 2>/dev/null | awk '{print $1}')
66
+ AFTER_PAIRS=${AFTER_PAIRS:-0}
67
+ AFTER_LEDGER=$(sqlite3 "$LEDGER_DB" "SELECT COUNT(*) FROM scraped" 2>/dev/null)
68
+ AFTER_LEDGER=${AFTER_LEDGER:-0}
69
  echo "═══ LOOP DONE $(date +%H:%M:%S)" | tee -a "$LOG"
70
  echo " iters: $ITER" | tee -a "$LOG"
71
  echo " pairs added: $((AFTER_PAIRS - BEFORE_PAIRS))" | tee -a "$LOG"
bin/hermes-status-server.py CHANGED
@@ -102,10 +102,23 @@ def _agentic_visited() -> int:
102
 
103
 
104
  def _ollama_models() -> list[str]:
 
 
105
  try:
106
- import urllib.request, json as _json
107
- with urllib.request.urlopen("http://127.0.0.1:11434/api/tags", timeout=2) as r:
108
- return [m["name"] for m in _json.load(r).get("models", [])]
 
 
 
 
 
 
 
 
 
 
 
109
  except Exception:
110
  return []
111
 
@@ -136,10 +149,14 @@ def health() -> dict:
136
  def log_tail(name: str, lines: int = 100) -> PlainTextResponse:
137
  """Tail a specific log file. Allowlist for security."""
138
  allowed = {
139
- "boot", "cron", "scrape-continuous", "scrape-daemon",
140
- "agentic-crawler", "skill-synthesis", "auto-orchestrate-loop",
141
- "training-push", "ollama", "discord-bot", "surrogate-research-loop",
142
- "domain-scrape", "qwen-coder", "git-clone", "git-pull",
 
 
 
 
143
  }
144
  if name not in allowed:
145
  raise HTTPException(404, f"Unknown log: {name}. Allowed: {sorted(allowed)}")
 
102
 
103
 
104
  def _ollama_models() -> list[str]:
105
+ """Quick (non-blocking) check of loaded Ollama models. Caches for 30s."""
106
+ cache = HOME / ".surrogate/state/.ollama-models-cache.json"
107
  try:
108
+ import json as _json, time
109
+ if cache.exists():
110
+ cached = _json.loads(cache.read_text())
111
+ if time.time() - cached.get("ts", 0) < 30:
112
+ return cached.get("models", [])
113
+ except Exception:
114
+ pass
115
+ try:
116
+ import urllib.request, json as _json, time
117
+ with urllib.request.urlopen("http://127.0.0.1:11434/api/tags", timeout=1.5) as r:
118
+ models = [m["name"] for m in _json.load(r).get("models", [])]
119
+ cache.parent.mkdir(parents=True, exist_ok=True)
120
+ cache.write_text(_json.dumps({"ts": time.time(), "models": models}))
121
+ return models
122
  except Exception:
123
  return []
124
 
 
149
  def log_tail(name: str, lines: int = 100) -> PlainTextResponse:
150
  """Tail a specific log file. Allowlist for security."""
151
  allowed = {
152
+ "boot", "cron", "cron-master", "scrape-continuous", "scrape-daemon",
153
+ "scrape-keyword-tuner", "agentic-crawler", "skill-synthesis",
154
+ "auto-orchestrate-loop", "training-push", "ollama", "discord-bot",
155
+ "hermes-discord-bot", "surrogate-research-loop", "surrogate-research-apply",
156
+ "surrogate-dev-loop", "domain-scrape-loop", "github-domain-scrape",
157
+ "qwen-coder", "git-clone", "git-pull", "redis",
158
+ "ollama-pull-coder", "ollama-pull-devstral", "ollama-pull-fallback",
159
+ "ollama-pull-yicoder", "ollama-pull-embed", "ollama-pull-light",
160
  }
161
  if name not in allowed:
162
  raise HTTPException(404, f"Unknown log: {name}. Allowed: {sorted(allowed)}")
bin/surrogate-orchestrate.sh CHANGED
@@ -531,8 +531,8 @@ if echo "$VERDICT_TEXT" | grep -qi "APPROVE"; then
531
  echo "${GR}${B}β–Έ Reviewer approved β€” committing changes${R}"
532
  if ! git -C "$(pwd)" diff --quiet 2>/dev/null || ! git -C "$(pwd)" diff --cached --quiet 2>/dev/null; then
533
  git -C "$(pwd)" add -A 2>/dev/null
534
- local short_task; short_task=$(echo "$TASK" | head -c 72)
535
- if git -C "$(pwd)" commit -m "feat: $short_task
536
 
537
  [surrogate auto-dev session $SESSION_ID]
538
  [reviewed: APPROVE]" 2>&1 | tee -a "$WORKDIR/git-commit.log" | grep -q "master\|main\|\["; then
 
531
  echo "${GR}${B}β–Έ Reviewer approved β€” committing changes${R}"
532
  if ! git -C "$(pwd)" diff --quiet 2>/dev/null || ! git -C "$(pwd)" diff --cached --quiet 2>/dev/null; then
533
  git -C "$(pwd)" add -A 2>/dev/null
534
+ SHORT_TASK=$(echo "$TASK" | head -c 72)
535
+ if git -C "$(pwd)" commit -m "feat: $SHORT_TASK
536
 
537
  [surrogate auto-dev session $SESSION_ID]
538
  [reviewed: APPROVE]" 2>&1 | tee -a "$WORKDIR/git-commit.log" | grep -q "master\|main\|\["; then