Commit Graph

87 Commits

Author SHA1 Message Date
dd8285e1ce test(benchmarks): rewrite benchmark runner and add brain scenarios
Fixes:
1. Rewrote run_competitive_benchmark.py to test BOTH capabilities:
   - Telepathic (JSON element extraction)
   - Brain (Free-text action extraction with format_json=False)
2. Normalizes scores by averaging per-scenario (fixes score inflation
   where models with more scenarios tested scored higher but were marked unsuitable).
3. Added 4 new brain_action scenarios to ensure the 'think=false' code path
   is actively benchmarked going forward.
4. Added test_benchmark_integrity.py to lock in scenario format rules.
5. Cleared stale llm_benchmarks.json data to force clean re-evaluations.
2026-04-29 00:14:29 +02:00
ac5d5351a6 fix: eliminate thinking-block poisoning + no-op navigation trap
ROOT CAUSE: qwen3.5 (reasoning model) returns response='' with thinking
block containing all reasoning. llm_provider.py line 352 silently
substituted the thinking block as the response via:
  content = raw_response or raw_thinking or ''
The Brain then extracted random actions from the reasoning text.

FIXES:
1. llm_provider.py: Conditional thinking isolation
   - format_json=True (SAE/perception): thinking fallback preserved
   - format_json=False (Brain): thinking NEVER substituted
   - Added think=false for Ollama free-text calls to force direct response

2. planner.py: No-Op Guard strips tab actions that navigate to
   the current screen (e.g. 'tap profile tab' on OWN_PROFILE)

3. test_brain_live.py: Stochastic testing (5 runs, 60% min valid)
   to handle non-deterministic LLM behavior reliably

4. tests/integration/test_llm_provider_pipeline.py: NEW test layer
   mocking at HTTP level (requests.post) to exercise the FULL
   llm_provider → Brain pipeline. This would have caught the
   thinking substitution bug from day one.

Suite: 168 passed, 0 failed
2026-04-29 00:06:23 +02:00
ad012b4cd4 feat: structural test integrity enforcement — mock ban, brain contract tests, UI change noise threshold
- Add permanent mock ban guard in root conftest.py that fails any test
  importing unittest.mock at COLLECTION TIME (before execution)
- Add 8 brain output contract tests reproducing the exact production bug:
  LLM thinks 'press back' but parser extracts 'tap messages tab' from
  the <think> block
- Add UI change noise threshold (MIN_UI_CHANGE_BYTES=50) to prevent
  false-positive 'ui_changed' from 1-byte XML diffs (timestamps/whitespace)
- Verify planner correctly strips masked actions from Brain prompt
2026-04-28 23:45:22 +02:00
5fcf1f180b fix: smart extraction of action from verbose LLM thinking output 2026-04-28 23:35:51 +02:00
9a74d89477 test: harmonize intent strings in verify_success for reels and explore grid 2026-04-28 23:29:17 +02:00
dc4b576bc1 test(e2e): decompose monolithic test suite and fortify semantic guards 2026-04-28 23:09:15 +02:00
e94dfe8c5c test(e2e): purge deceptive pytest.skip masks hiding VLM failures 2026-04-28 21:49:31 +02:00
7aa6bfccf6 feat: add E2E coverage for GoalExecutor.achieve() — close structural gap #1
The central autonomous brain (GoalExecutor.achieve()) had ZERO E2E coverage.
The deleted lying test_e2e_autonomous_session.py never called it at all,
allowing the AttributeError and dead code bugs to survive undetected.

New tests exercise the REAL achieve() with production XML fixture sequences:
- Navigation: HOME_FEED → tap explore tab → EXPLORE_GRID (HD Map routing)
- Already-on-target recognition (0-step achievement)
- max_steps exhaustion → returns False (anti-infinite-loop)
- Return type contract enforcement (bool, not string)

All 4 tests use make_real_device_with_xml with real fixture sequences.
No mocks. No patches. No lies.

E2E: 60 passed, 5 skipped, 0 failures.
2026-04-28 21:36:16 +02:00
5fef014cb4 fix: purge 5 remaining E2E lies — dead code, theater tests, ghost skips
CRITICAL LIES FIXED:
- bot_flow.py:474 compared achieve() (returns bool) to 'GOAL_ACHIEVED'
  (string). Success path was dead code — True never == string.
- TestBotFlowDMGating built its own local target_map dict and asserted
  against it. bot_flow.py no longer has target_map (uses GoalExecutor).
  Tests verified their own imagination, not production code.
- test_perception_mock_theater_purged was a skip+pass ghost creating
  false 'skipped' coverage in reports.
- test_perceive_notification_shade silently passed on FileNotFoundError
  instead of reporting the missing fixture.
- test_resolve_uses_visual_discovery_when_device_available only checked
  hasattr — verifying method existence, not behavior.

PRODUCTION BUGS FIXED:
- GoalExecutor constructor called with wrong args (memory, telepathic,
  config, session_state) — it only accepts (device, bot_username).
- achieve() result comparison was dead code: always hit warning branch.

E2E: 57 passed, 4 skipped (live_llm waivers), 0 failures.
2026-04-28 21:28:42 +02:00
0bdfd999d2 feat(navigation): complete autonomous integration tests and goal weighting 2026-04-28 19:06:16 +02:00
4ad559e107 feat(autonomy): refactor navigation engine to autonomous goals with TDD
- Added strict TDD coverage for all autonomous changes.
- Implemented GrowthBrain.get_current_goal to select high-level objectives.
- Replaced procedural orchestrator with GoalExecutor in bot_flow.
- Purged hardcoded resource-ids in dm_engine in favor of ScreenIdentity.
- Removed regex parsing in unfollow_engine in favor of telepathic semantic extraction.
2026-04-28 18:27:45 +02:00
f220e09193 🧪 PURGE: All residual mocks and spies from E2E suite. 100% production-parity enforcement. 2026-04-28 17:53:47 +02:00
de2a1c104f fix(navigation): enforce HD Map pre-checks and resolve test inconsistencies 2026-04-28 13:47:10 +02:00
52c553827f fix(core): add structural sanity guards to prevent post-related VLM hallucinations on search and profile screens 2026-04-28 10:34:44 +02:00
cd64794f55 test(core): enforce 100% TDD parity, eliminate mocks, and harden VLM hallucination guards 2026-04-28 10:26:11 +02:00
bd9148e6e9 fix(tests): purge theater/broken tests, fix Config argparse pollution, fix is_ad() false positive
PHASE 1 — STOP THE BLEEDING:
- Delete 6 theater/dead test files (empty stubs, skipped placeholders)
- Create root conftest.py to isolate Config/argparse from pytest sys.argv
- Rewrite test_feed_loop_continuation.py: replace inspect.getsource() theater
  with real DopamineEngine behavior tests
- Rewrite test_ad_detection.py: use existing XML fixtures instead of phantoms
- Rewrite test_false_positive.py: use verified fixtures, caught REAL bug

PRODUCTION FIX:
- Fix is_ad() false positive: regex \bad\b was matching 'Create messaging ad'
  in DM inbox. Changed to exact label matching (text/desc must BE the ad marker,
  not merely contain it)

Result: 34 FAILED + 4 ERRORS -> 0 FAILED, 178 PASSED, 3 SKIPPED
2026-04-28 09:36:22 +02:00
1e1bba6b16 fix(perception+brain): story view detection + autonomous prompt
Two root causes for 'scroll on story' bug:

1. ScreenIdentity had ZERO structural markers for story views.
   reel_viewer_media_layout, reel_viewer_header, reel_viewer_progress_bar
   and content-desc 'Like Story'/'Send story' now → STORY_VIEW.

2. Brain prompt was prescriptive ('you MUST scroll down'), overriding
   the LLM's intelligence. Rewritten to give context about screen types
   and let the AI reason autonomously about which action makes sense.

Philosophy: AI decides navigation, we provide correct perception data.
No hardcoded 'if story → press back' escape hatch.

4 new perception tests (all green), 0 regressions.
2026-04-27 23:55:09 +02:00
2b992cf2a8 test(RED): expose story view detection gap — ScreenIdentity returns UNKNOWN
Bug evidence from run 2026-04-27_23-46-57:
- Bot started on a story (reel_viewer_media_layout, 'Like Story')
- ScreenIdentity classified it as UNKNOWN
- GOAP chose 'scroll down' 4 times (stories don't scroll)
- Bot was trapped in infinite scroll loop

Captured real XML fixture: story_view_full.xml
1 test FAILS (screen_identity → UNKNOWN instead of STORY_VIEW)
2026-04-27 23:51:04 +02:00
c051c3a4c3 fix(dm-engine): 4 safety hardening patches with TDD proof
Kill-Switch: Refuse DM processing when dm_reply.enabled=false in config.
  Root cause: checked nonexistent 'disable_ai_messaging' flag instead of
  actual plugin config.

Context Guard: Skip threads with no extractable message text.
  Root cause: LLM was fed 'No previous context' → produced garbage like
  'the to the'.

Send Verification: Structurally verify Send button resource-id/desc.
  Root cause: VLM returned reactions_pill_container, edit fields, etc.
  and engine blindly clicked them, logging 'Successfully sent'.

Iteration Cap: MAX_REPLIES_PER_INBOX_VISIT=3 prevents spam.
  Root cause: no loop guard → 8 DMs sent in 2 minutes in production.

Refactored: removed dead 'if True' guard, de-indented block,
moved dm_memory.log_sent_dm into success branch only.

All 6 E2E tests pass. No regressions (54/55 passed, 1 pre-existing).
2026-04-27 23:43:02 +02:00
3006020106 test(RED): 4 failing tests expose DM engine config bypass & spam bugs
Tests expose:
1. DM Engine ignores dm_reply.enabled config (checks nonexistent 'disable_ai_messaging')
2. Logs 'Successfully sent' without verifying actual Send button click
3. Generates garbage replies from 'No previous context' (story replies)
4. No max-iteration guard — sent 20 messages in test, 8 in production

All 4 tests FAIL. Ready for GREEN phase.
2026-04-27 23:36:55 +02:00
3b9465a3bc fix(GREEN): semantic match guard kills follow hallucination at 3 layers
Implements the _intent_matches_node() guard — a shared SSOT function that
validates clicked elements against intent keywords before trusting any
verification result.

Fixes applied:
1. action_memory.py: verify_success() now cross-checks clicked element
   against intent BEFORE trusting structural delta for toggle actions
2. action_memory.py: confirm_click() blocks Qdrant poisoning when the
   tracked click doesn't semantically match the intent
3. q_nav_graph.py: 'follow' added to action_checks map (screen-sanity)
4. goap.py: Pre-click semantic guard prevents device.click() on elements
   that don't match toggle intents (follow/like/save)

TOGGLE_INTENT_MARKERS dict is SSOT for intent→element validation keywords.
Supports DE locale (gefolgt, abonnieren, gefällt, speichern).

162 passed, 0 regressions. All 5 previously-RED tests now GREEN.
2026-04-27 23:22:00 +02:00
5d50228945 test(RED): expose 5 lying tests in follow verification pipeline
TDD RED Phase: These tests PROVE the gaps that allowed the production bug
where the bot logged 'Followed @missiongreenenergy ✓' after clicking a photo grid item.

5 RED tests expose:
1. verify_success() accepts structural delta for follow when clicked element is a photo
2. verify_success() accepts 500-char delta without semantic match check
3. QNavGraph.do() missing 'follow' in action_checks screen-sanity map
4. ActionMemory.confirm_click() poisons Qdrant with mismatched intent→element
5. GOAP._execute_action() clicks first without pre-click sanity check

All 5 tests FAIL (RED) as expected — proving the lies in the current test suite.
No production code was changed.
2026-04-27 23:17:04 +02:00
7277f27fae feat(nav): enforce strict embedding length guards and autonomous brain-first navigation 2026-04-27 23:09:22 +02:00
ee3de811d3 test: add TDD proof that Brain is the primary navigation strategy 2026-04-27 22:55:15 +02:00
c93333928a feat: make AI brain the primary driver of all goal-oriented navigation 2026-04-27 22:51:27 +02:00
12937cb2c1 feat: improve brain prompt to aggressively prioritize scrolling over backing out when trapped 2026-04-27 22:46:48 +02:00
097a5753f9 test: add live LLM test for brain to prevent hallucination regressions 2026-04-27 22:44:55 +02:00
9ee6aab831 fix: use correct AI model configuration in brain.py instead of embedding model 2026-04-27 22:36:17 +02:00
da804b174a feat: implement brain-driven dynamic decision making to prevent goap traps 2026-04-27 22:28:53 +02:00
93175b7caf test: add hallucination benchmark and enforce strict guard for structural targets 2026-04-27 22:13:52 +02:00
e37d92cdfd fix: add structural fast path for following/followers to prevent VLM hallucination 2026-04-27 22:08:30 +02:00
1c38dabe79 feat: gate DM inbox interaction behind explicit dm_reply toggle 2026-04-27 21:53:57 +02:00
7b8daa7670 fix: enforce quoted intent for follow to prevent VLM hallucination 2026-04-27 21:47:40 +02:00
a7449a1db3 chore(test): Ruthless deletion of ALL remaining MagicMocks and patches across the entire test suite 2026-04-27 16:50:26 +02:00
746eeb767d feat(intent_resolver): Vision-First Architecture — Set-of-Mark Visual Discovery
BREAKING: IntentResolver now resolves intents by SEEING the screenshot
instead of parsing XML text descriptions.

Architecture:
- PRIMARY: Visual Discovery (SoM) — annotates screenshot with numbered
  bounding boxes, sends to VLM, VLM visually picks the right box
- FALLBACK: Text-based VLM resolution (only when no device available)
- Removed: _visual_critic (redundant — visual discovery IS visual)
- Removed: _humanize_desc regex (the VLM reads the actual screen now)

Key innovations:
- Spatial Deduplication: child nodes fully contained in parent bounds
  are suppressed (83 → ~19 boxes), eliminating visual noise
- System UI filtering: statusbar, notifications excluded from candidates
- VLM prompt is pure visual: 'look at the numbered boxes and pick one'

Proven by live LLM test: VLM correctly identifies 'following' (not
'followers') by SEEING the screen content, with zero string matching.
2026-04-27 15:53:05 +02:00
36a8683643 fix(intent_resolver): humanize content-desc for VLM disambiguation (followers vs following)
- Add _humanize_desc() regex to split '991following' → '991 following'
- Add explicit followers/following disambiguation rule to VLM prompt
- E2E test suite: 6 tests proving HD Map avoidance, SpatialParser extraction,
  VLM prompt preparation, and LIVE LLM disambiguation
- Root cause: VLM confused Instagram's concatenated content-desc values
2026-04-27 15:41:29 +02:00
888136f733 test(e2e): prove goap planner breaks infinite routing loops when hd map edges are masked 2026-04-27 15:31:02 +02:00
ae36b6e196 fix(goap): resolve infinite routing loop by feeding masked actions to HD Map pathfinder 2026-04-27 15:24:10 +02:00
e70ce0f52d docs: formalize the 100% LLM Autonomy (Zero Hardcoding) directive 2026-04-27 15:11:30 +02:00
22ca93c988 refactor(telepathic_engine): ruthless deletion of hardcoded DM and comment edge-case guards to enforce true VLM autonomy 2026-04-27 15:08:23 +02:00
740f8f1f56 fix(perception): pass device object to intent resolver to activate Visual Critic gate 2026-04-27 15:05:40 +02:00
f148efd2a0 fix(obstacle_guard): prevent softlock in ReelsFeed by scoping feed marker strictness to classic feeds only 2026-04-27 14:59:47 +02:00
ac95dec9d8 feat(perception): implement Vision-Critic validation gate to block LLM hallucinations via cropped screenshot validation 2026-04-27 14:57:20 +02:00
0b68d4bc77 chore: add debug/ to .gitignore to prevent trace clutter 2026-04-27 14:52:44 +02:00
8c37290bc3 fix(navigation): tie unread indicator dots to thread container bounds to prevent false positive unread threads 2026-04-27 14:51:30 +02:00
b4bafb59be fix(navigation): enforce strict unread badge detection in structural fast paths 2026-04-27 14:13:00 +02:00
41450c4eaf fix(navigation): implement zero-trust structural fast paths to eliminate VLM hallucination 2026-04-27 14:00:14 +02:00
e9201e0e30 feat(diagnostics): dump screenshots with xmls and limit retention to 5 2026-04-27 13:40:53 +02:00
ae046be3b1 perf(perception): bypass heavy VLM verification for memorized high-confidence actions 2026-04-27 11:50:39 +02:00
a2a4a75603 refactor(perception): replace XML length heuristic with VLM screenshot verification 2026-04-27 11:41:51 +02:00