Skip to content

token cache improvements#9652

Open
pjain1 wants to merge 2 commits into
mainfrom
token_caching_improvements
Open

token cache improvements#9652
pjain1 wants to merge 2 commits into
mainfrom
token_caching_improvements

Conversation

@pjain1

@pjain1 pjain1 commented Jul 6, 2026

Copy link
Copy Markdown
Member
  1. Token based truncation of messages in steps using max_input_tokens configurable per connector.
  2. Split the analyst prompt into a session-stable systemPrompt and a per-turn contextPrompt (date, dashboard state, filters)
  3. prompt_cache_key for per session cache for openai connector.

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@nishantmonu51 nishantmonu51 added Type:Improvement Size:M Medium change: 100-499 lines labels Jul 6, 2026
@nishantmonu51

Copy link
Copy Markdown
Collaborator

@codex: review

@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: c3be0511c0

ℹ️ 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".

// Insert the context prompt just before the trailing user prompt. It is regenerated on every
// call and not stored in the session, so keeping it at the end preserves the cached prefix of
// the earlier messages.
messages = slices.Insert(messages, len(messages)-1, NewTextCompletionMessage(RoleUser, contextPrompt))

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 Keep admin AI instructions in a system message

When a project defines ai_instructions, this inserts the new contextPrompt as a user message immediately before the actual user prompt, and that prompt now contains the administrator project-wide instructions. That downgrades those instructions from the previous system prompt to user-level content that the following user message can contradict or override, so configured analyst behavior/guardrails can be ignored. Keep admin instructions in the system prompt or another higher-priority message while moving only truly dynamic dashboard context here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

handled

@nishantmonu51

Copy link
Copy Markdown
Collaborator

@codex: review again

@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: bfad59c65f

ℹ️ 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".

// Insert the context prompt just before the trailing user prompt. It is regenerated on every
// call and not stored in the session, so keeping it at the end preserves the cached prefix of
// the earlier messages.
messages = slices.Insert(messages, len(messages)-1, NewTextCompletionMessage(RoleUser, contextPrompt))

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 Preserve per-turn context during truncation

When an analyst completion runs long enough for token truncation after tool calls have been appended, this inserted context message is no longer near the tail; maybeTruncateMessages only preserves the first four messages and a suffix, so it can drop the current dashboard filters/time range/date while keeping later tool-call history. In large dashboard sessions, later iterations can therefore query or answer without the per-turn context that previously lived in the always-kept system prompt.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size:M Medium change: 100-499 lines Type:Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants