-
Notifications
You must be signed in to change notification settings - Fork 439
fix(runtime-host): defer resource drain outside admission #4661
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
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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { truncateUtf8 } from '@maka/core/diagnostic-log'; | ||
| import { redactSecrets } from '@maka/core/redaction'; | ||
|
|
||
| export function boundedFailureDiagnostic(error: unknown): string { | ||
| const details = | ||
| error instanceof Error ? error.stack || `${error.name}: ${error.message}` : String(error); | ||
| return truncateUtf8(redactSecrets(details), 8 * 1024, '\n<diagnostic truncated>'); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3585,9 +3585,11 @@ export class SessionManager { | |
| const hostedAuthority = isRuntimeHostedRootAuthority(this.deps.messageAuthority) | ||
| ? this.deps.messageAuthority | ||
| : undefined; | ||
| const ownStop = hostedAuthority | ||
| ? hostedAuthority.stopSession(sessionId, input) | ||
| : this.runtimeKernel.stopSession(sessionId, input); | ||
| const ownStop = observeSettlement( | ||
| hostedAuthority | ||
| ? hostedAuthority.stopSession(sessionId, input) | ||
| : this.runtimeKernel.stopSession(sessionId, input), | ||
| ); | ||
| let childStops: PromiseSettledResult<void>[] = []; | ||
| let childLookupError: unknown; | ||
| try { | ||
|
|
@@ -3604,7 +3606,8 @@ export class SessionManager { | |
| } catch (error) { | ||
| childLookupError = error; | ||
| } | ||
| await ownStop; | ||
| const ownStopResult = await ownStop; | ||
| if (ownStopResult.status === 'rejected') throw ownStopResult.reason; | ||
|
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. P1 (reach: reasonable failure path): It is on the same call chain: Smallest fix: wrap that |
||
| const childStopError = childStops.find( | ||
| (result): result is PromiseRejectedResult => result.status === 'rejected', | ||
| )?.reason; | ||
|
|
@@ -5560,6 +5563,13 @@ function tail<T>(items: readonly T[], max: number): T[] { | |
| return items.slice(items.length - max); | ||
| } | ||
|
|
||
| function observeSettlement<T>(promise: Promise<T>): Promise<PromiseSettledResult<T>> { | ||
| return promise.then( | ||
| (value) => ({ status: 'fulfilled', value }), | ||
| (reason: unknown) => ({ status: 'rejected', reason }), | ||
| ); | ||
| } | ||
|
|
||
| function shellRunBashToolCallIds(messages: readonly StoredMessage[]): Set<string> { | ||
| return new Set( | ||
| messages.flatMap((message) => | ||
|
|
||
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.
P2 (reach: reasonable failure path): this file still calls
#requestDrain()from inside an admission in two other places, so the query path is the only one that got the fix.#mutableSessionFailureat:762, reached insidesessionAdmission.runfrom:410(#start),:525(#acquire),:611(#control),:718(#stop)#resourceFailureat:776, reached insidesessionAdmission.runfrom:580,:666,:735(the:507call site is outside the run and is fine)With
observeSettlementin place these no longer take the process down, but the nested admission still rejects.stream-graph-coordinator.ts:650-675collects that intofailures, so the drain never stops the graph's operator sessions andclose()ends withFailed to close one or more agent graph coordinators. The drain is degraded on exactly the paths it exists for.Smallest fix: give these two the same treatment as the query path, or move the deferral into
RuntimeHostKernel.#requestDrainso every site is covered at once.