@@ -11,7 +11,6 @@ import { checkAndBillPayerOverageThreshold } from '@/lib/billing/threshold-billi
1111import { OrchestrationError } from '@/lib/core/orchestration/types'
1212import { resourceScopeFromOwner , resourceScopeKey } from '@/lib/core/resource-scope'
1313import { PlatformEvents } from '@/lib/core/telemetry'
14- import { runDetached } from '@/lib/core/utils/background'
1514import { generateRequestId } from '@/lib/core/utils/request'
1615import { importDurableSecretProvenance } from '@/lib/execution/durable-secret-provenance'
1716import { reportDurableSecretProvenanceRefusal } from '@/lib/execution/durable-secret-provenance-telemetry'
@@ -620,8 +619,7 @@ const searchKnowledgeUseCase = defineAuthorizedKnowledgeUseCase({
620619 ] ,
621620 } )
622621 )
623- /** Whether the payer crossed a billing threshold is settled after the results are on their way. */
624- runDetached ( 'knowledge search overage billing' , ( ) =>
622+ await measureSearchStage ( 'overage_billing' , ( ) =>
625623 checkAndBillPayerOverageThreshold ( billingAttribution . billingEntity )
626624 )
627625 } catch ( error ) {
@@ -738,11 +736,10 @@ const searchKnowledgeUseCase = defineAuthorizedKnowledgeUseCase({
738736 } ,
739737 afterSuccess : async ( { principal, context, input, result } ) => {
740738 const actorUserId = resolvePrincipalSubjectUserId ( principal )
741- /** The record is for the organization's activity view; the caller's results never wait on it. */
742739 if ( context . organizationId && actorUserId ) {
743- runDetached ( 'organization search activity ', ( ) =>
740+ await measureSearchStage ( 'activity_recording ', ( ) =>
744741 recordOrganizationSearchActivity ( {
745- organizationId : context . organizationId ! ,
742+ organizationId : context . organizationId ,
746743 userId : actorUserId ,
747744 surface : input . surface ?? 'other' ,
748745 results : result . results ,
0 commit comments