Skip to content

Refactor monetization to controller-based reconciliation + autoresearch#315

Closed
bussyjd wants to merge 1 commit into
codex/serviceoffer-controllerfrom
claude/prepare-issue-299-review-W3FeR
Closed

Refactor monetization to controller-based reconciliation + autoresearch#315
bussyjd wants to merge 1 commit into
codex/serviceoffer-controllerfrom
claude/prepare-issue-299-review-W3FeR

Conversation

@bussyjd
Copy link
Copy Markdown
Collaborator

@bussyjd bussyjd commented Apr 7, 2026

Summary

This PR significantly refactors the monetization system to move ServiceOffer reconciliation from a Python CLI script into a dedicated Kubernetes controller, while adding comprehensive autoresearch capabilities (coordinator, worker, publisher). The changes establish a cleaner separation of concerns: the controller handles all CRD state management and ERC-8004 registration side effects, while the Python CLI becomes a thin helper for CRUD operations and catalog publishing.

Key Changes

Monetization Architecture Refactor

  • ServiceOffer Controller (cmd/serviceoffer-controller/main.go, internal/serviceoffercontroller/): New Kubernetes controller that owns ServiceOffer reconciliation, child resource management, and ERC-8004 registration side effects
  • Simplified monetize.py: Reduced from 400+ lines of reconciliation logic to ~200 lines of CRUD helpers; controller now handles staged pipeline (ModelReady → UpstreamHealthy → PaymentGateReady → RoutePublished → Registered → Ready)
  • New RegistrationRequest CRD (internal/embed/infrastructure/base/templates/registrationrequest-crd.yaml): Isolates ERC-8004 publication from ServiceOffer, enabling cleaner async side-effect handling
  • x402 source abstraction (internal/x402/source.go, internal/x402/serviceoffer_source.go): Decouples pricing configuration from ServiceOffer CRD, supporting both static and dynamic pricing models

Autoresearch System (New)

  • Coordinator (internal/embed/skills/autoresearch-coordinator/scripts/coordinate.py): Discovers GPU workers via ERC-8004/8004scan API, probes x402 pricing, submits experiments with micropayments, replaces Ensue-based shared-memory model
  • Worker API (internal/embed/skills/autoresearch-worker/scripts/worker_api.py): Minimal HTTP service for running submitted train.py experiments, storing results, exposing x402-gatable endpoints
  • Publisher (internal/embed/skills/autoresearch/scripts/publish.py): Publishes best autoresearch results to Ollama and optionally sells via x402
  • Skills & Documentation: New SKILL.md files for autoresearch, autoresearch-coordinator, autoresearch-worker, and monetize-guide with end-to-end guides

CLI Enhancements

  • obol sell probe (cmd/obol/sell.go): New subcommand to check x402 pricing for a worker endpoint
  • obol sell http improvements: Better integration with ServiceOffer controller lifecycle
  • Flow scripts (flows/flow-*.sh): Comprehensive test flows covering stack init, inference, agent setup, selling, buying, and lifecycle management

Infrastructure & Testing

  • Dockerfiles: New containers for serviceoffer-controller, autoresearch-worker, and reth-erc8004-indexer
  • Anvil + Facilitator flow (flows/flow-10-anvil-facilitator.sh): Local test infrastructure for paid flows
  • golangci.yml: Linter configuration with sensible defaults for the project
  • Test utilities: Enhanced facilitator and anvil test helpers for payment flow testing
  • Import validation (internal/openclaw/import.go): Better model API key environment handling

Code Quality

  • Consistent error handling: Added explicit errors imports across packages
  • Type modernization: Changed map[string]interface{} to map[string]any for Go 1.18+ compatibility
  • Import organization: Alphabetical sorting and grouping improvements
  • Validation layer: New internal/network/validate.go for install option validation

Notable Implementation Details

  1. Controller-driven reconciliation: ServiceOffer conditions now managed by controller watching CRD state, eliminating polling from Python script
  2. ERC-8004 integration: RegistrationRequest CRD enables async on-chain registration without blocking ServiceOffer readiness
  3. Decentralized discovery: Autoresearch coordinator uses 8004scan API instead of shared memory, enabling true peer-to-peer worker discovery
  4. **x402 microp

https://claude.ai/code/session_016ktZi3zLxbnWrjF8cLyTjm

- Rename `copy` → `patched` in controller.go to avoid shadowing the
  built-in copy function (4 occurrences)
- Revert cosmetic whitespace changes in kubectl.go and verifier.go that
  added review noise without functional benefit
- Add ApplyOutput to kubectl.go cleanly atop the original formatting
- Remove SetRegistration/HandleWellKnown from verifier (now handled by
  serviceoffer-controller registration resources)
- Update CLAUDE.md dev constraints to mention serviceoffer-controller image

https://claude.ai/code/session_016ktZi3zLxbnWrjF8cLyTjm
@bussyjd bussyjd changed the base branch from main to feat/monetize-path April 7, 2026 10:04
@bussyjd bussyjd changed the base branch from feat/monetize-path to codex/serviceoffer-controller April 7, 2026 10:05
@bussyjd bussyjd closed this Apr 7, 2026
@OisinKyne OisinKyne deleted the claude/prepare-issue-299-review-W3FeR branch April 23, 2026 19:27
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