Skip to content

Sourcehunt native-async refactor; drop llm.compat; FFmpeg docs - #8

Merged
ehartford merged 1 commit into
mainfrom
sourcehunt-native-h264-fixes
Apr 16, 2026
Merged

ehartford merged 1 commit into
mainfrom
sourcehunt-native-h264-fixes

Conversation

@ropoctl

@ropoctl ropoctl commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Sourcehunt hot path is native async end-to-end. SourceHuntRunner.arun() drives the pipeline; run() is a thin asyncio.run wrapper. All stages now have async variants (Verifier.averify/arun_patch_oracle, Exploiter.aattempt, AutoPatcher.aattempt, MechanismExtractor.aextract, VariantPatternGenerator.agenerate, VariantLoop.arun/arun_once). Dropped the GenAIPyO3ChatModel alias and hardened record_finding against extra model-supplied kwargs.
  • NativeAgentGraph is async-only. astream/ainvoke are the primary API; internal loop / assistant-step / tool-call / tool-invoke are all async, and _ainvoke_tool awaits directly instead of spawning a nested event loop via asyncio.run. Operator grows arun; run() is an asyncio.run wrapper. Web app's websocket session and CI/CD runner / interactive CLI bridge at their own entry points — no in-graph sync-to-async drain.
  • Dropped clearwing/llm/compat.py. Removed sync entrypoints in 7 sourcehunt files that only existed to feed the compat shim; async entrypoints now call llm.aask_text / llm.aask_json directly. Rewrote 16 sourcehunt/operator test files to AsyncMock + aask_text/aask_json/ainvoke/astream patterns (~300 edits). Deleted tests/test_llm_compat.py.
  • README. New "Running sourcehunt on a local repo (FFmpeg example)" section showing how to drive SourceHuntRunner directly against an already-cloned tree with per-stage AsyncLLMClients against an OpenAI-compatible endpoint.

Commits

  • 62a5188 Move sourcehunt hot path to native async and harden record_finding
  • 5c0b0b3 Make NativeAgentGraph async-only; drop sync stream/invoke wrappers
  • b4b5203 Drop llm.compat; sourcehunt stages are native async end-to-end
  • c4e0dd8 README: document local-repo sourcehunt flow via SourceHuntRunner

Test plan

  • uv run python -m pytest -q tests/ → 1400 passed
  • uv run python -m compileall clearwing → clean
  • Live FFmpeg run against the native pipeline — ranker completes, tier-A hunter pool progresses, findings written; currently still running in background (pid 3442987)
  • Reviewer: spot-check astream/ainvoke contracts in clearwing/agent/runtime.py and the AsyncMock patterns in the rewritten sourcehunt tests
  • Reviewer: confirm the new README snippet matches the provider setup you expect users to have

Squashed rollup of the work on this branch.

- Hot path is native async end-to-end: SourceHuntRunner.arun() drives
  the pipeline; run() is a thin asyncio.run wrapper. Every stage gets an
  async variant: Verifier.averify/arun_patch_oracle, Exploiter.aattempt,
  AutoPatcher.aattempt, MechanismExtractor.aextract,
  VariantPatternGenerator.agenerate, VariantLoop.arun/arun_once.
- record_finding tolerates extra kwargs from the model (e.g.
  severity_reason) instead of crashing on them.
- Trajectory logging + verifier resilience fixes carried through.

- astream / ainvoke are the primary API; internal _arun_loop /
  _aassistant_step / _arun_tool_calls / _aresume / _ainvoke_tool are
  all async. Dropped the sync stream / invoke / _drain_async_gen
  wrappers that reached across the async boundary.
- Operator grows arun(); run() is asyncio.run(arun()). _arun_inner_turn
  / _ahandle_interrupt / _adecide_next use the async graph + ainvoke
  on the operator LLM.
- Web app's websocket handler drives astream / ainvoke directly; awaits
  operator.arun() instead of run_in_executor(operator.run).
- CI/CD runner and interactive CLI bridge to async via one asyncio.run
  at their own sync entry points.

- Delete clearwing/llm/compat.py and tests/test_llm_compat.py.
- Remove sync entrypoints that only existed to feed the compat shim
  (Exploiter.attempt, Verifier.verify/run_patch_oracle,
  AutoPatcher.attempt, MechanismExtractor.extract,
  VariantPatternGenerator.generate, VariantLoop.run/run_once).
- Async entrypoints await llm.aask_text / llm.aask_json directly.
- harness_generator bridges to aask_text via asyncio.run inside its
  ThreadPoolExecutor worker.
- Rewrite 16 sourcehunt/operator tests to AsyncMock + aask_text /
  aask_json / ainvoke / astream instead of MagicMock.invoke.

- Switch pyproject dep from git+URL to PyPI "genai-pyo3 >= 0.1.9".
- genai-pyo3's ChatResponse is now isomorphic to rust-genai: `content`
  is the single source of truth, `first_text()` / `texts()` /
  `tool_calls()` are derived-view methods (matching rust-genai's getter
  names). Dropped the flattened `text` / `texts` / `tool_calls` fields
  that forced callers to coalesce None manually.
- Switch every call site to the method form: sourcehunt verifier /
  exploiter / patcher / variant_loop / mechanism_memory /
  harness_generator / hunter, plus clearwing/llm/chat.py and
  clearwing/llm/native.py.
- Delete clearwing's ~45-line _collect_stream_response stream-synth:
  native.py now just routes to client.achat_via_stream() (a 0.1.9
  Rust-side feature that forces the capture flags, drains the stream,
  and hands back a fully-collected ChatResponse) for openai_resp and
  client.achat() otherwise.
- Tests that faked a ChatResponse via SimpleNamespace(text=...) now
  build a real pyclass via ChatResponse(content=[{"text": ...}]).

- New "Running sourcehunt on a local repo (FFmpeg example)" section
  showing how to drive SourceHuntRunner directly against an
  already-cloned tree with per-stage AsyncLLMClient instances against
  an OpenAI-compatible endpoint.

- ruff --fix + ruff format across sorted imports, dropped unused
  MagicMock imports, closure-var binding in interactive CLI
  _collect_events.

- 1400 tests passing, ruff + ruff-format clean, scoped mypy gate clean
  on py3.10/3.11/3.12.
@ropoctl
ropoctl force-pushed the sourcehunt-native-h264-fixes branch from 761f770 to 15bbf28 Compare April 16, 2026 21:08
@ehartford
ehartford merged commit 0f5e922 into main Apr 16, 2026
3 checks passed
@ehartford
ehartford deleted the sourcehunt-native-h264-fixes branch July 16, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants