Repository navigation
fix(core): compact when a reply stops early at the output limit #58994
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ export type Outcome = Data.TaggedEnum<{ | |
| } | ||
| RecoverFull: {} | ||
| Compacted: {} | ||
| OutputLimit: { readonly needsContinuation: boolean } | ||
| OutputLimit: { readonly needsContinuation: boolean; readonly early: boolean } | ||
| }> | ||
| export const Outcome = Data.taggedEnum<Outcome>() | ||
|
|
||
|
|
@@ -277,7 +277,11 @@ export const make = Effect.gen(function* () { | |
| if (tools.interrupted && Exit.isFailure(joined)) return yield* Effect.failCause(joined.cause) | ||
| if (record.failure) return yield* new StepFailedError({ error: record.failure }) | ||
| const needsContinuation = input.prepared.request.toolChoice?.type !== "none" && record.needsContinuation | ||
| if (record.finish?.finish === "length") return Outcome.OutputLimit({ needsContinuation }) | ||
| if (record.finish?.finish === "length") { | ||
| const output = record.finish.usage?.outputTokens | ||
| const early = output !== undefined && input.model.limit.output > 0 && output < input.model.limit.output | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This compares output tokens with the catalog |
||
| return Outcome.OutputLimit({ needsContinuation, early }) | ||
| } | ||
| return Outcome.Completed({ needsContinuation }) | ||
| }), | ||
| ) | ||
|
|
||
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.
loadedwas taken before this step ran, so it doesn't include the reply that just stopped withlength. The summary leaves that reply out, and afterwards it's no longer in the model's context either: the new test ends with context[compaction, synthetic, assistant], and the partial reply only exists in the stored messages.CONTINUE_AFTER_OUTPUT_LIMITthen asks the model to carry on from output it can't see, so whatever the cut-off reply had produced is lost. Could you reload the context (prepareContext(sessionID).pipe(Effect.flatMap(context.load))) before compacting, so the cut-off reply is summarized or kept?