Skip to content

fix(trajectory): detect incomplete scratchpad with ordered tag depth - #11244

Closed
wangzhe19991 wants to merge 1 commit into
NousResearch:mainfrom
wangzhe19991:fix/trajectory-scratchpad-stack
Closed

fix(trajectory): detect incomplete scratchpad with ordered tag depth#11244
wangzhe19991 wants to merge 1 commit into
NousResearch:mainfrom
wangzhe19991:fix/trajectory-scratchpad-stack

Conversation

@wangzhe19991

Copy link
Copy Markdown

Summary

Replace the substring-based has_incomplete_scratchpad check with a left-to-right depth counter over <REASONING_SCRATCHPAD> / </REASONING_SCRATCHPAD> tokens. This prevents a later unclosed block from being misclassified as "complete" when an earlier closing tag exists elsewhere in the same string.

Related: #11194 (same symptom class: false detection around incomplete scratchpads).

Changes

  • agent/trajectory.py: ordered open/close matching; ignore orphan closing tags when depth is zero.
  • tests/agent/test_trajectory_scratchpad.py: regression coverage for paired blocks, a second unclosed block after a closed pair, and orphan-close + open tail cases.

Test plan

pytest tests/agent/test_trajectory_scratchpad.py -q -o addopts=

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Apr 25, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #11743 (ignore quoted scratchpad tags) and #11188/#11663 (same symptom class). This PR takes a depth-counter approach vs #11743's strip-before-check approach — maintainers should pick one.

@teknium1 teknium1 closed this Jun 21, 2026
cphowiehuang added a commit to elmtree-askmo/hermes-agent that referenced this pull request Jul 6, 2026
…orkaround (semconv says output includes reasoning; revert when fixed)
cphowiehuang added a commit to elmtree-askmo/hermes-agent that referenced this pull request Jul 6, 2026
…int buckets); document Langfuse NousResearch#11244 status + aggregate key-name semantics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants