fix(coding-runtime): close Pi extension lifecycle races

This commit is contained in:
2026-08-23 10:13:10 +08:00
parent 3861c3286a
commit 31de325cd8
9 changed files with 197 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ const MAX_TITLE_LENGTH = 256;
const MAX_EDITOR_TEXT_LENGTH = 64 * 1024;
const MAX_WIDGET_LINES = 32;
const MAX_WIDGET_LINE_LENGTH = 512;
const MAX_DIAGNOSTICS = 256;
export type PiExtensionUiProjection =
| { kind: 'notify'; conversationId: string; message: string; level: 'info' | 'warning' | 'error' }
@@ -136,7 +137,7 @@ export class PiExtensionUiProjector {
}
if (event.method === 'set_editor_text' && typeof event.text === 'string') {
if (this.getDraftRevision(conversationId) !== run.draftRevision) {
this.diagnostics.push({ method: event.method, reason: 'stale-draft-revision' });
this.recordDiagnostic({ method: event.method, reason: 'stale-draft-revision' });
return null;
}
return {
@@ -151,12 +152,17 @@ export class PiExtensionUiProjector {
}
private unsupported(method: string): null {
this.diagnostics.push({ method: bounded(method, 128), reason: 'unsupported-ui-method' });
this.recordDiagnostic({ method: bounded(method, 128), reason: 'unsupported-ui-method' });
return null;
}
private invalid(method: string): null {
this.diagnostics.push({ method: bounded(method, 128), reason: 'invalid-ui-payload' });
this.recordDiagnostic({ method: bounded(method, 128), reason: 'invalid-ui-payload' });
return null;
}
private recordDiagnostic(diagnostic: PiExtensionUiDiagnostic): void {
this.diagnostics.push(diagnostic);
if (this.diagnostics.length > MAX_DIAGNOSTICS) this.diagnostics.shift();
}
}