Skip to content

renderer: harden RenderState grapheme rebuilds#73

Draft
bvolpato wants to merge 2 commits into
manaflow-ai:mainfrom
bvolpato:fix/renderstate-unmarked-grapheme
Draft

renderer: harden RenderState grapheme rebuilds#73
bvolpato wants to merge 2 commits into
manaflow-ai:mainfrom
bvolpato:fix/renderstate-unmarked-grapheme

Conversation

@bvolpato

@bvolpato bvolpato commented Jun 4, 2026

Copy link
Copy Markdown

Summary

  • initialize RenderState grapheme slices before taking unmarked-row fast path
  • reset periodic RenderState rebuild counter after deinitialization
  • add regression coverage for false-negative source row grapheme metadata

Root cause

A source row can expose a codepoint_grapheme cell while its row-level grapheme flag is false. RenderState.update copied raw cell metadata, skipped managed-memory initialization, and left Cell.grapheme pointing into a reset row arena. Link serialization later dereferenced stale slice data and crashed.

Separately, terminal_state_frame_count never reset after reaching 100,000 frames. Long-running renderers therefore deinitialized and rebuilt RenderState every frame, increasing allocator churn and exposure to stale data.

Validation

  • zig fmt --check src/terminal/render.zig src/renderer/generic.zig
  • ReleaseFast universal GhosttyKit build through ./scripts/reload.sh --tag fix-renderstate-grapheme-crash
  • tagged cmux Debug build succeeded
  • two-commit test-first history retained

Targeted regression test was not executed locally per cmux testing policy. Drafting for manual review before approval.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Fixes a crash caused by stale grapheme slices in RenderState and stops unnecessary per-frame rebuilds in long-running sessions. We now clear grapheme slices on the unmarked-row fast path and reset the renderer’s frame counter after deinit.

  • Bug Fixes
    • In RenderState.update, zero cell grapheme slices when the source row isn’t marked to avoid dangling pointers and link serialization crashes; includes a targeted regression test.
    • In the generic renderer, reset terminal_state_frame_count to 0 after deinitializing terminal_state to prevent perpetual per-frame rebuilds once the threshold is reached.

Written for commit 3d9239e. Summary will update on new commits.

Review in cubic

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 07c55f23-8dfe-4597-ac81-3f3cfe5053b2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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.

1 participant