Skip to content

fix(moim): freeze turn-context timestamp at turn start to preserve prefix cache - #10734

Merged
Abhijay007 merged 3 commits into
aaif-goose:mainfrom
Abhijay007:fix/freeze-moim-timestamp-at-turn-start
Jul 29, 2026
Merged

fix(moim): freeze turn-context timestamp at turn start to preserve prefix cache#10734
Abhijay007 merged 3 commits into
aaif-goose:mainfrom
Abhijay007:fix/freeze-moim-timestamp-at-turn-start

Conversation

@Abhijay007

Copy link
Copy Markdown
Collaborator

Fixes #10706

Summary

timestamp was regenerated on every LLM call inside a turn, busting the prefix cache for OpenAI-compatible providers. Now captured once before the agent loop and passed frozen into inject_moim.

Testing

manual

@michaelneale michaelneale left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is right - this means the latest Moim gets the latest real time though doesnit it @Abhijay007 ?

@Abhijay007

Copy link
Copy Markdown
Collaborator Author

I think it is right - this means the latest Moim gets the latest real time though doesnit it @Abhijay007 ?

oh yea it gets the real time captured once at turn start when the user sends their message, the only thing removed is the mid-turn refresh between tool calls, which was cache-busting with no benefit to the model

@ccgauvin94

Copy link
Copy Markdown
Contributor

Freezing the time stamp fixes the most common cause of this, but when you cross 50% of the compaction threshold, <compaction> also appears. Could we capture compaction_info at turn start as well?

@Abhijay007

Copy link
Copy Markdown
Collaborator Author

Freezing the time stamp fixes the most common cause of this, but when you cross 50% of the compaction threshold, <compaction> also appears. Could we capture compaction_info at turn start as well?

thanks, good catch, will add that in this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 977fac29ca

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose/src/agents/agent.rs Outdated
@alexhancock

Copy link
Copy Markdown
Collaborator

@Abhijay007 please merge after you complete #10734 (comment)

@Abhijay007

Copy link
Copy Markdown
Collaborator Author

@Abhijay007 please merge after you complete #10734 (comment)

Done in 977fac2

@Abhijay007
Abhijay007 added this pull request to the merge queue Jul 29, 2026
@Abhijay007
Abhijay007 removed this pull request from the merge queue due to a manual request Jul 29, 2026
@Abhijay007
Abhijay007 enabled auto-merge July 29, 2026 13:45

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2cdab76041

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +1948 to +1950
let turn_start_compaction_info =
super::moim::compute_compaction_info(&session_config.id, &self.extension_manager)
.await;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Freeze extension context too

In sessions where a platform extension emits changing MOIM text during the same reply loop, this snapshot still does not stabilize the cached prefix: inject_moim continues to call collect_moim_parts for every provider request, and the summon extension's MOIM includes running/idle durations, so OpenAI-compatible cache-control paths still hash different bytes in the last user message after a tool loop. Snapshot the extension MOIM alongside the timestamp/compaction data, or keep it outside the cached prefix as well.

Useful? React with 👍 / 👎.

@Abhijay007
Abhijay007 added this pull request to the merge queue Jul 29, 2026
Merged via the queue into aaif-goose:main with commit 465269e Jul 29, 2026
25 checks passed
@Abhijay007
Abhijay007 deleted the fix/freeze-moim-timestamp-at-turn-start branch July 29, 2026 14:01
filipkujawa added a commit that referenced this pull request Aug 4, 2026
…x cache

OpenAI-compatible providers cache implicitly on the longest byte-stable
request prefix. #10734 froze the turn-context block within a turn, but it
still migrates to the new user message at every turn boundary,
re-prefilling the entire previous turn. Strip it at format time and
re-emit it at the end of the formatted request, merging into a trailing
user message when one exists, mirroring the Anthropic-side fix (#10030).
Covers the remaining turn-boundary half of #10706 for every provider
that builds requests through formats/openai.rs.
filipkujawa added a commit that referenced this pull request Aug 4, 2026
…x cache

OpenAI-compatible providers cache implicitly on the longest byte-stable
request prefix. #10734 froze the turn-context block within a turn, but it
still migrates to the new user message at every turn boundary,
re-prefilling the entire previous turn. Strip it at format time and
re-emit it at the end of the formatted request, merging into a trailing
user message when one exists, mirroring the Anthropic-side fix (#10030).
Covers the remaining turn-boundary half of #10706 for every provider
that builds requests through formats/openai.rs.
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.

tom: <turn-context> refreshes every LLM call within a turn, breaking prompt-prefix caching

4 participants