Skip to content

Commit

Permalink
AIX: un-race-cond, debug-last-request
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Jan 15, 2025
1 parent 558d73a commit 849eb58
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
23 changes: 13 additions & 10 deletions src/modules/aix/client/ContentReassembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ export let devMode_AixLastDispatchRequest: { url: string, headers: string, body:
export class ContentReassembler {

private currentTextFragmentIndex: number | null = null;
private readonly dispatchRequest: typeof devMode_AixLastDispatchRequest = null;

constructor(readonly accumulator: AixChatGenerateContent_LL) {
// [DEV} nullify the global
devMode_AixLastDispatchRequest = null;
constructor(readonly accumulator: AixChatGenerateContent_LL, debugDispatchRequest: boolean) {
// [DEV] Debugging the request, last-write-wins for the global (displayed in the UI)
if (debugDispatchRequest) {
this.dispatchRequest = { url: '', headers: '', body: '', particles: [] };
devMode_AixLastDispatchRequest = this.dispatchRequest;
}
}

// reset(): void {
Expand All @@ -34,7 +38,6 @@ export class ContentReassembler {
reassembleParticle(op: AixWire_Particles.ChatGenerateOp, debugIsAborted: boolean): void {
if (DEBUG_PARTICLES)
console.log('-> aix.p:', op);
let isDebug = false;
switch (true) {

// TextParticleOp
Expand Down Expand Up @@ -65,6 +68,10 @@ export class ContentReassembler {
// ChatControlOp
case 'cg' in op:
switch (op.cg) {
case '_debugRequest':
if (this.dispatchRequest)
Object.assign(this.dispatchRequest, op.request);
break;
case 'end':
this.onCGEnd(op);
break;
Expand All @@ -77,10 +84,6 @@ export class ContentReassembler {
case 'set-model':
this.onModelName(op);
break;
case '_debugRequest':
isDebug = true;
devMode_AixLastDispatchRequest = { ...op.request, particles: [] };
break;
default:
this._appendReassemblyDevError(`unexpected ChatGenerateOp: ${JSON.stringify(op)}`);
}
Expand All @@ -91,8 +94,8 @@ export class ContentReassembler {
}

// [DEV] Debugging
if (!isDebug && devMode_AixLastDispatchRequest?.particles)
devMode_AixLastDispatchRequest.particles.push((debugIsAborted ? '!(A)! ' : '') + JSON.stringify(op));
if (this.dispatchRequest && (!('cg' in op) || op.cg !== '_debugRequest'))
this.dispatchRequest.particles.push((debugIsAborted ? '!(A)! ' : '') + JSON.stringify(op));
}

reassembleClientAbort(): void {
Expand Down
7 changes: 4 additions & 3 deletions src/modules/aix/client/aix.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ async function _aixChatGenerateContent_LL(
fragments: [],
/* rest start as undefined (missing in reality) */
};
const contentReassembler = new ContentReassembler(accumulator_LL);
const debugDispatchRequestbody = getLabsDevMode() && aixContext.name === 'conversation'; // [DEV] Debugging the conversation request (only)
const contentReassembler = new ContentReassembler(accumulator_LL, debugDispatchRequestbody);

// Initialize throttler if throttling is enabled
const throttler = (onReassemblyUpdate && throttleParallelThreads)
Expand All @@ -558,9 +559,9 @@ async function _aixChatGenerateContent_LL(
chatGenerate: aixChatGenerate,
context: aixContext,
streaming: getLabsDevNoStreaming() ? false : aixStreaming, // [DEV] disable streaming if set in the UX (testing)
...(getLabsDevMode() && {
...(debugDispatchRequestbody && {
connectionOptions: {
debugDispatchRequestbody: aixContext.name === 'conversation', // [DEV] Debugging the request without requiring a server restart
debugDispatchRequestbody: true, // [DEV] Debugging the request without requiring a server restart
},
}),
}, {
Expand Down

0 comments on commit 849eb58

Please sign in to comment.