fix: close internal semantic review gaps
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
import type { OllamaEnsureResult, ThtRunner } from "../tht/tht-runner.js";
|
||||
import type {
|
||||
OllamaEnsureResult,
|
||||
SemanticReadinessCode,
|
||||
ThtRunner,
|
||||
} from "../tht/tht-runner.js";
|
||||
import type { PrincipalContext } from "../auth/principal.js";
|
||||
import type { WorkspaceDescriptor } from "../workspaces/schema.js";
|
||||
|
||||
export type ReadinessResult = OllamaEnsureResult & { code?: SemanticReadinessCode };
|
||||
|
||||
interface ReadyEntry {
|
||||
expiresAt: number;
|
||||
result: OllamaEnsureResult;
|
||||
result: ReadinessResult;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -11,7 +18,7 @@ interface ReadyEntry {
|
||||
* Failures are deliberately not cached so a submit can retry after a transient outage.
|
||||
*/
|
||||
export class ReadinessManager {
|
||||
private inFlight = new Map<string, Promise<OllamaEnsureResult>>();
|
||||
private inFlight = new Map<string, Promise<ReadinessResult>>();
|
||||
private ready = new Map<string, ReadyEntry>();
|
||||
|
||||
constructor(
|
||||
@@ -21,7 +28,11 @@ export class ReadinessManager {
|
||||
private now: () => number = Date.now,
|
||||
) {}
|
||||
|
||||
ensure(workspace = "", principal?: PrincipalContext): Promise<OllamaEnsureResult> {
|
||||
ensure(
|
||||
workspace = "",
|
||||
principal?: PrincipalContext,
|
||||
descriptor?: WorkspaceDescriptor,
|
||||
): Promise<ReadinessResult> {
|
||||
const key = `${principal?.issuer ?? ""}\0${principal?.subject ?? ""}\0${workspace}`;
|
||||
const cached = this.ready.get(key);
|
||||
if (cached && cached.expiresAt > this.now()) return Promise.resolve(cached.result);
|
||||
@@ -32,7 +43,20 @@ export class ReadinessManager {
|
||||
|
||||
const runner = principal && typeof (this.tht as any).withPrincipal === "function"
|
||||
? this.tht.withPrincipal(principal) : this.tht;
|
||||
const pending = runner.ollamaEnsure(workspace, this.timeoutSec)
|
||||
const pending = (async (): Promise<ReadinessResult> => {
|
||||
try {
|
||||
if (descriptor) {
|
||||
const qdrant = await runner.qdrantEnsure(descriptor, this.timeoutSec);
|
||||
if (!qdrant.ok) return qdrant;
|
||||
}
|
||||
const ollama = await runner.ollamaEnsure(workspace, this.timeoutSec);
|
||||
return ollama.ok
|
||||
? ollama
|
||||
: { ...ollama, code: "workspace_not_activatable" };
|
||||
} catch {
|
||||
return { ok: false, code: "workspace_not_activatable" };
|
||||
}
|
||||
})()
|
||||
.then((result) => {
|
||||
if (result.ok) {
|
||||
this.ready.set(key, { result, expiresAt: this.now() + this.ttlMs });
|
||||
|
||||
Reference in New Issue
Block a user