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 intoMay 24, 2026
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
email_inbound)source="email"→route="email_inbound"mapping confirmed; no-op for production today (inbound is regex-based intent, not reasoning).email_outbound_compose)MessageSourceliteral + bypass-path + gateway-path mapping. Future caller that buildsIncomingMessage(source="email_outbound_compose")now bills correctly.mcp_tool)source="mcp"→route="mcp_tool"mapping confirmed.alert_investigation)MessageSourceliteral + mapping. No alert wake-consumer exists today; mapping is wire-readiness so the future alert dispatch site bills correctly.tool_loop_iteration)route="tool_loop_iteration"is set on iteration 2.scheduled_task)MessageSourceliteral + mapping. Future cron-entry reasoning calls bill correctly.kora_hermes_plugin/audit/plugin.pyalready readsroutefrom kwargs + propagates to structured logs. No code change.tasks.open_count+in_progress_countnow populated from IsoKron Sea_Tickets provider. 30-min throttle preserves $0 LLM premise. Failed refresh keeps prior cached values.Bonus bug-fix:
probe_investigationwas previously falling through toROUTE_UNKNOWNin the bypass-path telemetry mapping despite the wake_consumer explicitly settingsource="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,actionbecomes"auto_applied"and a stub record is also written to${KORA_HOME}/promotions/snapshot_expand/applied/<proposal_id>.jsonfor at-rest review.Combined daily cost ceiling
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
Test plan
tests/kora_cli/promote/snapshot_expand/(observer / proposer / applier+cycle) — all passtest_anthropic_engine_router.py— all passtest_kora_hermes_plugin.py::test_source_to_kora_route— all pass>=to avoid recreating the same churn on future bumpstests/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