Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

🤖 perf: a stage opened at settlement but not due at the next turn start can stop the turn again

Open
#7,336 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript
Domain
backend, testing

Research direction

Read src/node/services/contextManagement/strategies/tokenBudget.ts and trace dueTurnStartStage and prepareTurnStartStage, then follow how settlement uses nextRequestTokens from streamManager.ts and contextBudgetCounting.ts. Add a test for a settlement that opens a stage when the next turn start’s full count is below its point; done means that turn does not stop again with another “Continue”.

Written by the indexing model from the issue text.

Description

Found from code reading during the final check of #7332, not reproduced. Related: #5223, #5286, #7331.

Problem

In Token Budget mode, a settled tool step can open a handoff or final stage that the next turn start does not see as due. Settlement then stops the turn and queues a "Continue". That turn start publishes no warning and sets no declined marker, so the next settlement can stop the turn again with another "Continue".

Why it can happen

  1. Settlement decides on the anchored next-request estimate: the provider's input count plus an estimate of the appended messages only (estimateAnchoredRequestTokensForModel, src/node/services/contextBudgetCounting.ts, passed as nextRequestTokens from streamManager.ts).
  2. The turn start decides on the full count of the built request (dueTurnStartStage and prepareTurnStartStage in src/node/services/contextManagement/strategies/tokenBudget.ts).
  3. prepareTurnStartStage sets stageDeclinedStream only when a stage is due. If the full count is below the stage point, nothing marks the stream, so settlesWithoutStage does not stop the next settlement from opening the stage again.

Trigger

The full count must run below provider usage (k < 1, where k = estimate / provider usage). Measured k today is above 1 (OpenAI about 1.3 to 1.6, Claude about 1.04 to 1.36, see #5223), so this is expected to be rare.

Scope

Main already has this path: before #7332, settlement opened stages on provider usage, which can also sit above the turn start's full count. #7332 opens stages on the anchored estimate and widens the path only by the difference between the anchored and the full counts. No fix is in #7332.

Acceptance

  • Test: a settlement opens a stage, the next turn start's full count is below the stage point, and the turn does not stop again with another "Continue".

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $525.35

Dominant language
TypeScript
Stars
2.1k
Forks
140
Avg merge
4h 57m
Merged PRs (30d)
946

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from coder/xum

All issues in coder/xum

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.