Skip to content

refactor: use mark_dirty() method instead of direct attribute assignment - #3

Merged
dharshan-X merged 1 commit into
mainfrom
jules/refactor-history-dirty-7680221199825390300
Jun 9, 2026
Merged

refactor: use mark_dirty() method instead of direct attribute assignment#3
dharshan-X merged 1 commit into
mainfrom
jules/refactor-history-dirty-7680221199825390300

Conversation

@dharshan-X

@dharshan-X dharshan-X commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Replaces all direct assignments to session.history_dirty = True with the encapsulated session.mark_dirty() method call to properly enforce the performance semantics documented in the Session dataclass. This improves encapsulation.


PR created automatically by Jules for task 7680221199825390300 started by @dharshan-X

Summary by CodeRabbit

  • Refactor
    • Enhanced internal session state handling mechanisms for improved code consistency and maintainability across multiple components.

Replaces all direct assignments to `session.history_dirty = True` with the encapsulated `session.mark_dirty()` method call to properly enforce the performance semantics documented in the Session dataclass.

Co-authored-by: dharshan-X <72392459+dharshan-X@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings June 9, 2026 14:16
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d1f5d536-227a-43cf-9370-b88af00f2396

📥 Commits

Reviewing files that changed from the base of the PR and between 944da3f and b2b7549.

📒 Files selected for processing (6)
  • agent.py
  • bot.py
  • cli.py
  • commit_message.txt
  • desktop/api_bridge.py
  • prompt_builder.py

Walkthrough

This PR refactors session dirty-flag tracking by replacing 18 direct assignments to session.history_dirty = True with calls to session.mark_dirty() across agent message handling, cancel handlers, and prompt-building workflows. No public APIs or logic flow changed.

Changes

Session Dirty Marking Method Refactor

Layer / File(s) Summary
Agent message history operations
agent.py
After appending tool results, user messages, resumed tool calls, assistant rounds, and resolving or denying confirmations, the agent now calls session.mark_dirty() instead of direct attribute assignment. Seven sites updated across _append_tool_result, _turn_state, _execute_unanswered_tool_calls, _append_assistant_round, _finalize_or_request_more_work, resolve_confirmations, and deny_confirmations.
Cancel and denial handlers
bot.py, cli.py, desktop/api_bridge.py
Command-line, bot, and desktop API cancel flows now call session.mark_dirty() after appending denial entries instead of direct attribute assignment. Four sites updated across /cancel handlers and tool result update paths.
Prompt building workflow operations
prompt_builder.py
Prompt construction functions (_compact_history, _inject_system_directive, _sync_basic_facts_into_system_prompt, _merge_memory_context_into_system_prompt, _normalize_single_system_message) now call session.mark_dirty() when modifying system prompt or message history. Six sites updated; all conditional logic for when to mark dirty remains unchanged.
Refactor documentation
commit_message.txt
Commit message documents the switch from direct attribute assignment to the method call for alignment with session dataclass performance semantics.

🎯 2 (Simple) | ⏱️ ~8 minutes

A refactor most neat,
mark_dirty() calls so sweet,
No logic shall shift—
Just methods—a gift! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: replacing direct attribute assignments with a method call across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jules/refactor-history-dirty-7680221199825390300

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.

Copilot AI 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.

Pull request overview

This PR refactors session mutation tracking by replacing direct session.history_dirty = True assignments with the encapsulated session.mark_dirty() call, aligning code usage with the Session dataclass’s documented performance semantics.

Changes:

  • Replaced session.history_dirty = True with session.mark_dirty() across agent, CLI, bot, desktop bridge, and prompt-building flows.
  • Ensured history mutations in prompt/system directive injection and compaction paths mark the session as dirty via the method.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
prompt_builder.py Uses session.mark_dirty() after history/system-prompt mutations (compaction, directive injection, normalization, memory merge).
desktop/api_bridge.py Uses session.mark_dirty() after cancel flow mutates tool/history state.
cli.py Uses session.mark_dirty() after appending tool/user-facing messages in signal handler flows.
bot.py Uses session.mark_dirty() after cancel flow appends denial message and clears pending confirmations.
agent.py Uses session.mark_dirty() after appending user/tool/assistant messages and tool results.
commit_message.txt Adds a commit-message artifact file (not referenced elsewhere).

Comment thread commit_message.txt
Comment on lines +1 to +3
refactor: use mark_dirty() method instead of direct attribute assignment

Replaces all direct assignments to `session.history_dirty = True` with the encapsulated `session.mark_dirty()` method call to properly enforce the performance semantics documented in the Session dataclass.
@dharshan-X
dharshan-X merged commit fb091ce into main Jun 9, 2026
2 of 3 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