Skip to content

feat(webhooks): outbound webhook delivery#32

Merged
RustMunkey merged 5 commits intomainfrom
feat/webhooks
Mar 14, 2026
Merged

feat(webhooks): outbound webhook delivery#32
RustMunkey merged 5 commits intomainfrom
feat/webhooks

Conversation

@RustMunkey
Copy link
Copy Markdown
Owner

@RustMunkey RustMunkey commented Mar 14, 2026

Summary by CodeRabbit

  • New Features

    • Multi-model selection with tier-based access and optional model override plus per-run system prompt.
    • Per-model billing multipliers applied to usage accounting.
    • Outbound webhooks: CRUD, test deliveries, delivery logs, and background dispatch with retries.
  • Chores

    • CI and test suite updated to include the runtime service.
    • Lint-staged configuration replaced with an environment-aware implementation.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 14, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: f3fc3ba5-7268-4350-ad3c-1b980e957b0d

📥 Commits

Reviewing files that changed from the base of the PR and between 88fbee9 and 255ee23.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (18)
  • .github/workflows/codeql.yml
  • packages/db/src/schema/pg/enums.ts
  • packages/db/src/schema/pg/index.ts
  • packages/db/src/schema/pg/nodes.ts
  • packages/db/src/schema/pg/relations.ts
  • packages/jobs/src/dispatch.ts
  • packages/webhooks/src/deliver.ts
  • packages/webhooks/src/events.ts
  • packages/webhooks/src/index.ts
  • packages/webhooks/src/sign.ts
  • services/api/package.json
  • services/api/src/index.ts
  • services/api/src/jobs/webhook.ts
  • services/api/src/routes/webhooks.ts
  • services/worker/src/worker/consumer.py
  • services/worker/src/worker/handlers/__init__.py
  • services/worker/src/worker/handlers/webhook.py
  • services/worker/src/worker/models.py

📝 Walkthrough

Walkthrough

Adds a new @maschina/model package with tiered model catalog and billing multipliers; integrates model selection into agent dispatch, extends job/daemon/runtime payloads for model and system prompt, implements runtime routing between Ollama and cloud providers with token multipliers, and introduces webhook delivery infrastructure and node DB schemas.

Changes

Cohort / File(s) Summary
Model package
packages/model/package.json, packages/model/tsconfig.json, packages/model/src/catalog.ts, packages/model/src/catalog.test.ts, packages/model/src/index.ts
New package providing MODEL_CATALOG, tier defaults, access validation, multiplier lookup, resolver, and tests.
Runtime & tests
services/runtime/src/runner.py, services/runtime/tests/test_runner_routing.py
Runtime routing by model prefix (ollama/* → local; others → Anthropic), billing multiplier computation, token accounting, and unit tests for routing/multiplier helpers.
Daemon / orchestrator
services/daemon/src/runtime/mod.rs, services/daemon/src/orchestrator/scan.rs, services/daemon/src/orchestrator/scan_compat.rs, services/daemon/src/orchestrator/analyze.rs
Expanded job/run structs to include model and system_prompt; renamed RunOutput.payload → output_payload; runtime request/endpoint updated to include plan_tier, model, system_prompt, max_tokens, timeout_secs and POST /run; SQL binding fixed to output_payload.
API layer & routes
services/api/src/routes/agents.ts, services/api/src/routes/webhooks.ts, services/api/src/index.ts, services/api/src/jobs/webhook.ts, services/api/Dockerfile, services/api/package.json
Validate/resolve model per tier, compute system prompt, persist model & systemPrompt, dispatch jobs with new fields; new webhook CRUD, test endpoint, delivery listing, Stripe inbound handling, and started webhook dispatcher on service startup; added @maschina/model dependency and Docker build ordering.
Jobs & types
packages/jobs/src/types.ts, packages/jobs/src/dispatch.ts
AgentExecuteJob and dispatchAgentRun extended with model and systemPrompt (and timeoutSecs); added dispatchWebhookJob for worker webhook dispatch subject.
Validation schema
packages/validation/src/schemas/agent.ts
RunAgentSchema gains optional model string field for model override.
Worker webhook handler & models
services/worker/src/worker/handlers/webhook.py, services/worker/src/worker/models.py, services/worker/src/worker/consumer.py, services/worker/src/worker/handlers/__init__.py
New WebhookDispatchJob model and handler implementing signed POSTs, retries/backoff, delivery state updates; consumer routes webhook_dispatch subject to handler; handlers export updated.
Webhooks package (types, signing, delivery)
packages/webhooks/src/events.ts, packages/webhooks/src/sign.ts, packages/webhooks/src/deliver.ts, packages/webhooks/src/index.ts
Typed webhook event payloads, signing utilities, delivery logic with backoff and per-attempt timeouts, and consolidated exports.
DB schema: nodes
packages/db/src/schema/pg/nodes.ts, packages/db/src/schema/pg/enums.ts, packages/db/src/schema/pg/relations.ts, packages/db/src/schema/pg/index.ts
New nodes, node_capabilities, node_heartbeats tables; new enums for node status/tier; relation mappings and index export added.
CI / tooling / scripts
.github/workflows/ci.yml, .github/workflows/codeql.yml, .lintstagedrc.json, .lintstagedrc.mjs, package.json
Added model to build/test flows; replaced JSON lint-staged with .mjs that filters existing files; added pytest runtime and other pytest scripts; CodeQL upgraded to v4 with continue-on-error.
CHANGELOG
CHANGELOG.md
Documented model routing, API/daemon/runtime changes, added tests and CI updates.
sequenceDiagram
    participant Client
    participant API
    participant Validation as ModelValidation
    participant Jobs
    participant Daemon
    participant Runtime

    Client->>API: POST /agents/run (agentId, tier, model?)
    API->>Validation: validateModelAccess(tier, model)
    alt denied
        Validation-->>API: 403 reason
        API-->>Client: 403
    else allowed
        Validation-->>API: allowed
        API->>Validation: resolveModel(tier, model)
        Validation-->>API: resolvedModel
        API->>API: systemPrompt = agent.config or default
        API->>Jobs: dispatchAgentRun(runId, model, systemPrompt, timeoutSecs, ...)
        Jobs-->>API: jobAccepted
        API-->>Client: {runId, status}
        Jobs->>Daemon: agent.execute job (model, system_prompt, plan_tier, timeout_secs, ...)
        Daemon->>Runtime: POST /run (model, system_prompt, plan_tier, max_tokens, timeout_secs, input_payload)
        alt model starts with "ollama/"
            Runtime->>Runtime: route to OllamaRunner (multiplier: 0)
        else cloud model
            Runtime->>Runtime: lazy-import Anthropic client (multiplier: 1|3|15)
        end
        Runtime-->>Daemon: RunResponse (output_payload, raw_tokens, billed_tokens)
        Daemon->>Daemon: persist output_payload (RunOutput.output_payload)
        Daemon-->>Jobs: mark complete
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🐰 I hopped through code with a tiny thump,
Catalogs, routes, and multipliers jump—
Ollama or cloud, the runtime now knows,
Webhooks delivered where the wild wind blows,
Tokens counted, prompts carried, the warren hums.

📝 Coding Plan
  • Generate coding plan for human review comments

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can enforce grammar and style rules using `languagetool`.

Configure the reviews.tools.languagetool setting to enable/disable rules and categories. Refer to the LanguageTool Community to learn more.

@RustMunkey RustMunkey merged commit 2c953f7 into main Mar 14, 2026
21 of 24 checks passed
@RustMunkey RustMunkey deleted the feat/webhooks branch March 14, 2026 03:35
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.

1 participant