This repository was archived by the owner on May 26, 2026. It is now read-only.
feat(KR-7b): swap C2 capability mirror for kora__read_kora_capability_row MCP fetch — closes D-kr2-st2 - #15
Merged
Conversation
…_row MCP fetch — closes D-kr2-st2
Mechanical follow-on swap unlocked by K-7 (substrate `ee730853`) and
KR-7a's MCP client transport. CC#3 elected Option A (use the unified
IsoKronMCPClient) over Option B (parallel httpx fetch) since KR-7a is
shipped — one canonical MCP-call pattern across all closure swaps.
Pattern: provider.initialize() now refreshes the capability matrix
from the substrate before returning. On fetch failure (substrate
unreachable / transport down / bad response), the hand-mirrored
49-entry fallback stays in place + a WARNING is logged so dev/test
ergonomics survive substrate downtime. Operators grep
[kora.capability_matrix.fallback] in production logs to confirm the
fetch is succeeding.
capability_matrix_mirror.py:
* New populate_capability_matrix_from_mcp(mcp_client) coroutine:
- Invokes kora__read_kora_capability_row (no args; K-7 contract:
static-config tool, no actor identity needed).
- Validates the response shape: {capability_matrix: dict[str, bool]}
with defensive checks on both key and value types (Zod-strict on
the TS side, but a regression would silently break
actor_has_capability lookups — fail loudly here).
- Mutates ACTOR_CAPABILITY_MATRIX_KORA_COLUMN in place via
clear() + update(). Identity preserved so capability_check.py's
by-reference import sees fresh data without re-importing.
- Returns the count of entries written (for logging visibility).
- Raises on None mcp_client (defensive) or bad response shape;
caller decides fail-closed vs fallback.
* New CAPABILITY_MATRIX_MCP_TOOL = "kora__read_kora_capability_row"
constant — referenced by the populate function + tests.
* Module docstring rewritten: hand-mirrored data is now framed as
dev/test fallback (not "C2 interim"). Forward stability noted
for K-13's upcoming additions (substrate ships → fetch picks up;
fallback dict gets the 2-line update at next parity-test failure).
provider.initialize():
* New _refresh_capability_matrix_from_mcp() method called after the
connection starts. Two log paths:
- Happy: [kora.capability_matrix] populated from kora__read_kora_
capability_row — N entries (INFO from mirror module).
- Substrate fetch failed: [kora.capability_matrix.fallback] MCP
fetch ... failed (...); using hand-mirrored fallback (WARNING).
- MCP client unavailable (transport not started): [kora.capability_
matrix.fallback] could not reach MCP client ... (WARNING).
* Same production-test posture as KR-7's chain-emit closure: code
shape ships green; substrate-team dispatch tier un-stubs the K-7
handler; until then production falls back to hand-mirrored data
+ WARNINGs are operator-visible.
Tests:
* test_capability_matrix_mcp_fetch.py — 11 new tests:
- populate invokes the canonical tool with empty args
- populate replaces the dict in-place (identity preserved across
re-imports — forward-stability check for capability_check.py
consumers)
- Defensive errors: None mcp_client / missing capability_matrix
key / non-dict response / non-bool value / non-str key / under-
lying invocation error propagation
- provider.initialize success-path logs [kora.capability_matrix]
INFO + dict replaced
- provider.initialize substrate-down logs [kora.capability_matrix.
fallback] WARNING + fallback intact
- provider.initialize transport-unavailable logs the distinct
"could not reach MCP" fallback variant
- autouse fixture snapshots + restores the module-level dict so
parallel xdist workers and serial tests stay clean
* test_provider_end_to_end.py updated:
- _FakeMcpClient.invoke now routes by tool_name (returns a
canonical 3-entry capability_matrix for kora__read_kora_capability
_row; mock event_ids for kora__append_event).
- Test asserts the initialize-time fetch fired + replaced the dict
with the test matrix; separately asserts the 2 append_event
emits via the new append_event_calls attribute on the fake.
- New restore_capability_matrix fixture snapshots + restores the
module-level dict.
BUILD_DEVIATIONS:
* D-kr2-st2-capability-matrix-mirror moved Open → Closed with Rule-5
spec-quote, KR-7b's Option-A rationale, production-test posture,
hand-mirrored fallback retention note.
* 2 deferrals remain open (D-kr2-st3 / D-kr3-st2).
README "Operator pitfalls":
* Deferred-surface table trimmed 3 → 2 rows; D-kr2-st2 moves to
Recently-closed.
* Individual "Capability matrix is currently a Python mirror" pitfall
rewritten as "Capability matrix is now MCP-fetched at provider
initialize (KR-7b)" with the fallback semantics + operator grep
pointer.
Local gates:
* ty check — 7,337 diagnostics, zero-delta vs KR-7 baseline.
* pytest tests/plugins/memory/ — 362/362 passing (11 new KR-7b +
351 pre-KR-7b).
* Full suite via xdist (-n auto): 24,652 / 175 failed / 129 skipped.
Δ vs KR-7 (24,561/203/52err/129): +91 passed, -28 failed, -52
errors. Same tests/tools/* + tests/tui_gateway/* xdist isolation
noise as documented across prior PRs; none touch isokron.
2 deferrals still open pending CC#1 substrate buckets:
* D-kr2-st3-no-scratchpad-write-mcp-tool ← KR-8 (K-8 merged; PM dispatched)
* D-kr3-st2-no-relationlink-write-mcp-tool ← KR-9 (K-10 merged; PM dispatched)
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
KR-7b swaps the hand-mirrored C2 capability dict for an authoritative MCP fetch via
kora__read_kora_capability_rowat provider initialize. ClosesD-kr2-st2-capability-matrix-mirror.CC#3 elected Option A (use the KR-7a-wired
IsoKronMCPClient) over Option B (parallel httpx fetch path) since KR-7a is shipped — one canonical MCP-call pattern across all closure swaps. The hand-mirrored 49-entry dict stays as a dev/test fallback (parity test still guards drift); production fetches authoritatively at start.Production-test posture (same as KR-7)
K-7's
kora__read_kora_capability_rowhandler is anotImplementedHandlerstub on substrate main; substrate-team's dispatch tier (queued, task NousResearch#395) un-stubs the handler. KR-7b's code shape is sound; mock tests verify the populate machinery; production deploys wait on the dispatch tier landing. On fetch failure the hand-mirrored fallback stays in place + a[kora.capability_matrix.fallback]WARNING is logged — dev/test ergonomics survive substrate downtime; sessions still run. Operators grep[kora.capability_matrix.fallback]in production logs to confirm fetch health.What landed
plugins/memory/isokron/capability_matrix_mirror.pypopulate_capability_matrix_from_mcp(mcp_client)coroutine — invokeskora__read_kora_capability_row(no args), validates{capability_matrix: dict[str, bool]}shape (defensive checks on both keys and values), mutatesACTOR_CAPABILITY_MATRIX_KORA_COLUMNin-place viaclear()+update(). Returns the entry count. NewCAPABILITY_MATRIX_MCP_TOOLconstant. Module docstring rewritten: hand-mirrored data is now the dev/test fallback (no longer "C2 interim").plugins/memory/isokron/provider.pyinitialize()now calls new_refresh_capability_matrix_from_mcp()after starting the connection. Two log paths: INFO[kora.capability_matrix]on success; WARNING[kora.capability_matrix.fallback]on MCP-fetch or transport failure (fallback intact).tests/plugins/memory/test_capability_matrix_mcp_fetch.pytests/plugins/memory/test_provider_end_to_end.py_FakeMcpClient.invokeroutes by tool name — returns a canonical 3-entrycapability_matrixforkora__read_kora_capability_row; mockevent_idforkora__append_event. E2E asserts the initialize-time fetch fired and replaced the dict. Newrestore_capability_matrixfixture.BUILD_DEVIATIONS.mdplugins/memory/isokron/README.mdWhy hand-mirrored fallback stays
The 49-entry C2 dict at module import is now framed as the dev/test fallback rather than "C2 interim":
initialize()→ dict replaced with authoritative substrate data. K-13's upcoming additions (cap_emit_chain_event,cap_write_relationlink) flow through automatically at next provider start — no Python-side code change.actor_has_capabilitylookups still resolve. K-13 will still require a 2-line bump to the fallback for dev parity, but production picks it up automatically (the parity test against TS source catches the bump-needed signal at CI).[kora.capability_matrix.fallback]WARNING fires. Sessions keep running on (potentially stale) dev data rather than failing closed. Operators grep the tag to confirm fetch health.Test plan
11 new tests in
test_capability_matrix_mcp_fetch.py, all passing:populate_capability_matrix_from_mcp(7):kora__read_kora_capability_rowwith empty argscapability_checkconsumers)ValueErroron Nonemcp_clientRuntimeErroron missingcapability_matrixkeyRuntimeErroron non-dict responseRuntimeErroron non-bool capability value (defensive vs substrate regression)RuntimeErroron non-str capability keyprovider.initialize(3):[kora.capability_matrix] populated from kora__read_kora_capability_row — N entries+ dict replaced[kora.capability_matrix.fallback] MCP fetch ... failed (...); using hand-mirrored fallback+ fallback intact[kora.capability_matrix.fallback] could not reach MCP client (...)E2E updated (
test_provider_end_to_end.py):_FakeMcpClient.invokeroutes by tool name. Asserts the initialize-time fetch fired with the spec-pinned tool name + empty args, dict was replaced with the canonical test matrix, and the 2 append_event emits still fired separately.Gates
ty check— 7,337 diagnostics, zero-delta vs KR-7 baseline. All targeted-file diagnostics resolved.pytest tests/plugins/memory/— 362/362 passing (11 new KR-7b + 351 pre-KR-7b).-n auto): 24,652 passed / 175 failed / 129 skipped. Δ vs KR-7 (24,561 / 203 / 52err / 129): +91 passed, −28 failed, −52 errors. Sametests/tools/*+tests/tui_gateway/*xdist isolation noise; none touchplugins/memory/isokron/.Rule-6 / BUILD_DEVIATIONS / Open asks
Closed:
D-kr2-st2-capability-matrix-mirror(KR-7b).2 deferrals remain open — both unblocked at substrate; PM has dispatched the matching closure swaps:
D-kr2-st3-no-scratchpad-write-mcp-toolbd165eb2; PM dispatched)D-kr3-st2-no-relationlink-write-mcp-toolBoth swaps follow the KR-7 template — same mechanical pattern, same production-test posture. Shipping KR-8 next per PM-suggested order, then KR-9. After all 4 closures merge, the standing-by state becomes dispatch-tier-gated (substrate-team task NousResearch#395 + service-token mint for production).
🤖 Generated with Claude Code