Skip to content

Conversation

@LZL0
Copy link
Member

@LZL0 LZL0 commented Dec 13, 2025

Summary by cubic

Improves runtime performance by removing per-call regex compilation in drift detection and switching to a slot-backed State with an O(1) token buffer for content assembly. This reduces CPU time and string allocations during streaming.

  • Performance
    • Pre-compiled regex patterns across drift.py (tone, sentence split, markdown, hedging); removed repeated lowercasing via case-insensitive matches.
    • Converted State to a slot-backed class with O(1) buffered appends (append_content) and lazy flush via the content property.
    • Switched callback IDs to UUIDv7 for faster, time-ordered guardrail rule traces.

Written for commit 8df4f77. Summary will update automatically on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/l0/types.py">

<violation number="1" location="src/l0/types.py:271">
P1: Breaking API change: `content` is no longer a constructor parameter. Existing code using `State(content=&quot;...&quot;)` will fail. Consider using `__post_init__` to accept `content` as an init parameter while still using the internal buffer, or add `content: InitVar[str] = &quot;&quot;` to preserve backward compatibility.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

src/l0/types.py Outdated
Access `content` property to get the accumulated string (flushes buffer automatically).
"""

_content: str = ""
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 13, 2025

Choose a reason for hiding this comment

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

P1: Breaking API change: content is no longer a constructor parameter. Existing code using State(content="...") will fail. Consider using __post_init__ to accept content as an init parameter while still using the internal buffer, or add content: InitVar[str] = "" to preserve backward compatibility.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/l0/types.py, line 271:

<comment>Breaking API change: `content` is no longer a constructor parameter. Existing code using `State(content=&quot;...&quot;)` will fail. Consider using `__post_init__` to accept `content` as an init parameter while still using the internal buffer, or add `content: InitVar[str] = &quot;&quot;` to preserve backward compatibility.</comment>

<file context>
@@ -262,9 +262,14 @@ class BackoffStrategy(str, Enum):
+    Access `content` property to get the accumulated string (flushes buffer automatically).
+    &quot;&quot;&quot;
+
+    _content: str = &quot;&quot;
+    _content_buffer: list[str] = field(default_factory=list)
     checkpoint: str = &quot;&quot;  # Last known good slice for continuation
</file context>
Fix with Cubic

@LZL0 LZL0 merged commit 476a8c9 into master Dec 13, 2025
4 checks passed
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.

2 participants