Skip to content

[pull] main from danny-avila:main#67

Merged
pull[bot] merged 1 commit intoinnFactory:mainfrom
danny-avila:main
Apr 25, 2026
Merged

[pull] main from danny-avila:main#67
pull[bot] merged 1 commit intoinnFactory:mainfrom
danny-avila:main

Conversation

@pull
Copy link
Copy Markdown

@pull pull Bot commented Apr 25, 2026

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

* fix: tolerate trailing tool_use without a thinking block (#115)

When Anthropic thinking is enabled and Claude issues a tool call without
emitting a thinking block first, the pruner saw `[AI tool_use, Tool]` at
the tail and walked back searching for a thinking block. With none to
find, it threw "The payload is malformed. There is a thinking sequence
but no AI messages with thinking blocks" — permanently breaking any
conversation that crossed the context limit on that turn.

Anthropic does not require a thinking block before every tool call, so
the absence of one is valid. Broaden the false-start guard to clear
thinkingEndIndex whenever the loop exits the trailing AI/tool sequence
without having found a thinking block, instead of only on the message
immediately before the tail.

* test: cover multi-hop and createPruneMessages cases for #115

Two additional cases requested in PR review:
- Multi-hop tail [AI(tool_use), Tool, AI(tool_use), Tool] with no
  thinking blocks anywhere — locks down the guard for chained tool
  calls, a common Anthropic pattern.
- Carry-over scenario through createPruneMessages: a first call
  establishes runThinkingStartIndex from a thinking turn, and a
  second call extends the conversation with a no-thinking tail. This
  exercises the production entry point and verifies the new guard
  interacts correctly with the closed-over thinking-index state.

* test: verify pruner output flows correctly through ensureThinkingBlockInMessages

Models the full Graph.ts pipeline (pruner → ensureThinkingBlockInMessages)
with the issue #115 tail. Confirms the two functions handle complementary
concerns: the pruner just stops throwing, and ensureThinkingBlockInMessages
folds the orphan AI(tool_use)+Tool into a [Previous agent context]
HumanMessage. The outgoing API payload contains no AI tool_use without a
thinking block, so Anthropic's signature requirement is satisfied.

* test: address PR review of #115 follow-ups

- Drop the redundant double-call in the multi-hop test; calling the
  pure function once and asserting on the result is sufficient (a throw
  fails the test anyway).

- Tighten the carry-over test so the first call actually triggers
  pruning. Previously maxTokens=1000 against a 12-token conversation
  took the early-return path, leaving runThinkingStartIndex at -1 — the
  second call was indistinguishable from a fresh call. Now the first
  call's Human is large enough to be pruned while the AI(thinking)
  message survives, so runThinkingStartIndex is set to the AI's index.
  The second call's Tool is sized so AI(tool_use) survives and the
  carry-over thinking block actually gets reattached, which the new
  assertion verifies.

* test: fix vacuous ensureThinkingBlockInMessages integration assertion

The prior test used Tool('f'×8000) against maxContextTokens: 200, which
sent every message to prunedMemory. ensureThinkingBlockInMessages then
received an empty array, the assertion loop iterated zero times, and the
test passed without checking anything — pure false-confidence coverage.

Tune Tool size to 100 chars and budget to 300 so the full
[Human, AI(tool_use), Tool] tail survives pruning. Replace the
filter-and-skip loop with concrete assertions: context.length === 3
post-prune, finalMessages.length === 2 post-fold, both finalMessages are
HumanMessage instances, the folded message contains the
'[Previous agent context]' marker, and no AI(tool_use) survives in the
outgoing payload.
@pull pull Bot locked and limited conversation to collaborators Apr 25, 2026
@pull pull Bot added the ⤵️ pull label Apr 25, 2026
@pull pull Bot merged commit 1f72807 into innFactory:main Apr 25, 2026
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant