Skip to content

Refactor: Rename 'kata' to 'entity' - #33

Merged
visahak merged 6 commits into
AgentToolkit:mainfrom
visahak:refactor/rename-kata-to-entity
Jan 26, 2026
Merged

Refactor: Rename 'kata' to 'entity'#33
visahak merged 6 commits into
AgentToolkit:mainfrom
visahak:refactor/rename-kata-to-entity

Conversation

@visahak

@visahak visahak commented Jan 24, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR addresses issue #27 by renaming all references of "kata" to "entity" throughout the codebase to better align with the domain model.

Changes

  • Renamed BaseKataBackend to BaseEntityBackend.
  • Renamed MilvusKataBackend to MilvusEntityBackend.
  • Renamed FilesystemKataBackend to FilesystemEntityBackend.
  • Updated default database paths:
    • katas.milvus.db -> entities.milvus.db
    • katas.sqlite.db -> entities.sqlite.db
  • Updated configuration and loggers to use "entity" naming.
  • Updated KaizenClient and MCP server to reflect these changes.
  • Updated unit tests to match the new class names.

Breaking Changes

  • Database Names: The default database filenames have changed. Existing data stored in katas.milvus.db or katas.sqlite.db will not be loaded by the new default configuration. Users will need to manually rename their database files to entities.milvus.db / entities.sqlite.db or migrate data if they wish to preserve existing content.

Related Issue

Fixes #27

Please merge after PR#32

Summary by CodeRabbit

  • Bug Fixes

    • Improved message extraction and parsing with safer handling of string-encoded messages, non-dict items, and richer exception logging.
  • Refactoring

    • Standardized backend and logging naming across the codebase for consistency.
  • Chores

    • Updated default service endpoints, local database defaults, and minor docstrings/messages to match naming changes.
  • Tests

    • Test suite updated to reflect renamed backend references.

✏️ Tip: You can customize this high-level summary in your review settings.

@visahak
visahak requested a review from illeatmyhat January 24, 2026 01:05
@coderabbitai

coderabbitai Bot commented Jan 24, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Renames public backend types from "Kata" → "Entity", updates logger names and default DB identifiers, adjusts client/MCP references, and hardens phoenix_sync message/token extraction with defensive parsing, payload summaries, and wider token-usage fallbacks.

Changes

Cohort / File(s) Summary
Backend core
kaizen/backend/base.py
BaseKataBackendBaseEntityBackend; module logger target changed from "katas-db""entities-db"
Backend implementations
kaizen/backend/filesystem.py, kaizen/backend/milvus.py
Imports and subclass names updated (FilesystemKataBackendFilesystemEntityBackend, MilvusKataBackendMilvusEntityBackend); logger names switched to entities-db.*
Config & DB defaults
kaizen/config/milvus.py, kaizen/db/sqlite_manager.py
Default identifiers updated from katas.*entities.* (MilvusDBSettings.uri, SQLiteManager default db_path)
Frontend & MCP
kaizen/frontend/client/kaizen_client.py, kaizen/frontend/mcp/mcp_server.py
Client/backend references, NotImplementedError message, docstrings, MCP domain and logger changed from "katas""entities"
Sync parsing & resilience
kaizen/sync/phoenix_sync.py
Added _format_payload_summary; defensive parsing for string-encoded messages; skip non-dict items with debug logs; replace broad excepts with Exception logging and logger.exception; token usage extraction extended to check gen_ai.usage.*, llm.usage.*, and llm.token_count.* fallbacks
Schema docstring
kaizen/schema/conflict_resolution.py
Docstring wording updated to reference "entity backend"
Tests
tests/unit/test_client.py
Test imports and monkeypatches updated: BaseKataBackendBaseEntityBackend

Sequence Diagram(s)

sequenceDiagram
    actor Span
    participant PhoenixSync
    participant Parser as _parse_content
    participant Normalizer
    participant TokenUsage

    Span->>PhoenixSync: deliver span (inputs, outputs, gen_ai/llm fields)
    PhoenixSync->>Parser: parse string-encoded items
    Parser-->>PhoenixSync: parsed dicts or failure
    PhoenixSync->>Normalizer: normalize messages, skip non-dicts (log payload summary)
    PhoenixSync->>TokenUsage: extract tokens (check gen_ai.usage.*, llm.usage.*, llm.token_count.*)
    Normalizer-->>PhoenixSync: normalized messages
    PhoenixSync-->>Span: return extracted messages + token usage (or logger.exception on error)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • vinodmut

Poem

🐰 I hopped from Kata to Entity with glee,
I renamed classes, logs, and DB,
I parse string payloads with a careful sniff,
Skip odd crumbs and keep the logs stiff,
A rabbit hums — the sync sleeps peacefully.

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The commit message mentions 'secure logging and robust token usage extraction' changes in phoenix_sync.py that go beyond the rename scope, introducing new defensive parsing and debug logging functionality. Verify whether the logging improvements in phoenix_sync.py are intentional additions or should be separated into a different PR to maintain focus on the terminology rename.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.95% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: a codebase-wide rename of 'kata' to 'entity' terminology.
Linked Issues check ✅ Passed The PR fully addresses issue #27 by systematically renaming 'kata' to 'entity' across backend classes, configuration, loggers, and tests, aligning the codebase terminology with the issue's objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

@visahak
visahak requested a review from vinodmut January 24, 2026 01:05

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@kaizen/schema/conflict_resolution.py`:
- Line 17: The module docstring in kaizen/schema/conflict_resolution.py contains
a grammatical error: change the phrase "Produced by the LLM, to be processed by
a entity backend." to use the correct article, e.g. "Produced by the LLM, to be
processed by an entity backend." Update the module-level docstring accordingly.

In `@kaizen/sync/phoenix_sync.py`:
- Around line 163-179: The fallback for plain string output.value was
accidentally removed so when self._parse_content returns a string output_msgs
stays None; restore the fallback by setting output_msgs to a single-message list
(e.g., [{"role": "assistant", "content": parsed_output or output_val}]) inside
the else branch of the output handling block in phoenix_sync.py (where
output_msgs, attrs.get("output.value") and self._parse_content are used), so
plain text outputs populate assistant context; keep it inside the try/except and
maintain existing logging/exception behavior.
🧹 Nitpick comments (2)
kaizen/frontend/mcp/mcp_server.py (1)

78-80: Consider using json.dumps() instead of str() for non-string content.

When message["content"] is a list or dict, using str() produces Python repr format (e.g., {'key': 'value'}) rather than valid JSON. This may cause parsing issues if the stored content needs to be deserialized later.

♻️ Suggested fix
             Entity(
                 type="trajectory",
                 content=message["content"]
                 if isinstance(message["content"], str)
-                else str(message["content"]),
+                else json.dumps(message["content"]),
kaizen/backend/base.py (1)

42-49: Missing @abstractmethod decorator on search_entities.

Unlike all other methods in this ABC, search_entities lacks the @abstractmethod decorator. This means subclasses can silently inherit the base implementation (which returns None) rather than being forced to provide their own implementation.

♻️ Suggested fix
+    `@abstractmethod`
     def search_entities(
         self,
         namespace_id: str,
         query: str | None = None,
         filters: dict | None = None,
         limit: int = 10
     ) -> list[RecordedEntity]:
         pass

Comment thread kaizen/schema/conflict_resolution.py
Comment thread kaizen/sync/phoenix_sync.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@kaizen/sync/phoenix_sync.py`:
- Around line 365-368: The total_tokens lookup uses the wrong attribute key;
update the fallback chain to use attrs.get("gen_ai.usage.total_tokens") instead
of attrs.get("llm.usage.total_tokens") so it matches the pattern used for
prompt_tokens and completion_tokens (keep the existing fallback to
attrs.get("llm.token_count.total")). Locate the dict building where attrs is
read (the block creating "prompt_tokens", "completion_tokens", "total_tokens")
and replace the incorrect key to ensure consistency.
🧹 Nitpick comments (3)
kaizen/sync/phoenix_sync.py (3)

135-136: Bare except clauses silently swallow all exceptions.

These catch-all blocks hide parsing failures and make debugging difficult. Consider catching Exception explicitly and logging at debug level to aid troubleshooting without cluttering logs.

Proposed fix
-                except:
-                    pass
+                except Exception:
+                    logger.debug(f"Failed to parse input.value: {input_val[:100] if input_val else ''}")

Apply similar pattern at lines 151-152:

-                        except:
-                            pass
+                        except Exception:
+                            logger.debug(f"Failed to parse input message: {msg}")

Also applies to: 151-152


186-187: Same bare except issue in output parsing.

Apply the same pattern here for consistency and debuggability.

Proposed fix
                 except:
-                    pass
+                except Exception:
+                    logger.debug(f"Failed to parse output.value: {output_val[:100] if output_val else ''}")

And at lines 198-199:

-                        except:
-                            pass
+                        except Exception:
+                            logger.debug(f"Failed to parse output message: {msg}")

Also applies to: 198-199


520-523: Use logger.exception to capture traceback.

When logging inside an exception handler, logger.exception() automatically includes the stack trace, which aids debugging.

Proposed fix
            except Exception as e:
                error_msg = f"Error processing span {span_id}: {e}"
-               logger.error(error_msg) 
+               logger.exception(error_msg)
                errors.append(error_msg)

Comment thread kaizen/sync/phoenix_sync.py Outdated
@visahak
visahak force-pushed the refactor/rename-kata-to-entity branch from 8f5fccc to 5d77adf Compare January 26, 2026 15:38

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@kaizen/sync/phoenix_sync.py`:
- Around line 148-152: Replace the bare except/pass around calls to
self._parse_content with an explicit Exception handler that logs the error at
debug level before continuing; specifically, in the blocks where msg is a str
and you call self._parse_content (the occurrences around the existing msg
parsing and the similar block later), change the except to "except Exception as
e" and call the module/class logger (or self.logger) to debug.log the exception
and the offending msg payload so malformed payloads are visible while preserving
behavior.
- Line 522: In the except Exception as e block where logger.error(error_msg) is
called (in phoenix_sync.py), replace the error-only call with
logger.exception(error_msg) so the exception stack trace is captured; locate the
except block around the logger.error call and change the logging invocation to
logger.exception(error_msg) (no need to pass e explicitly) to preserve traceback
for triage.

Comment thread kaizen/sync/phoenix_sync.py Outdated
Comment thread kaizen/sync/phoenix_sync.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@kaizen/sync/phoenix_sync.py`:
- Around line 135-137: The debug logs currently emit full raw payloads (e.g.,
logger.debug in the except block that logs input_val and similar calls at the
other locations), risking PII leakage; update these to avoid printing raw
content by logging only the payload type and length or a short redacted preview
(e.g., show first N chars + "...") and/or gate full payload logging behind a
secure flag; locate uses of logger.debug that reference input_val or input.value
(and the similar calls around lines 148-153, 186-187, 195-199) and replace them
with a call to a small helper (e.g., redact_preview(payload) or
format_payload_summary(payload)) that returns type/length or a redacted snippet
before logging.

Comment thread kaizen/sync/phoenix_sync.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@kaizen/sync/phoenix_sync.py`:
- Around line 381-385: The current usage dict uses the `or` operator with
`attrs.get(...)` which treats valid 0 values as falsy; update the three lookups
for prompt_tokens, completion_tokens, and total_tokens to prefer the first
non-None value instead of truthy-bytes (e.g., implement a small helper like
`_first_non_none` and call it with attrs.get("gen_ai.usage.prompt_tokens"),
attrs.get("llm.token_count.prompt"), attrs.get("llm.usage.prompt_tokens") for
prompt_tokens, similarly for completion and total) so that explicit 0 is
preserved; ensure you replace the `or` chains in the usage construction with
calls to the helper or explicit None checks using `is not None`.
🧹 Nitpick comments (1)
kaizen/sync/phoenix_sync.py (1)

200-204: Remove dead code comment.

The commented #pass on line 202 is a leftover from when the fallback was disabled. It serves no purpose now and should be removed.

Proposed fix
                     else:
                          # Fallback for simple string output
                          output_msgs = [{"role": "assistant", "content": output_val}]
-                         `#pass` 
                 except Exception as e:

Comment thread kaizen/sync/phoenix_sync.py
@visahak
visahak merged commit 6cd2dc8 into AgentToolkit:main Jan 26, 2026
11 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Feb 6, 2026
@visahak
visahak deleted the refactor/rename-kata-to-entity branch February 16, 2026 20:17
@coderabbitai coderabbitai Bot mentioned this pull request Mar 5, 2026
4 tasks
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.

Terminology changes

2 participants