Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _append_tool_result(
"content": content,
}
)
session.history_dirty = True
session.mark_dirty()


def _turn_state(user_msg: Optional[Any], session: Session, memory_service: Any) -> dict:
Expand Down Expand Up @@ -155,7 +155,7 @@ def _turn_state(user_msg: Optional[Any], session: Session, memory_service: Any)
state["experience_update_start_index"] = len(session.message_history)

session.message_history.append({"role": "user", "content": user_msg})
session.history_dirty = True
session.mark_dirty()
log_agent(session.user_id, "IN", user_msg, Fore.CYAN)

if _is_gui_interaction_request(user_msg):
Expand Down Expand Up @@ -316,7 +316,7 @@ async def run_and_store(name=func_name, arguments=args, call_id=tc_id):
results = await asyncio.gather(*tasks)
for r in results:
session.message_history.append(r)
session.history_dirty = True
session.mark_dirty()

if session.pending_confirmations:
if signal_handler:
Expand Down Expand Up @@ -582,7 +582,7 @@ def _append_assistant_round(session: Session, round_result: dict) -> bool:
msg_dict["tool_calls"] = valid_tool_calls

session.message_history.append(msg_dict)
session.history_dirty = True
session.mark_dirty()
return bool(valid_tool_calls)


Expand Down Expand Up @@ -616,7 +616,7 @@ async def _finalize_or_request_more_work(
"If `validation_pytest` is missing, run at least one `pytest` command via `run_bash`."
)
session.message_history.append({"role": "user", "content": guidance})
session.history_dirty = True
session.mark_dirty()
return None

if turn_state["experience_update_active"]:
Expand All @@ -630,7 +630,7 @@ async def _finalize_or_request_more_work(
"Then provide confirmation that the experience was actually stored."
)
session.message_history.append({"role": "user", "content": guidance})
session.history_dirty = True
session.mark_dirty()
return None

if memory_service and user_msg:
Expand Down Expand Up @@ -777,7 +777,7 @@ async def resolve_confirmations(
"content": result,
}
)
session.history_dirty = True
session.mark_dirty()

# After resolving, run the agent turn again to process results
return await run_agent_turn(None, session, signal_handler=signal_handler)
Expand Down Expand Up @@ -814,7 +814,7 @@ async def deny_confirmations(session: Session, deny_all: bool = True) -> None:
"content": "Action denied by user.",
}
)
session.history_dirty = True
session.mark_dirty()


def main():
Expand Down
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ async def cancel(update: Update, context: ContextTypes.DEFAULT_TYPE):
"content": "Action denied by user.",
}
)
session.history_dirty = True
session.mark_dirty()
count = len(session.pending_confirmations)
session.pending_confirmations = []
session_manager.save(user_id)
Expand Down
4 changes: 2 additions & 2 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async def cli_signal_handler(msg: str):
"content": result
})

session.history_dirty = True
session.mark_dirty()
session_manager.save(user_id)
is_resume = True # Continue the same turn
continue
Expand Down Expand Up @@ -180,7 +180,7 @@ async def cli_signal_handler(msg: str):
"name": e.action,
"content": "Action denied by user."
})
session.history_dirty = True
session.mark_dirty()
session_manager.save(user_id)
is_resume = True
continue
Expand Down
3 changes: 3 additions & 0 deletions commit_message.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,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.
Comment on lines +1 to +3
2 changes: 1 addition & 1 deletion desktop/api_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ async def handle_command(request: web.Request) -> web.Response:
})
count = len(session.pending_confirmations)
session.pending_confirmations = []
session.history_dirty = True
session.mark_dirty()
session_manager.save(user_id)
result = f"✅ {count} pending action(s) cancelled."
else:
Expand Down
12 changes: 6 additions & 6 deletions prompt_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ async def _compact_history(session: Session, router: LLMRouter) -> None:
new_history.extend(last_messages)

session.message_history = new_history
session.history_dirty = True
session.mark_dirty()
log_agent(
session.user_id, "COMPACT", "History successfully compacted.", Fore.GREEN
)
Expand Down Expand Up @@ -397,7 +397,7 @@ def _inject_system_directive(session: Session, directive: str) -> None:
if directive not in content:
session.message_history[0]["content"] = content + "\n\n" + directive
# System prompt content changed; sanitize output may differ.
session.history_dirty = True
session.mark_dirty()


def _extract_memory_lines(results: Any, limit: int = 6) -> List[str]:
Expand Down Expand Up @@ -547,7 +547,7 @@ def _sync_basic_facts_into_system_prompt(
)
if updated != content:
session.message_history[0]["content"] = updated
session.history_dirty = True
session.mark_dirty()


def _build_memory_context(
Expand Down Expand Up @@ -874,7 +874,7 @@ def _merge_memory_context_into_system_prompt(

if session.message_history[0].get("role") != "system":
session.message_history.insert(0, get_initial_messages()[0])
session.history_dirty = True
session.mark_dirty()

base_content = str(session.message_history[0].get("content") or "")

Expand All @@ -890,7 +890,7 @@ def _merge_memory_context_into_system_prompt(
)
if merged != str(session.message_history[0].get("content") or ""):
session.message_history[0]["content"] = merged
session.history_dirty = True
session.mark_dirty()


def _normalize_single_system_message(session: Session) -> None:
Expand Down Expand Up @@ -951,7 +951,7 @@ def _normalize_single_system_message(session: Session) -> None:

if changed:
session.message_history = normalized
session.history_dirty = True
session.mark_dirty()


def _extract_tool_path(args: dict) -> str:
Expand Down