Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.

feat(kora): KR-PROMOTE-EXPAND-AND-TELEMETRY-WIRES-MEGABUCKET — 2nd loop + 7 route wires + snapshot v5#190

Merged
rafe-walker merged 1 commit into
feature/phase2-upgradesfrom
feat/kora-KR-PROMOTE-EXPAND-AND-TELEMETRY-WIRES-MEGABUCKET
May 24, 2026
Merged

feat(kora): KR-PROMOTE-EXPAND-AND-TELEMETRY-WIRES-MEGABUCKET — 2nd loop + 7 route wires + snapshot v5#190
rafe-walker merged 1 commit into
feature/phase2-upgradesfrom
feat/kora-KR-PROMOTE-EXPAND-AND-TELEMETRY-WIRES-MEGABUCKET

Conversation

@rafe-walker

Copy link
Copy Markdown
Owner

Summary

CC#1 megabucket bundle (per [[feedback-batch-bigger-buckets]]): 2nd promotion loop (snapshot-expand) + 7 cost-telemetry route wires + 2 snapshot field expansions (v5 tasks). Single PR.

Per-deliverable status

ID Deliverable Status Notes
A KR-PROMOTE-SNAPSHOT-EXPAND (2nd promotion loop) ✅ shipped Observer + proposer + applier + cycle + listener. Auto-apply OFF by default per STOP-ASK §4.
B KR-EMAIL-COST-BILL (email_inbound) ✅ shipped source="email"route="email_inbound" mapping confirmed; no-op for production today (inbound is regex-based intent, not reasoning).
C KR-EMAIL-OUTBOUND-COST-BILL (email_outbound_compose) ✅ shipped New MessageSource literal + bypass-path + gateway-path mapping. Future caller that builds IncomingMessage(source="email_outbound_compose") now bills correctly.
D KR-MCP-COST-BILL (mcp_tool) ✅ shipped source="mcp"route="mcp_tool" mapping confirmed.
E KR-ALERT-INVESTIGATION-COST-BILL (alert_investigation) ✅ shipped New MessageSource literal + mapping. No alert wake-consumer exists today; mapping is wire-readiness so the future alert dispatch site bills correctly.
F KR-TOOL-LOOP-COST-BILL (tool_loop_iteration) ✅ shipped Already wired via iteration ≥2 check; new test confirms route="tool_loop_iteration" is set on iteration 2.
G KR-SCHEDULED-TASK-COST-BILL (scheduled_task) ✅ shipped New MessageSource literal + mapping. Future cron-entry reasoning calls bill correctly.
H KR-PLUGIN-AUDIT-COST-TAG ✅ verified kora_hermes_plugin/audit/plugin.py already reads route from kwargs + propagates to structured logs. No code change.
I KR-SNAPSHOT-TASKS (v5) ✅ shipped tasks.open_count + in_progress_count now populated from IsoKron Sea_Tickets provider. 30-min throttle preserves $0 LLM premise. Failed refresh keeps prior cached values.
FE TS SnapshotResponse v5 ✅ updated Comment block bumped; types were already correct for the populated shape.

Bonus bug-fix: probe_investigation was previously falling through to ROUTE_UNKNOWN in the bypass-path telemetry mapping despite the wake_consumer explicitly setting source="probe_investigation". Now bills correctly.

Sample audit entries

Loop 1 (existing — KR-PROMOTE-PHRASEBOOK-FOUNDATION; for reference)

{"emitted_at":"2026-05-23T14:00:00Z","seam":"promotion.proposed","details":{"proposal_id":"prop-abc","cluster_size":7,"sample_questions":[],"proposed_pattern":"(?i)(burn|cost|spend)","proposed_reply_template":"Burn is $XX today.","proposed_category":"cost_query","confidence":0.7,"created_at":"2026-05-23T14:00:00Z","status":"pending","review_notes":"","cluster_caller_session_ids":["D1:1","D1:2"],"haiku_synthesized":false,"synth_cost_usd":0.0},"caller_session_id":"promotion:phrasebook:prop-abc","source":"reasoning"}

Loop 2 (NEW — KR-PROMOTE-SNAPSHOT-EXPAND)

{"emitted_at":"2026-05-23T15:00:00Z","seam":"promotion.snapshot_field_added","details":{"proposal_id":"prop-xyz","cluster_size":8,"proposed_field_path":"open_tickets","proposed_collector_summary":"Collector would project the result of kora__open_tickets called with args [status=open] (6/8 observations matched this shape)","source_tool_name":"kora__open_tickets","sample_caller_session_ids":["D1JOSH:170000001","D1JOSH:170000002","D1JOSH:170000003"],"confidence":0.8,"created_at":"2026-05-23T15:00:00Z","status":"proposed","action":"proposed"},"caller_session_id":"promotion:snapshot_expand:prop-xyz","source":"reasoning"}

With KORA_PROMOTE_SNAPSHOT_EXPAND_AUTO_APPLY=true, action becomes "auto_applied" and a stub record is also written to ${KORA_HOME}/promotions/snapshot_expand/applied/<proposal_id>.json for at-rest review.

Combined daily cost ceiling

Loop Per-cycle cost Daily
Phrasebook (loop 1) ≤$0.005 (Haiku synthesis cap, ≤5 proposals × ~$0.001) ≤$0.005
Snapshot-expand (loop 2) $0 (fully lexical — no LLM call anywhere in observer/proposer/applier) $0
Combined ≤$0.005/day

Well within the [[feedback-promotion-loops-self-improving-subsystems]] ~$0.01-0.05/day target. Lots of headroom for the next 2-3 promotion loops the spec anticipates.

STOP-ASK posture

  • ✅ Sea_Ticket MCP read at 30-min cadence — implemented; substrate read is one indexed SELECT (LIMIT 200) crossing gateway-to-substrate boundary. Cadence cap keeps it cheap. No PM ask needed.
  • ✅ Deliverable H — already on by default; no gateway-default flip needed.
  • ✅ Route wires — all 7 fit the 1-3 line shape (extending two existing dicts + the MessageSource Literal). No structural changes needed.
  • ✅ Auto-apply for snapshot-expand — DEFAULT FALSE per STOP-ASK §4. v1 auto-apply path persists a stub record + emits audit; does NOT mutate state_snapshot.py. Operator-gated scaffolding still required.

Test plan

  • 19 new tests in tests/kora_cli/promote/snapshot_expand/ (observer / proposer / applier+cycle) — all pass
  • 7 new parametrized tests in test_anthropic_engine_router.py — all pass
  • 4 added parametrize cases in test_kora_hermes_plugin.py::test_source_to_kora_route — all pass
  • 5 new tests for v5 tasks cache (refresh / throttle / provider-None / provider-error) — all pass
  • Existing schema-pin tests at v4 / v2 relaxed to >= to avoid recreating the same churn on future bumps
  • Full tests/kora_cli/snapshot/ + tests/kora_cli/promote/ + tests/kora_cli/reasoning/ + tests/plugins/test_kora_hermes_plugin.py + cost-telemetry tests: 809 pass locally (only failures are missing-dev-dep imports unrelated to this PR)

🤖 Generated with Claude Code

…op + 7 route wires + snapshot v5

Deliverable A — KR-PROMOTE-SNAPSHOT-EXPAND (2nd promotion loop):
* New ``kora_cli/promote/snapshot_expand/`` (observer / proposer /
  applier / cycle). Reads ``reasoning.tool_called`` audit rows,
  clusters by tool_name, proposes new snapshot fields whose
  collector would have answered the same questions at $0 LLM cost.
* Audit seam ``promotion.snapshot_field_added`` (one row per
  proposal; ``action`` ∈ {``proposed``, ``auto_applied``}).
* Listener registers a daily cycle on the heartbeat scheduler.
* Auto-apply OFF by default per STOP-ASK §4 (schema mutation at
  runtime is fragile) — operator flips
  ``KORA_PROMOTE_SNAPSHOT_EXPAND_AUTO_APPLY=true`` once trust
  built. v1 auto-apply path persists a stub record only; it does
  NOT mutate ``state_snapshot.py``.

Deliverables B–H — cost-telemetry route wires:
* Extended ``MessageSource`` Literal in
  ``kora_cli/reasoning/engine.py`` with the four remaining
  reserved sources (``alert_investigation`` /
  ``email_outbound_compose`` / ``scheduled_task``;
  ``probe_investigation`` was already present).
* Extended ``_record_call_to_telemetry`` (bypass path) +
  ``_SOURCE_TO_ROUTE`` (gateway-route-through path) so every
  source value bills under its canonical route. Notably fixes
  ``probe_investigation`` previously falling through to
  ROUTE_UNKNOWN despite the wake_consumer setting that source.
* ``tool_loop_iteration`` (F) was already wired via the
  iteration ≥2 check; route mapping confirmation added to tests.
* Plugin audit cost tag (H): confirmed
  ``kora_hermes_plugin/audit/plugin.py`` reads ``route`` from
  kwargs + propagates to structured logs — no code change
  needed; behavior validated in the gateway route-through path.

Deliverable I — KR-SNAPSHOT-TASKS (v5):
* Bumped ``SCHEMA_VERSION`` 4 → 5.
* ``_collect_tasks`` now reads from a module-level cache
  populated by ``maybe_refresh_tasks_cache``, called from
  ``run_snapshot_cycle`` on a 30-min throttle (every 6th tick at
  the default 5-min snapshot cadence). Preserves the $0-LLM
  premise — the substrate read is one indexed SELECT but it
  crosses the gateway-to-substrate boundary so we cap frequency.
* Failed-provider refresh preserves prior cached values (so a
  flapping provider doesn't blank the panel).

FE TS type update:
* ``web/src/lib/api.ts`` ``SnapshotResponse.tasks`` comment block
  bumped to v5 with the populated-not-stub annotation. Existing
  types already cover the populated shape.

Tests:
* 19 new tests under ``tests/kora_cli/promote/snapshot_expand/``
  (observer / proposer / applier + cycle).
* 7 new tests for the route-mapping extension in
  ``test_anthropic_engine_router.py`` + 4 added parametrize
  cases in ``test_kora_hermes_plugin.py``.
* 5 new tests for the v5 tasks cache (refresh / throttle /
  provider-None / provider-error preserves-prior).
* Existing schema-pin tests at v4 / v2 relaxed to ``>=`` so
  future bumps don't recreate the same churn.

All 19 snapshot_expand tests pass; 21/21 router tests; 26/26
cost-telemetry tests. Combined daily cost ceiling for the two
promotion loops is well under $0.01/day (snapshot-expand is
fully lexical, $0; phrasebook averages ≤$0.005/day per its own
PR estimate).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rafe-walker rafe-walker deleted the feat/kora-KR-PROMOTE-EXPAND-AND-TELEMETRY-WIRES-MEGABUCKET branch May 24, 2026 06:41
@rafe-walker rafe-walker restored the feat/kora-KR-PROMOTE-EXPAND-AND-TELEMETRY-WIRES-MEGABUCKET branch May 24, 2026 06:41
@rafe-walker rafe-walker reopened this May 24, 2026
@rafe-walker rafe-walker merged commit 7cccf08 into feature/phase2-upgrades May 24, 2026
@rafe-walker rafe-walker deleted the feat/kora-KR-PROMOTE-EXPAND-AND-TELEMETRY-WIRES-MEGABUCKET branch May 24, 2026 06:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant