Repository navigation
fix(server): cited assistant quotes reach providers expanded again #16389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
josephv123
wants to merge
8
commits into
pingdotgg:main
from
josephv123:fix/provider-citation-expansion
+806
−14
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f447381
fix(server): cited assistant quotes reach providers expanded again
josephv123 f38c87b
Merge remote-tracking branch 'origin/main' into fix/provider-citation…
juliusmarminge 48824b7
fix(server): reject oversized citation messages before dispatch
juliusmarminge d4f4cac
fix(server): validate queued citation messages before steering
juliusmarminge 88988d5
fix(server): expose citation validation to MCP queue tools
juliusmarminge 64f9d72
fix(server): validate citations under the thread dispatch lock
juliusmarminge 21a04c0
Merge remote-tracking branch 'origin/main' into fix/provider-citation…
juliusmarminge 233f598
test(server): adopt main's receipt replay flag and succeedSome in cit…
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { | ||
| type OrchestrationMessageContext, | ||
| PROVIDER_SEND_TURN_MAX_INPUT_CHARS, | ||
| } from "@t3tools/contracts"; | ||
| import { expandAssistantCitationsForProvider } from "@t3tools/shared/assistantCitations"; | ||
| import { projectComposerContextForProvider } from "@t3tools/shared/composerContextReferences"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Schema from "effect/Schema"; | ||
|
|
||
| class ProviderInputTooLongError extends Schema.TaggedError<ProviderInputTooLongError>()( | ||
| "ProviderInputTooLongError", | ||
| { inputLength: Schema.Number }, | ||
| ) { | ||
| override get message(): string { | ||
| const excess = this.inputLength - PROVIDER_SEND_TURN_MAX_INPUT_CHARS; | ||
| return `Message is ${excess.toLocaleString("en-US")} ${excess === 1 ? "character" : "characters"} over the ${PROVIDER_SEND_TURN_MAX_INPUT_CHARS.toLocaleString("en-US")}-character limit once assistant quotes are expanded. Shorten it or quote less.`; | ||
| } | ||
| } | ||
|
|
||
| // Project context before expanding quotes, including citations inside context records. | ||
| // The durable message keeps its clickable links. | ||
| export const providerUserMessageText = (message: { | ||
| readonly text: string; | ||
| readonly context?: OrchestrationMessageContext | undefined; | ||
| }): Effect.Effect<string, ProviderInputTooLongError> => { | ||
| const projected = projectComposerContextForProvider({ | ||
| text: message.text, | ||
| records: message.context?.records ?? [], | ||
| }); | ||
| const text = expandAssistantCitationsForProvider(projected); | ||
| return text !== projected && text.length > PROVIDER_SEND_TURN_MAX_INPUT_CHARS | ||
| ? Effect.fail(new ProviderInputTooLongError({ inputLength: text.length })) | ||
| : Effect.succeed(text); | ||
| }; | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the error text name every input that counts toward the limit.
text.lengthis the length afterprojectComposerContextForProviderandexpandAssistantCitationsForProviderboth run. The composer context envelope can therefore be the main reason a message goes over the limit. The concurrent-edit test inruntimeLayer.test.tsshows this case: a 26,000-character terminal record, combined with one short citation, is what exceeds the limit.Even then, the message tells the sender "Shorten it or quote less." A sender who removes the quote but keeps the large context is under the limit again only because the length check skips messages without citations. That is not because the cause was fixed.
The fix is to name both inputs in the message, then update the regex in
runtimeLayer.test.tsto match.Proposed wording
Based on learnings: "ensure error messages and error types accurately describe the actual failure cause."
Committable suggestion
Source: Learnings