Skip to content

fix: enforce long-term memory settlement on completion - #790

Open
kjore wants to merge 2 commits into
lsdefine:mainfrom
kjore:fix/long-term-update-completion-gate
Open

fix: enforce long-term memory settlement on completion#790
kjore wants to merge 2 commits into
lsdefine:mainfrom
kjore:fix/long-term-update-completion-gate

Conversation

@kjore

@kjore kjore commented Sep 2, 2026

Copy link
Copy Markdown

Closes #789

Summary

  • add a one-time completion gate for normal tasks reaching 15 turns
  • start long-term memory evaluation before exit when settlement has not alreadybots begun
  • prevent duplicate settlement after an explicit start_long_term_update call
  • preserve exemptions for autonomous flows and configurations where the tool is unavailable
  • align the Chinese and English threshold wording to turn >= 15
  • add regression tests for the threshold and one-time gate behavior

This forces memory evaluation, not unconditional memory modification. The evaluation may still conclude that nothing should be stored.

Behavior

  • turn < 15: exit normally
  • turn >= 15 with prior settlement: exit normally
  • turn >= 15 without prior settlement: run settlement once, then exit
  • rejected calls before turn 10 do not consume the completion gate

The gate is scoped to one task. A new user request creates a new handler and resets the gate.

Testing

  • pytest tests/test_long_term_update_gate.py -q
    • 5 passed
  • full Windows test suite
    • 278 passed, 2 skipped
    • the skipped tests require symbolic-link privileges unavailable to the current Windows account
  • python -m py_compile ga.py agentmain.py
  • git diff --check

Copilot AI lite review requested due to automatic review settings September 2, 2026 14:44

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.

🟡 Changes recommended

There are a couple of correctness/robustness issues in the updated logging flow and the new tests (determinism depends on filesystem/CWD) that should be fixed before merging.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR enforces the “15+ turns must trigger start_long_term_update on completion” requirement at runtime by adding a one-time completion gate that starts long-term memory evaluation before exiting long-running tasks (while preserving exemptions like autonomous flows and tool-unavailable configurations).

Changes:

  • Add a per-task, one-time completion gate in GenericAgentHandler.do_no_tool() that triggers long-term memory evaluation when turn >= 15 and settlement hasn’t started yet.
  • Track settlement gating state via long_term_update_pending, and prevent duplicate settlement after explicit do_start_long_term_update().
  • Align EN/CN tool schema wording to “15 or more turns”, and add regression tests for threshold + one-time gate behavior.
File summaries
File Description
ga.py Adds the turn >= 15 completion gate and refactors long-term update initiation to prevent duplicate settlement.
agentmain.py Initializes the handler’s gate based on tool availability and autonomous-flow detection.
assets/tools_schema.json Aligns English description wording to “15 or more turns”.
assets/tools_schema_cn.json Aligns Chinese description wording to “达到15轮…”.
tests/test_long_term_update_gate.py Adds regression coverage for threshold behavior and one-time gating.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ga.py
Comment thread tests/test_long_term_update_gate.py
Comment thread tests/test_long_term_update_gate.py

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.

🟡 Changes recommended

The auto-gate path inlines the long-term-update “tool result” into next_prompt instead of passing it via the normal tool_results channel, which can change prompt structure/behavior across backends and should be corrected before merging.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread ga.py
Comment on lines +531 to +532
outcome = yield from self.do_start_long_term_update({}, response)
return StepOutcome(None, next_prompt=f'{outcome.data}\n{outcome.next_prompt}')
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.

Bug: 15+ turn tasks can exit without calling start_long_term_update

2 participants