Repository navigation
fix(llm): fencing a long text gives other requests their turn - #390
Merged
Merged
Conversation
The fence neutralization has an asynchronous form that does the same work in slices and lets the event loop run between them; the result is the same string. The tool handlers, whose texts can be long, use it. A reserved tag name that starts with '/' or a blank is refused, like one that contains '<'.
…edit steps A slice is 100,000 units. Every call of an asynchronous fence builder is awaited, a tool handler imports no synchronous builder under any name, and the application of edits takes its turns: each has a test.
…does-not-hold-the-process # Conflicts: # docs/UPSTREAM_COMPATIBILITY_LEDGER.md
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
Fencing a long text no longer holds the API process.
neutralizeFenceAsyncdoes the same work asneutralizeFencein slices of at most 100,000 units and gives the event loop a turn between slices; the output is byte for byte the same.What changed
promptFence.ts: one shared core (fast reject, matcher loop, edit application) driven in one go byneutralizeFenceand in slices byneutralizeFenceAsync;fencedAsync; a reserved name whose fold starts with/or a blank is now refused like one that contains<.contextBuilders.ts:spotlightAsync,spotlightWorkflowAsync. The tool handlers (document reads, search and page results, delegate results, live Word text, workflow bodies) use them.Why
Fencing costs in proportion to the text, and a document read can hand the model up to 16 MiB of it. The work on a long text is now split into slices so that other requests keep advancing while it runs. Nothing is cut or rejected: the model receives the same text as before.
Testing
Differential tests (existing corpora plus tokens, surrogate pairs and multi-unit folds placed on slice boundaries, with small and real slice sizes), turn-count tests for the scan and for the application of edits, precondition tests with an exhaustive code-space check, read-path tests through the tool handler (document and workflow reads), the guard tests with samples. Mutants of each rule fail the matching test. Focused set: 2905 passed; build and test typecheck clean.
Measured on a shared, loaded host with 16 MiB inputs through the real builder: the longest stretch without a turn of the event loop is 3 to 7 ms for ordinary text and typically 20 to 65 ms for the slowest texts, with single stretches of 100 to 140 ms seen on the loaded host (before: one stretch of 1.3 to 2.9 s). Total time is near the synchronous form. A 100-character text costs about 1.5 µs more per call when it contains
<and about the same when it does not.Not changed here: the caller's first use of a very large result and its serialization are still done in one go (up to about 0.3 s for a 16 to 21 MB result, as before), and a call whose request has ended runs to its end, now without holding the process.
Deploy notes
No migration, no setting. What the model receives does not change.