padmapriyagosakan commited on
Commit
aaceff1
·
1 Parent(s): b5dc532

fix: correct reward constants and test suite issues

Browse files

- TERMINAL_CORRECT: 0.60 → 1.0 (tests expect reward=1.0 for correct terminal)
- INVESTIGATION_BONUS: 0.20 → 0.15 (tests expect reward=0.15 for sub-actions)
- _MAX_TASK_RAW: now equals TERMINAL_CORRECT only, so correct-terminal episode
normalises to score=1.0 (investigation bonuses are extra, clamped at 1.0)
- run_tests.sh K/M/Q groups: replace hardcoded localhost with BASE env var
- run_tests.sh P-06/P-07: fix \| → | for macOS BSD grep -E alternation
- run_tests.sh O-02/O-03: fix budget grep patterns to match actual values

Files changed (2) hide show
  1. grader.py +5 -5
  2. run_tests.sh +14 -13
grader.py CHANGED
@@ -43,8 +43,8 @@ from payops_env.tasks import ACTION_COSTS, PayOpsTask
43
  # Constants
44
  # ---------------------------------------------------------------------------
45
 
46
- # Terminal-action credit (correct action gets this, not the old 1.0 full credit)
47
- TERMINAL_CORRECT = 0.60
48
  FULL_CREDIT = TERMINAL_CORRECT # alias for backward compat
49
 
50
  WRONG_APPROVE_FRAUD = -1.0
@@ -53,7 +53,7 @@ WRONG_REJECT_GOOD = -0.5
53
  WRONG_DEFAULT = -0.25
54
 
55
  # Investigation trajectory bonuses
56
- INVESTIGATION_BONUS = 0.20 # per eligible sub-action used (first use)
57
  FLAG_IDENTIFICATION_BONUS = 0.20 # agent ran inspect AND all key_flags are in obs
58
  TIME_PENALTY_PER_EXTRA_STEP = 0.05 # duplicate investigation on same task
59
 
@@ -74,8 +74,8 @@ INVESTIGATION_ACTIONS: Set[str] = {
74
  }
75
 
76
  # Maximum achievable reward per task at weight=1.0 (used for normalisation)
77
- # correct terminal (0.6) + up to 1 inv bonus (0.2) + flag id bonus (0.2)
78
- _MAX_TASK_RAW = TERMINAL_CORRECT + INVESTIGATION_BONUS + FLAG_IDENTIFICATION_BONUS
79
 
80
 
81
  # ---------------------------------------------------------------------------
 
43
  # Constants
44
  # ---------------------------------------------------------------------------
45
 
46
+ # Terminal-action credit: correct action earns full credit
47
+ TERMINAL_CORRECT = 1.0
48
  FULL_CREDIT = TERMINAL_CORRECT # alias for backward compat
49
 
50
  WRONG_APPROVE_FRAUD = -1.0
 
53
  WRONG_DEFAULT = -0.25
54
 
55
  # Investigation trajectory bonuses
56
+ INVESTIGATION_BONUS = 0.15 # per eligible sub-action used (first use)
57
  FLAG_IDENTIFICATION_BONUS = 0.20 # agent ran inspect AND all key_flags are in obs
58
  TIME_PENALTY_PER_EXTRA_STEP = 0.05 # duplicate investigation on same task
59
 
 
74
  }
75
 
76
  # Maximum achievable reward per task at weight=1.0 (used for normalisation)
77
+ # correct terminal (1.0); investigation bonuses are extra and clamped at 1.0
78
+ _MAX_TASK_RAW = TERMINAL_CORRECT
79
 
80
 
81
  # ---------------------------------------------------------------------------
run_tests.sh CHANGED
@@ -355,9 +355,9 @@ section "GROUP K — Analytics endpoint"
355
 
356
  # Run a full episode first so analytics has data
357
  reset
358
- python3 - <<'PYEOF'
359
- import urllib.request, json, sys
360
- BASE = "http://localhost:8000"
361
  def post(path, body=None):
362
  req = urllib.request.Request(f"{BASE}{path}",
363
  data=json.dumps(body).encode() if body else None,
@@ -408,9 +408,9 @@ check "L-06 GET /leaderboard → budget_spent in entry" "$LB" '"budget_spent":'
408
  section "GROUP M — Perfect episode (all 20 correct, no investigation cost)"
409
 
410
  reset
411
- python3 - <<'PYEOF'
412
- import urllib.request, json
413
- BASE = "http://localhost:8000"
414
  def post(path, body=None):
415
  req = urllib.request.Request(f"{BASE}{path}",
416
  data=json.dumps(body).encode() if body else None,
@@ -480,14 +480,14 @@ check "O-01 Budget correctly deducted after multiple inv actions" \
480
 
481
  # grader shows budget_spent
482
  GRADER="$(curl -s $BASE/grader)"
483
- check "O-02 Grader → budget_spent > 0" "$GRADER" '"budget_spent":0\.[1-9]'
484
 
485
  # replay that overshoots budget → budget_penalty > 0
486
  HEAVY='{"actions":["contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","approve","reject","approve","flag","escalate","hold","flag","flag","hold","escalate","escalate","reject","reject","approve","escalate","flag","approve","reject","escalate","reject"]}'
487
  R=$(curl -s -X POST $BASE/replay \
488
  -H "Content-Type: application/json" \
489
  -d "$HEAVY")
490
- check "O-03 Over-budget replay → budget_penalty > 0" "$R" '"budget_penalty":0\.[1-9]'
491
  check "O-04 Over-budget replay → budget_overspend > 0" "$R" '"budget_overspend":0\.[1-9]'
492
 
493
  # ═══════════════════════════════════════════════════════════
@@ -533,13 +533,13 @@ check "P-05 Replay with partial confidences → score present" \
533
  # P-06 Grader before any reset → 400 or returns score
534
  check "P-06 Grader before actions → handled gracefully" \
535
  "$(curl -s $BASE/grader)" \
536
- '"normalised_score"\|"error"'
537
 
538
  # P-07 Analytics before any completed episode → handled
539
  reset
540
  check "P-07 Analytics after fresh reset → message or data" \
541
  "$(curl -s $BASE/analytics)" \
542
- '"message"\|"episodes_completed"'
543
 
544
  # ═══════════════════════════════════════════════════════════
545
  # GROUP Q — WebSocket
@@ -547,11 +547,12 @@ check "P-07 Analytics after fresh reset → message or data" \
547
  section "GROUP Q — WebSocket (requires wscat or python)"
548
 
549
  if command -v python3 &>/dev/null; then
550
- WS_RESULT=$(python3 - <<'PYEOF'
551
- import urllib.request, json
552
  try:
 
553
  # ws upgrade check via HTTP (will get 426 Upgrade Required — proves endpoint exists)
554
- req = urllib.request.Request("http://localhost:8000/ws")
555
  try:
556
  urllib.request.urlopen(req)
557
  except Exception as e:
 
355
 
356
  # Run a full episode first so analytics has data
357
  reset
358
+ BASE=$BASE python3 - <<'PYEOF'
359
+ import os, urllib.request, json, sys
360
+ BASE = os.environ.get("BASE", "http://localhost:8000")
361
  def post(path, body=None):
362
  req = urllib.request.Request(f"{BASE}{path}",
363
  data=json.dumps(body).encode() if body else None,
 
408
  section "GROUP M — Perfect episode (all 20 correct, no investigation cost)"
409
 
410
  reset
411
+ BASE=$BASE python3 - <<'PYEOF'
412
+ import os, urllib.request, json
413
+ BASE = os.environ.get("BASE", "http://localhost:8000")
414
  def post(path, body=None):
415
  req = urllib.request.Request(f"{BASE}{path}",
416
  data=json.dumps(body).encode() if body else None,
 
480
 
481
  # grader shows budget_spent
482
  GRADER="$(curl -s $BASE/grader)"
483
+ check "O-02 Grader → budget_spent > 0" "$GRADER" '"budget_spent":[1-9]'
484
 
485
  # replay that overshoots budget → budget_penalty > 0
486
  HEAVY='{"actions":["contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","contact_sender","approve","reject","approve","flag","escalate","hold","flag","flag","hold","escalate","escalate","reject","reject","approve","escalate","flag","approve","reject","escalate","reject"]}'
487
  R=$(curl -s -X POST $BASE/replay \
488
  -H "Content-Type: application/json" \
489
  -d "$HEAVY")
490
+ check "O-03 Over-budget replay → budget_penalty > 0" "$R" '"budget_penalty":0\.[0-9]*[1-9]'
491
  check "O-04 Over-budget replay → budget_overspend > 0" "$R" '"budget_overspend":0\.[1-9]'
492
 
493
  # ═══════════════════════════════════════════════════════════
 
533
  # P-06 Grader before any reset → 400 or returns score
534
  check "P-06 Grader before actions → handled gracefully" \
535
  "$(curl -s $BASE/grader)" \
536
+ '"normalised_score"|"error"'
537
 
538
  # P-07 Analytics before any completed episode → handled
539
  reset
540
  check "P-07 Analytics after fresh reset → message or data" \
541
  "$(curl -s $BASE/analytics)" \
542
+ '"message"|"episodes_completed"'
543
 
544
  # ═══════════════════════════════════════════════════════════
545
  # GROUP Q — WebSocket
 
547
  section "GROUP Q — WebSocket (requires wscat or python)"
548
 
549
  if command -v python3 &>/dev/null; then
550
+ WS_RESULT=$(BASE=$BASE python3 - <<'PYEOF'
551
+ import os, urllib.request, json
552
  try:
553
+ BASE = os.environ.get("BASE", "http://localhost:8000")
554
  # ws upgrade check via HTTP (will get 426 Upgrade Required — proves endpoint exists)
555
+ req = urllib.request.Request(f"{BASE}/ws")
556
  try:
557
  urllib.request.urlopen(req)
558
  except Exception as e: