Codex Handoff: Pam — Next Tasks
Date: 2026-04-16
Branch: Work from main
Test baseline: 181 pass, 7 fail, 22 error (210 total)
Goal: All 210 tests passing, research loop producing valid gate metrics, live scanner surfacing at least 1 deployable_trade per scan cycle.
Priority 1 — Fix Failing Tests
1a. Book dataclass missing contract_side field (22 errors)
The Book dataclass in arbitrage/liquidity.py now requires a contract_side field, but three test files still construct Book without it.
Fix: Add contract_side="yes" to every Book(...) call in:
- tests/test_liquidity.py
- tests/test_pricing.py
- tests/test_executor_paths.py
This is a mechanical find-and-replace. Once done, 22 errors should clear.
1b. equivalence_score() signature changed (3 failures)
equivalence_score() in matcher/align.py now requires 4 positional args: (pm, pm_parsed, ks, ks_parsed, expiry_tol_sec=90). The 3 call sites in tests/test_matcher.py still pass only 2 args.
Fix: Update each call to pass ks and ks_parsed dicts as the 3rd and 4th arguments. Check tests/test_matcher.py for the context around each call to determine appropriate test fixture values.
1c. Stale expiration fixture in tests/test_scanner_gates.py (1 failure)
Line 48 uses "2026-04-10T12:00:00Z" as an expiration date, which is now in the past.
Fix: Change "2026-04-10T12:00:00Z" → "2027-04-10T12:00:00Z". One-line change.
1d. Equivalence score regression in tests/test_parsers_matcher.py::test_equivalence_close (1 failure)
The BTC price pair test expects a score of >=0.9 but currently returns 0.76. This is a real logic regression, not a stale fixture.
Investigation path:
- Look at recent changes to matcher/align.py, specifically the penalty weights used by equivalence_score()
- The score drop from >=0.9 to 0.76 suggests a penalty was added or an existing weight was increased
- Run the test in isolation with verbose output to see which sub-score is dragging it down
- Restore the penalty weights for the BTC-style case, or adjust the scoring so a close price-pair match still scores >=0.9
Priority 2 — Research Loop State
research/latest_state.json currently shows confident: True with score: None, stable_cycles: None, hit_rate: None. The deployment gate is passing on empty metrics — this is a false positive.
Steps:
1. Run: python main.py research-loop --max-cycles 1
2. Verify research/latest_state.json is repopulated with non-null values for score, stable_cycles, and hit_rate
3. If the gate passes again after the run, confirm it’s passing on real numbers, not nulls
4. If the run fails or produces nulls, check research/continuous_loop.py for where these fields are written — the write path may have a silent exception or early exit
Context: research/best_strategy_params.json currently holds the best known baseline (score: 17.6, hit_rate: 0.8). The research loop should be able to evaluate against these params and produce a valid state snapshot.
Priority 3 — Live Scanner Effectiveness
The live scanner (strategy/kalshi_opportunity_scanner.py) produces mostly watch rows. The replay strategy is healthy (score: 17.6), but the live signal path doesn’t translate to deployable trades.
Current blockers (from CODEX_HANDOFF_STRATEGY_FIX.md):
- Global: stable_cycles < 3 — gate requires 3 consecutive cycles of stable confidence before deploying
- Local: live_edge_bps < 100.0 — individual candidates aren’t crossing the edge threshold
Task: Add a quantitative bypass path in the live scanner analogous to the replay-side quantitative_eventful_reversal sleeve.
The replay sleeve bypasses heuristic_direction entirely, gating only on eventful_score, price_move_bps, tradeability, and low live price. The live scanner should have a parallel code path that does the same: if a market meets the quantitative criteria, classify it as actionable regardless of heuristic_direction.
Key files:
- strategy/kalshi_opportunity_scanner.py — add the bypass path here
- research/candidate_review.py — check how live candidates are classified; may need mirroring
- research/strategy.py — reference implementation of quantitative_eventful_reversal sleeve
Verification:
cd /Users/joshua/Projects/Unicorn.Land/pam
source .venv/bin/activate
python main.py opportunity-scan --limit 20
python main.py trade-candidates --limit 20 --json
Target: at least 1 row with deployable_trade status. If still zero, document the exact remaining blocker mix:
- live heuristic direction
- live edge estimation
- stable-cycles gate
- sleeve matching / semantic mismatch
Priority 4 — Cleanup (Low Priority)
Remove stale debug and config files from the project root once the above are complete.
Debug scripts to delete:
- debug_dates.py
- debug_final_issue.py
- debug_polymarket_discovery.py
- algorithm_diagnosis.py
- fix_algorithm.py
- fix_discovery_patterns.py
Stale config files to delete:
- config_backup_20250913_143604.yaml
- config_backup_20250913_143647.yaml
- config_backup_20250913_143722.yaml
- config_fixed.yaml
- config_optimal.yaml
Use trash not rm for all deletions.
Success Criteria
| Check | Current | Target |
|---|---|---|
| Tests passing | 181/210 | 210/210 |
| Test failures | 7 | 0 |
| Test errors | 22 | 0 |
latest_state.json gate metrics |
null | populated |
opportunity-scan deployable rows |
0 | >= 1 per cycle |
Key Files Reference
| File | Purpose |
|---|---|
arbitrage/liquidity.py |
Book dataclass (source of 22 errors) |
matcher/align.py |
equivalence_score() (signature change + regression) |
tests/test_liquidity.py |
Needs contract_side="yes" fix |
tests/test_pricing.py |
Needs contract_side="yes" fix |
tests/test_executor_paths.py |
Needs contract_side="yes" fix |
tests/test_matcher.py |
Needs updated equivalence_score() call signatures |
tests/test_scanner_gates.py |
Needs future expiration date (line 48) |
tests/test_parsers_matcher.py |
test_equivalence_close regression |
research/latest_state.json |
Current research state snapshot |
research/continuous_loop.py |
Research loop orchestration |
research/best_strategy_params.json |
Current best params (score: 17.6) |
strategy/kalshi_opportunity_scanner.py |
Live scanner — add quantitative bypass here |
research/candidate_review.py |
Live market classification |
research/strategy.py |
Replay strategy sleeves (reference implementation) |