refactor: extract callModel, unify tool handlers, add sessionCompactor#2761
Closed
dgageot wants to merge 3 commits into
Closed
refactor: extract callModel, unify tool handlers, add sessionCompactor#2761dgageot wants to merge 3 commits into
dgageot wants to merge 3 commits into
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
4365963 to
14d512d
Compare
Member
|
waiting on a rebase once the eventsink is merged |
…ndler Remove ToolHandlerFunc type and the per-batch adapter loop in processToolCalls. Built-in handlers (transfer_task, handoff, change_model, revert_model, run_skill) now match toolexec.ToolHandler directly and access events through r.toolSink, set for the duration of each processToolCalls call.
Move compactWithReason, compactIfNeeded, preCompactSourceFor, and joinPrompts into a sessionCompactor struct. The LocalRuntime holds a *sessionCompactor and delegates all compaction calls to it. This concentrates compaction reasoning (previously spread across runtime.go, loop.go, loop_steps.go, and session_compaction.go) in one place.
14d512d to
19ce805
Compare
rumpl
reviewed
May 12, 2026
| // emits a TokenUsageEvent so the UI immediately reflects the new | ||
| // context pressure. | ||
| func (c *sessionCompactor) Compact(ctx context.Context, sess *session.Session, additionalPrompt, reason string, events EventSink) { | ||
| r := c.runtime |
Member
There was a problem hiding this comment.
kinda weird for this to depend on the runtime just to run the pre-compaction hooks
rumpl
reviewed
May 12, 2026
| a := r.resolveSessionAgent(sess) | ||
|
|
||
| source := preCompactSourceFor(reason) | ||
| skip, msg, extraPrompt := r.executePreCompactHooks(ctx, sess, a, source, events) |
Member
There was a problem hiding this comment.
r.doCompact already calls executeBeforeCompactionHooks, what is the difference between the two?
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.
Three runtime refactors stacked on #2759 and #2760:
Extract callModel method — Pulls the before-hooks → transforms → LLM call → error handling → after-hooks pipeline out of
runTurninto a standalonecallModelmethod.Unify tool handler registration — Removes
ToolHandlerFunctype. Built-in handlers now matchtoolexec.ToolHandlerdirectly, eliminating the per-batch adapter loop inprocessToolCalls.sessionCompactor collaborator — Moves compaction logic (previously scattered across 4 files) into a self-contained
sessionCompactorstruct.Depends on #2759 and #2760. Pure refactor, no behaviour change.