Repository navigation
perf(subagents): slim and rate-limit subagent frames sent to the browser #444
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
base: main
Are you sure you want to change the base?
Changes from all commits
08dcd5a
3df136f
3aa94a0
cb9d706
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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { applyMessageDelta, isDeltaUpdate, withStreamedArguments } from "./messa | |
| import { invalidateModelsCache } from "./models-cache"; | ||
| import { RpcCommandError, RpcCommandTimeoutError, RpcProcess, type RpcFrame } from "./omp/rpc-process"; | ||
| import type { RpcTransport } from "./omp/rpc-transport"; | ||
| import { SubagentStreamLimiter } from "./subagent-stream"; | ||
| import { cacheSessionPath } from "./session-reader"; | ||
| import { allowFileRoot } from "./file-access"; | ||
| import { loadWebServerSettings } from "./web-settings"; | ||
|
|
@@ -482,6 +483,10 @@ export class AgentSessionWrapper { | |
| * the same conversation moving to a sibling file, not a session switch. */ | ||
| private sessionMovePending = false; | ||
| private unsubscribeFrames: (() => void) | null = null; | ||
| /** Slims and rate-limits subagent frames before they reach any tab (lib/subagent-stream.ts). */ | ||
| private readonly subagentStream = new SubagentStreamLimiter((frame) => { | ||
| if (this._alive) this.emit(frame); | ||
| }); | ||
|
Comment on lines
+487
to
+489
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.
|
||
| private readonly detectNotification = createNotificationDetector(); | ||
| /** Agent activity since the last `session_settled`: background work may still run after the turn ended. */ | ||
| private unsettled = false; | ||
|
|
@@ -1279,6 +1284,8 @@ export class AgentSessionWrapper { | |
| if (event.isTerminal !== false) { | ||
| // A server dialog belongs to a tool call of this run; nobody can answer it after the run. | ||
| this.dropServerUiRequests(); | ||
| // Held-back progress must land before the run's end, never after it. | ||
| this.subagentStream.flushAll(); | ||
|
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. Flush pending progress before synthetic terminal events too. If Move the terminal flush into the common
|
||
| this.streaming = false; | ||
| this.promptRunning = false; | ||
| this.awaitingAgentStart = false; | ||
|
|
@@ -1463,7 +1470,8 @@ export class AgentSessionWrapper { | |
| } | ||
|
|
||
| this.publishNotifications(event); | ||
| this.emit(event); | ||
| // Subagent frames are slimmed or held back (newest progress per child per second) before any tab sees them. | ||
| if (!this.subagentStream.push(event)) this.emit(event); | ||
| notifyRunningChange({ refreshSessionList }); | ||
| } | ||
|
|
||
|
|
@@ -3088,6 +3096,7 @@ export class AgentSessionWrapper { | |
| this.sessionFileSignalTimer = null; | ||
| } | ||
| this.unsubscribeFrames?.(); | ||
| this.subagentStream.dispose(); | ||
| this.unsubscribeHostStatus?.(); | ||
| this.unsubscribeHostStatus = null; | ||
| this.clearPendingUiRequests(); | ||
|
|
||
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.
Preserve a recovery trigger received during an earlier read.
If an earlier
get_subagentsresponse is delayed, a reconnect can reach this return after a quiet child has started. The earlier snapshot cannot contain that child. This return discards the reconnect trigger, andfinallyonly clears the marker. The child stays absent until another recovery trigger, normally the next periodic reconcile.Record a pending refresh and issue one trailing read after the current request settles. Keep the session, run and generation checks for that read.