Skip to content

Match session thinking and tool choice in handoff requests - #3

Merged
HugoLopes45 merged 1 commit into
mainfrom
fix/handoff-cache-reuse
Oct 6, 2026
Merged

HugoLopes45 merged 1 commit into
mainfrom
fix/handoff-cache-reuse

Conversation

@HugoLopes45

Copy link
Copy Markdown
Owner

Why

Anthropic invalidates the cached message prefix when tool_choice or thinking parameters differ from earlier requests. Handoff note requests sent toolChoice: "none" and no reasoning, while session turns send no tool choice and the session thinking level. In the recorded sessions, 170 handoff notes read only 3.96M of 20.5M prompt tokens from cache (5-14% per note); the rest was re-billed at the input or cache-write rate.

What

  • requestNote sends the session thinking level (pi.getThinkingLevel(), off maps to undefined as in Pi's agent loop) and no longer sets toolChoice.
  • handoffNote rejects a reply that contains a tool call, because tool use is no longer disabled. Rejection falls back to Pi's summary.
  • Reviewer note: thinking now uses part of maxTokens, so a note can hit the length cap more often; that also falls back to Pi's summary. Models with budget-based thinking derive the budget from maxTokens and can still miss the cache; claude-opus-5-5 uses adaptive thinking.
  • The cache gain is estimated from session logs, not measured after the change.

Checks

  • npm run check passes (91 tests). Both new tests failed before the fix for the intended reason.
  • User-visible changes have an entry under ## Unreleased in CHANGELOG.md.
  • The README matches the new behavior.

Anthropic invalidates the cached message prefix when tool_choice or thinking parameters differ from the conversation's requests. Handoff notes sent toolChoice "none" without reasoning, so in the recorded sessions they read only 5-14% of their prompt from cache (3.96M of 20.5M tokens over 170 notes). A reply that calls a tool is now rejected, since tool use is no longer disabled.
@HugoLopes45 HugoLopes45 self-assigned this Oct 6, 2026
@HugoLopes45
HugoLopes45 merged commit c29ea1c into main Oct 6, 2026
2 checks passed
@HugoLopes45
HugoLopes45 deleted the fix/handoff-cache-reuse branch October 6, 2026 09:36
HugoLopes45 added a commit that referenced this pull request Oct 6, 2026
…security policy (#5)

Every push to main ran the npm publication step. The merge of #3 tried
to publish 0.2.0 and failed only because no trusted publisher exists
yet. Merges now only prepare a version. Publication needs an explicit
v* tag on main, successful CI on that commit, and owner approval of the
npm environment. An existing npm version must come from the same commit.
CI validates version changes and lockfile metadata, and runs weekly and
against the latest Pi packages.

The repository is public but had no contribution guide, security policy
or issue template, so reports could leak session content in public
issues.
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.

1 participant