Repository navigation
Preserve entry timestamps on compaction and branch-summary replay messages - #764
Open
baixinghao wants to merge 1 commit into
Open
baixinghao wants to merge 1 commit into
baixinghao wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #747.
SessionState.from_entriesbuilds a syntheticUserMessageforcompactionandbranch_summaryentries without passingtimestamp=, soUserMessage'sdefault_factory=current_timestamp_msfills in wall-clock "now" at replay time instead of the entry's historicalentry.timestamp.This breaks
_last_applicable_provider_usage(src/tau_coding/context_window.py), which anchors token accounting on the latest assistant response's provider-reported usage but rejects any usage older than a later message. Because the replayed summary message's timestamp is always "now", every assistant usage after a compaction fails the ordering check and context accounting falls back to the crude 4-chars-per-token estimate for the rest of a compacted-and-reloaded session.Fix
Pass
timestamp=round(entry.timestamp * 1000)at both sites, mirroring thecustom_messagefix from #710:_apply_compaction'ssummary_rowbranch_summarycase inSessionState.from_entriesVerification
Reproduced the issue's script on this branch:
UserMessage timestamp= 1791756578906(wall clock),estimate_context_usagereturneduses_provider_usage=False, provider_tokens=0.UserMessage timestamp= 1700000010000(entry time),uses_provider_usage=True, provider_tokens=999.Added
test_compaction_and_branch_summary_messages_keep_entry_timestampscovering both the compaction summary row and the branch-summary row.uv run pytest tests/test_session.py— 42 passed.uv run ruff check/ruff format --check/mypyon the touched files — clean.Note: this Windows environment has ~40 pre-existing test failures on a clean checkout (TUI layout, updater, file-drop path handling, etc.). I diffed the failure list before/after this change: identical, so the change introduces no regressions.