Repository navigation
Studio: stop a reset dropping the task when the user types short prompts - #9379
Conversation
carried_forward_items only accepted a user turn of 80 characters or more, on the reasoning that someone who typed a paragraph wrote an instruction. A real chat does not clear that bar. Measured on a live session building a game: "Create a Flappy Bird game in HTML" is 33 characters, "Add music to the game" is 21, "Continue work" is 13. All three failed the floor, so all three compactions carried an EMPTY block and the statement of what was being built was evicted with everything else. The budget was never the constraint: 473 tokens were free and nothing was eligible to spend them on. The floor is now a preference rather than a filter. The first pass is unchanged, so a thread that has a paragraph behaves exactly as before. Only when that pass comes back empty does a second walk run without the floor. is_substantive still applies _CONTINUATIONS, which is what actually keeps "ok" and "continue" out of the system turn; the length check was a second guess at the same question, and an empty block is not the safer answer, it is the one where the model is told the conversation was compacted and handed none of it. The no-floor pass also reserves the oldest qualifying turn before walking newest-first. Selection is newest-first so a late change of direction wins, but in a short-prompt thread that alone would spend all eight slots on the increments nearest the end and evict the opening statement of the task, which is the loss this pass exists to prevent. Items are now ordered by transcript position rather than by selection order, since with a reserved item the two are no longer the same and reversing put the oldest turn last, inverting the supersession the header promises.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d3d9a1fd0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if item in seen: | ||
| # Users restate a standing rule, and each copy used to take a slot out of | ||
| # eight: one rule repeated eight times crowded out the user's other rule. | ||
| # Checked before the cost is charged, so a repeat cannot exhaust the budget. | ||
| continue |
There was a problem hiding this comment.
Keep the newest copy of a reserved repeated instruction
In the all-short fallback, reserve_oldest processes the oldest qualifying turn before the newest-first walk, so this duplicate check retains that oldest position and discards a later restatement. For example, Use metric units, then Use imperial units, then Use metric units renders only the first metric entry followed by imperial; the block's stated later-wins rule therefore makes imperial appear current even though the user most recently restored metric. Deduplicate while preserving the newest occurrence's transcript position.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and it inverts the one rule the block states about itself.
reserve_oldest walks the oldest qualifying turn before the newest-first pass, so the dedupe kept that oldest position and dropped the restatement. Your example reproduces exactly: Use metric units, Use imperial units, Use metric units rendered as metric then imperial, and since the header says a later line supersedes an earlier one, it told the model imperial was current at the moment the user had just restored metric.
Changed seen from a set to item -> index into picked, so a repeat updates the stored position when it is newer instead of being discarded. Cost is still charged once per unique item, so a repeat still cannot exhaust the budget. In the plain newest-first walk the first sighting is already the newest, so nothing moves there and the dedupe's original purpose is unchanged: one rule restated five times still takes one slot out of eight.
Both are covered now, the three-turn metric/imperial case asserting ["Use imperial units", "Use metric units"], and a five-repeat case asserting a single slot.
… block The all-short fallback reserves the oldest qualifying turn and walks it before the newest-first pass, so the dedupe retained that oldest position and dropped the later restatement. "Use metric units", then "Use imperial units", then "Use metric units" therefore rendered as metric followed by imperial. The block's header states that a later line supersedes an earlier one, so it told the model imperial was current at the moment the user had just restored metric: the opposite of what happened. The surviving copy now keeps the newest position. The plain newest-first walk already sees the newest copy first, so nothing moves there and the dedupe's original purpose is unchanged: one rule restated many times still takes one slot out of eight rather than crowding out the user's other rules.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9dc6b43c8f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if reserve_oldest: | ||
| first = next((i for i in range(len(groups)) if _item(i)), None) | ||
| if first is not None: | ||
| order = [first] + [i for i in order if i != first] |
There was a problem hiding this comment.
Keep the latest correction when reserving the oldest turn
When the cap can retain only one instruction—such as UNSLOTH_CHECKPOINT_MAX_ITEMS=1, or a token budget that fits the opening prompt but no second item—placing the oldest turn first exhausts the cap before the newest-first walk begins. For example, Build a Flappy Bird game, followed by Actually build Tetris instead, carries only the obsolete Flappy Bird request, so the compacted context loses the user's latest direction; reserve the opening task without allowing it to displace the newest qualifying turn under tight caps.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right, and it is worse than losing an item: the block asserts the opposite of the user's latest direction.
order = [oldest] + rest meant the reserved turn consumed the cap before the newest-first walk ran at all. Your example reproduces at MAX_ITEMS=1, and equally on a token budget with room for the opening prompt and nothing after it.
The opening task is now slotted in behind the newest qualifying turn instead of ahead of everything. Room for two keeps both, rendered oldest first as before; room for one keeps the correction. The reason reserve_oldest exists is untouched, and I added a test for it: a run of short increments still keeps the statement of the task itself, and now keeps the newest increment alongside it rather than only one of the two.
Tests assert ["Actually build Tetris instead"] at max_items=1 and the ordered pair at 2.
Placing the oldest qualifying turn first exhausted a tight cap before the
newest-first walk began. At MAX_ITEMS=1, or a token budget with room for the
opening prompt and nothing else, "Build a Flappy Bird game" followed by
"Actually build Tetris instead" carried only the abandoned request, so the
block stated the opposite of the user's latest direction.
The opening task is now slotted in behind the newest qualifying turn rather
than ahead of everything. With room for two, both survive and render oldest
first as before. With room for one, the correction wins.
The reason reserve_oldest exists is unchanged and covered: a run of short
increments ("add music", "now the score", "fix the pipes") still keeps the
statement of the task itself, and now keeps the newest increment alongside it.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ddef39234e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if items: | ||
| return items |
There was a problem hiding this comment.
Keep short corrections when long items exist
When the evicted history contains any qualifying 80+ character instruction, this early return prevents every shorter turn from reaching the fallback. For example, after a long “Build a Flappy Bird game…” request and a later “Actually make it Tetris” correction have both been evicted, the checkpoint carries only the obsolete Flappy Bird request. This loses the user's latest direction precisely when a short correction follows a detailed task statement, so short eligible turns need to remain candidates even when the first pass found a long item.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, and this is the same failure as the tight-cap one a round earlier, reached by a different route: the user's latest direction lost because an EARLIER turn happened to be wordy.
The floor is gone rather than reordered. One walk now, no length floor. is_substantive still applies _CONTINUATIONS, which is what actually keeps "ok" and "continue" out of the system turn, so the floor was only ever a second guess at the same question.
The cost is real and I have made the suite state it instead of hiding it. test_a_long_instruction_still_wins_over_a_short_one asserted that a passing remark alongside a paragraph is NOT promoted; it now asserts the opposite, because nothing structural separates "fix it" from "Actually make it Tetris" and you cannot keep one without the other. The trade favours keeping both: a wasted slot out of eight in a block that already labels itself lossy, against losing the user's direction outright.
Two new tests: the long-task-plus-short-correction case asserting the correction reads last, and a nudge case confirming filler is still excluded without the floor.
The 80-character floor ran as a first pass, with the no-floor walk taken only when it came back empty. That was worse than useless in the case that matters most: a long "Build a Flappy Bird game ..." followed by a short "Actually make it Tetris" clears the floor on the first turn alone, so the fallback never ran and the block carried only the abandoned request. The user's latest direction was dropped precisely because an earlier turn happened to be wordy. One walk now, with no floor. `is_substantive` still applies `_CONTINUATIONS`, which is what actually keeps "ok" and "continue" out of the system turn; the floor was only ever a second guess at the same question. The cost is real and is now asserted rather than hidden: a passing remark like "fix it" reaches the block where the floored pass excluded it. Nothing structural separates it from "Actually make it Tetris", so the two cannot be told apart. The trade favours keeping both, since a wasted slot out of eight in a block that already labels itself lossy beats losing the user's direction.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd198f2a62
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| newest = next((index for index in rest if _item(index)), None) | ||
| if newest is None: | ||
| order = [oldest] + rest | ||
| else: | ||
| at = rest.index(newest) + 1 | ||
| order = rest[:at] + [oldest] + rest[at:] |
There was a problem hiding this comment.
Reserve the oldest only after the newest item that fits
When the latest substantive turn exceeds max_tokens, this treats it as the newest candidate even though the selection loop will skip it, then places the reserved oldest turn ahead of every usable recent turn. If the remaining budget fits either the opening task or a later correction but not both, the opening task consumes it and the correction is lost—for example, an opening “Build Flappy Bird,” a later “Actually build Tetris,” and a final oversized pasted request carries only Flappy Bird. The new slotting fix therefore still reproduces the tight-budget stale-direction failure when the nominal newest item is oversized; choose the newest candidate that can actually fit before inserting the reservation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right, and I reproduced it. Fixed in 9fc68db.
The reservation picked the newest turn that QUALIFIES, not the newest one that can actually be taken:
newest = next((index for index in rest if _item(index)), None)
_item() only checks is_substantive plus non-empty text, never cost. The walk at checkpoint.py:206 skips an over-cap turn with a bare continue and spends nothing, so slotting the oldest behind an oversized newest turn put it ahead of every usable recent turn. It then took the whole budget and the correction did not fit.
Reproduced on a 2048-token context, where the production formula min(1024, int(prompt_budget(ctx, max_tokens) * MAX_FRACTION)) gives a 153-token cap: an opening Flappy Bird request (84 tok), an Actually build Tetris correction (82 tok) and a pasted traceback (269 tok) carried only Flappy Bird. Your example, at the cap a real small model hands this selection.
The fix adds a _takeable() predicate, cost <= max_tokens, and reserves behind the newest takeable turn instead. Comparing against the whole cap is the right bound because the walk starts at spent = 0, so that is exactly the test the first item in the order will face.
Regression test is test_an_oversized_newest_turn_does_not_hand_the_budget_to_the_opening_task. It fails on the parent commit with the Flappy Bird text and passes after. test_checkpoint_compaction.py: 76 passed.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9fc68dbeee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| at = rest.index(newest) + 1 | ||
| order = rest[:at] + [oldest] + rest[at:] |
There was a problem hiding this comment.
Do not reserve a stale opener ahead of newer corrections
When the newest evicted turn is merely an increment, inserting the oldest turn immediately after it lets that opener displace every intermediate correction. For example, with max_items=2, Build Flappy Bird, then Actually build Tetris instead, then Add music produces ['Build Flappy Bird', 'Add music'], so the checkpoint applies the increment to the abandoned game. This is a remaining case beyond the fixed max_items=1 scenario: under the default cap, the same loss occurs after seven later increments, so the reservation must not outrank all newer turns that establish the current task.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed on merged main, and it is not limited to a small cap. Running carried_forward_items directly:
max_items=2, [Build Flappy Bird, Actually build Tetris instead, Add music]
-> ['Build Flappy Bird', 'Add music']
max_items=8 (the default), [Build Flappy Bird, Actually build Tetris instead, Add feature 1..7]
-> ['Build Flappy Bird', 'Add feature 1' ... 'Add feature 7']
So the block states the abandoned task and then applies seven increments to it, which is the failure the reservation was added to prevent, inverted. This PR is already merged, so it is going out as a follow-up PR rather than more commits here, and I will link it back to this thread.
There was a problem hiding this comment.
Follow-up PR: #9424
The rule it lands on is that the opening turn is reserved together with the turn that follows it, both or neither, so the block can never show an opening request without what the user said next about it. Verified independently against the two repro cases above:
max_items=2, three turns -> ['Actually build Tetris instead', 'Add music']
max_items=8, nine turns -> ['Build Flappy Bird', 'Actually build Tetris instead', 'Add feature 2' ... 'Add feature 7']
and the case the reservation exists for is unchanged: a task statement followed by 19 increments at max_items=8 still keeps the task statement. max_items=1 also behaves exactly as it does today.
The bug, from a live session
Building a game in Studio at a 5,248-token context. Three compactions in six turns, all correctly
checkpoint: true, andcarried_forward_chars: 0on every one of them:carried_forward_itemsrequiresis_substantive, which requires 80 characters. Every user turn in a real chat is shorter than that:So at the first reset the statement of what was being built was evicted and carried nowhere, and that reset recalled nothing either. The model went into the next turn holding the system prompt and "Add music to the game". This is the exact loss the block exists to prevent.
The budget was never the constraint. 473 tokens were free and nothing was eligible to spend them on.
The change
The floor becomes a preference instead of a filter. The first pass is untouched, so any thread that does contain a paragraph behaves exactly as before and a passing remark alongside it is still not promoted. Only when that pass returns empty does a second walk run with the floor dropped.
is_substantivestill applies_CONTINUATIONSin both passes, and that list is what actually keeps "ok", "continue" and "thanks" out of the system turn. The length check was a second guess at the same question, and an empty block is not the safer answer: it is the one where the model is told the conversation was compacted and then handed none of it.The no-floor pass also reserves the oldest qualifying turn before walking newest-first. Selection is newest-first so a late change of direction wins, but in a short-prompt thread that alone spends all eight slots on the increments nearest the end ("add music", "now the score", "fix the pipes") and evicts the opening statement of the task, which is the loss the pass exists to stop. Because a reserved item breaks the assumption that selection order is the reverse of transcript order, items are now ordered by position rather than by
reversed(), which had put the oldest turn last and inverted the supersession the header promises.A reversed decision, stated plainly
test_an_instruction_shorter_than_the_substantive_floor_is_not_carriedasserted the old behaviour and called it a deliberate bound, priced as dropping "always answer in French". This PR reverses that decision, and the test is rewritten rather than deleted. The evidence above is why: the price is not an occasional terse rule, it is the task statement of an ordinary coding session.Known limitation, deliberately not fixed
"Continue work" is still carried.
_CONTINUATIONSholds the bare "continue"; the two-word forms are not in it, andis_thin_querydoes not call them thin either. Teaching either helper to recognise them means guessing at phrasing, and the same guess would have to reject "fix it" and "keep the tests green" to be worth anything. One wasted slot out of eight is the cheaper error, and it is recorded in the test.Tests
Four cases, of which two fail against
main:The other two pin what must not change: a thread with a paragraph is unaffected, and a thread of pure filler still produces no block.
test_checkpoint_compaction,test_context_overflow_truncation,test_conversation_archive,test_conversation_recall_injection,test_llama_cpp_context_fit: 390 passed.