Skip to content

[Sprint 92] Autonomous cost reduction — q1b-only, weekly cadence, CEE-night doc pipeline #404

Description

@peter-fusek

Context

Commit 2c93428 landed the cost-reduction baseline for Sprint 92. This issue captures:

  1. What changed in the code.
  2. The handoff queries a future infra-cost-optimizer agent should run to verify and tune.
  3. The one-liner resume path when e5g / sgu become clinically active again.

Only q1b (Erika Fusekova) is currently clinically active; e5g (Peter) and sgu (Nora) are onboarded but not under treatment review.

What changed (2c93428)

  • PatientProfile.paused: bool added (non-destructive pause).
  • e5g and sgu marked paused=True in patient_context.py.
  • Scheduler gate added at scheduler.py:126 — paused patients contribute zero per-patient jobs.
  • 14 agent crons rewritten to once-per-week at CEE night (02:00-03:00 UTC, stacked at 15-min offsets).
  • document_pipeline_drain agent added (runs daily 02:00 UTC for q1b only).
  • api_document_webhook now:
    • Rejects paused patients with 202 skipped_patient_paused (no Claude spend).
    • Out-of-window uploads enqueued into pending_docs_queue agent_state; drain agent processes nightly.
    • In-window uploads (00:00-04:00 UTC by default) dispatch immediately as before.
  • AUTONOMOUS_COST_LIMIT default lowered $5 → $3.
  • PAUSED_PATIENTS env var → hot-pause without redeploy.
  • DOC_WEBHOOK_CEE_NIGHT_HOURS env var → override the immediate-dispatch window (default 0-4).

Tests: 850 pass, ruff clean.

Railway env vars to set on the oncoteam service

Var Value Why
AUTONOMOUS_COST_LIMIT 3.0 Matches the new default; lower than the $10 pressure-test value.
PAUSED_PATIENTS e5g,sgu Belt-and-suspenders with code; allows hot-unpause via env.
DOC_WEBHOOK_CEE_NIGHT_HOURS 0-4 (optional, default) Covers 01:00-05:00 Bratislava year-round.

Handoff — what the infra-cost-optimizer agent should check

1. Verify the spend drop (run 7 days post-deploy)

  • mcp__claude_ai_Oncofiles__search_conversations(tags=\"sys:agent-run\", limit=500) → sum cost:* tags per task:* tag. Expect total < $4 / week.
  • GET https://api.oncoteam.cloud/api/autonomous/cost — expect mtd_spend on pace for ≤ $15/mo.
  • mcp__claude_ai_Oncofiles__search_conversations(tags=\"sys:cost-alert\") — expect zero new alerts.

2. Check the drain queue

  • mcp__claude_ai_Oncofiles__get_agent_state(\"pending_docs_queue\") after 02:30 UTC — should be empty or very small (<3 docs).
  • If the queue regularly grows >20 docs overnight, split the drain into two cron slots (02:00 + 03:00 UTC) or add per-doc concurrency.

3. Scheduler job census

  • GET /healthscheduler.jobs count. With q1b active only, expect exactly 20 jobs (18 per-patient for q1b + 2 system).
  • Any :e5g or :sgu job IDs indicate the pause gate regressed.

4. WhatsApp reactive path

  • Send a test message to +421800223213. Expect a Haiku reply within ~6s.
  • Confirm no background WhatsApp broadcasts to paused-patient phone numbers.

Tuning knobs (for the future infra-cost-optimizer)

  • If weekly cadence is too sparse for research on q1b, bump daily_research back to every 3 days (schedule_params={\"day\": \"*/3\", \"hour\": 2}).
  • If mtd_spend exceeds $5/mo, downgrade daily_research and trial_monitor to Haiku (set model=\"light\" in agent_registry.py). Keep Sonnet only for pre_cycle_check and weekly_briefing.
  • If the drain queue regularly hits >20 entries, split into document_pipeline_drain_a (02:00 UTC) / document_pipeline_drain_b (03:00 UTC).

Resume path (non-destructive)

When e5g or sgu become active again:

  1. Via env (hot, no redeploy): set Railway PAUSED_PATIENTS=\"sgu\" (keep whichever stays paused) or remove entirely, then restart the service.
  2. Via code: flip paused=False on the profile in src/oncoteam/patient_context.py, push, Railway redeploys.

Tokens, oncofiles data, agent_state, conversation history — all preserved. No migration.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvementinfraInfrastructure, CI/CD, deploymentpriority:highHigh priority

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions