Fix 4 bugs: remove dead PubSub code, ensure engine starts before accepting connections, restore checkpoint turn count inference logic, remove no-op syncCheckpointTurnCounts
- Remove unused readModelPubSub/eventPubSub instances and their publish calls from OrchestrationEngine (dead code adding latency to command dispatch) - Start orchestration engine before binding HTTP server port so clients never receive an un-replayed empty read model snapshot - Restore inferCheckpointTurnCountByTurnId to respect explicit checkpointTurnCount values on summaries instead of always using index+1 - Remove syncCheckpointTurnCounts (called listCheckpoints but discarded the result) and its fingerprint tracking ref from ChatView
This commit is contained in:
1 parent
c3b7cc713c
commit
17cec0b11d
4 files changed
+30
-74
No files matched your search
@@ -6,7 +6,7 @@ import type {
|
||||
OrchestrationReadModel,
|
||||
} from "@t3tools/contracts";
|
||||
import { OrchestrationCommandSchema } from "@t3tools/contracts";
|
||||
import { PubSub, Queue, Schema, Stream, Effect, Fiber, Runtime, Either } from "effect";
|
||||
import { Queue, Schema, Stream, Effect, Fiber, Runtime, Either } from "effect";
|
||||
|
||||
import { createLogger } from "../logger";
|
||||
import { SqliteEventStore } from "./eventStore";
|
||||
@@ -194,8 +194,6 @@ export class OrchestrationEngine {
|
||||
|
||||
private readModel: OrchestrationReadModel;
|
||||
private commandQueue: Queue.Queue<CommandEnvelope>;
|
||||
private readModelPubSub: PubSub.PubSub<OrchestrationReadModel>;
|
||||
private eventPubSub: PubSub.PubSub<OrchestrationEvent>;
|
||||
private workerFiber: Fiber.RuntimeFiber<void, unknown> | null = null;
|
||||
private readonly readModelListeners = new Set<(snapshot: OrchestrationReadModel) => void>();
|
||||
private readonly domainEventListeners = new Set<(event: OrchestrationEvent) => void>();
|
||||
@@ -205,10 +203,6 @@ export class OrchestrationEngine {
|
||||
this.eventStore = new SqliteEventStore(dbPath);
|
||||
this.readModel = createEmptyReadModel(new Date().toISOString());
|
||||
this.commandQueue = Runtime.runSync(this.runtime)(Queue.unbounded<CommandEnvelope>());
|
||||
this.readModelPubSub = Runtime.runSync(this.runtime)(
|
||||
PubSub.unbounded<OrchestrationReadModel>(),
|
||||
);
|
||||
this.eventPubSub = Runtime.runSync(this.runtime)(PubSub.unbounded<OrchestrationEvent>());
|
||||
}
|
||||
|
||||
async start(): Promise<void> {
|
||||
@@ -226,12 +220,6 @@ export class OrchestrationEngine {
|
||||
this.eventStore.append(eventBase),
|
||||
);
|
||||
this.readModel = reduceEvent(this.readModel, savedEvent);
|
||||
await Promise.all([
|
||||
Runtime.runPromise(this.runtime)(PubSub.publish(this.eventPubSub, savedEvent)),
|
||||
Runtime.runPromise(this.runtime)(
|
||||
PubSub.publish(this.readModelPubSub, this.readModel),
|
||||
),
|
||||
]);
|
||||
for (const listener of this.domainEventListeners) {
|
||||
listener(savedEvent);
|
||||
}
|
||||
|
||||
@@ -676,21 +676,17 @@ export function createServer(options: ServerOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
function start() {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
async function start() {
|
||||
await orchestrationEngine.start();
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const onError = (error: Error) => {
|
||||
httpServer.off("error", onError);
|
||||
reject(error);
|
||||
};
|
||||
httpServer.once("error", onError);
|
||||
const onListening = async () => {
|
||||
const onListening = () => {
|
||||
httpServer.off("error", onError);
|
||||
try {
|
||||
await orchestrationEngine.start();
|
||||
resolve();
|
||||
} catch (error) {
|
||||
reject(error instanceof Error ? error : new Error("Failed to start orchestration engine"));
|
||||
}
|
||||
resolve();
|
||||
};
|
||||
if (host) {
|
||||
httpServer.listen(port, host, onListening);
|
||||
|
||||
@@ -414,8 +414,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
const dragDepthRef = useRef(0);
|
||||
const terminalOpenByThreadRef = useRef<Record<string, boolean>>({});
|
||||
const checkpointHydrationSessionRequestRef = useRef(new Set<string>());
|
||||
const checkpointTurnCountSyncFingerprintRef = useRef(new Map<string, string>());
|
||||
|
||||
const activeThread = state.threads.find((t) => t.id === threadId);
|
||||
const diffSearch = useMemo(
|
||||
() => parseDiffRouteSearch(rawSearch as Record<string, unknown>),
|
||||
@@ -1405,39 +1403,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
focusComposer();
|
||||
};
|
||||
|
||||
const syncCheckpointTurnCounts = useCallback(
|
||||
async (input: {
|
||||
threadId: string;
|
||||
sessionId: string;
|
||||
threadRuntimeId: string | null;
|
||||
}): Promise<void> => {
|
||||
if (!api || turnDiffSummaries.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const turnIds = turnDiffSummaries.map((summary) => summary.turnId);
|
||||
if (turnIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const syncKey = `${input.threadId}:${input.sessionId}:${input.threadRuntimeId ?? "none"}`;
|
||||
const turnFingerprint = turnIds.join(",");
|
||||
if (checkpointTurnCountSyncFingerprintRef.current.get(syncKey) === turnFingerprint) {
|
||||
return;
|
||||
}
|
||||
checkpointTurnCountSyncFingerprintRef.current.set(syncKey, turnFingerprint);
|
||||
|
||||
try {
|
||||
await api.providers.listCheckpoints({
|
||||
sessionId: input.sessionId,
|
||||
});
|
||||
} catch {
|
||||
checkpointTurnCountSyncFingerprintRef.current.delete(syncKey);
|
||||
}
|
||||
},
|
||||
[api, turnDiffSummaries],
|
||||
);
|
||||
|
||||
const ensureSession = useCallback(
|
||||
async (cwdOverride?: string): Promise<EnsuredSessionInfo | null> => {
|
||||
if (!api || !activeThread || !activeProject) return null;
|
||||
@@ -1449,11 +1414,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
: sessionThreadId === activeThread.codexThreadId
|
||||
? "resumed"
|
||||
: "fallback_new";
|
||||
await syncCheckpointTurnCounts({
|
||||
threadId: activeThread.id,
|
||||
sessionId: activeThread.session.sessionId,
|
||||
threadRuntimeId: sessionThreadId,
|
||||
});
|
||||
return {
|
||||
sessionId: activeThread.session.sessionId,
|
||||
resolvedThreadId: sessionThreadId,
|
||||
@@ -1497,11 +1457,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
: resolvedThreadId === priorCodexThreadId
|
||||
? "resumed"
|
||||
: "fallback_new";
|
||||
await syncCheckpointTurnCounts({
|
||||
threadId: activeThread.id,
|
||||
sessionId: session.sessionId,
|
||||
threadRuntimeId: resolvedThreadId,
|
||||
});
|
||||
return {
|
||||
sessionId: session.sessionId,
|
||||
resolvedThreadId,
|
||||
@@ -1527,7 +1482,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
runtimeApprovalPolicy,
|
||||
runtimeSandboxMode,
|
||||
selectedModel,
|
||||
syncCheckpointTurnCounts,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -116,13 +116,31 @@ export function deriveTurnDiffFilesFromUnifiedDiff(diff: string): TurnDiffFileCh
|
||||
export function inferCheckpointTurnCountByTurnId(
|
||||
summaries: TurnDiffSummary[],
|
||||
): Record<string, number> {
|
||||
const sorted = [...summaries].sort((a, b) => a.completedAt.localeCompare(b.completedAt));
|
||||
const result: Record<string, number> = {};
|
||||
for (let index = 0; index < sorted.length; index += 1) {
|
||||
const summary = sorted[index];
|
||||
if (!summary) continue;
|
||||
result[summary.turnId] = index + 1;
|
||||
if (summaries.length === 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const sorted = [...summaries].sort((a, b) => {
|
||||
const aTime = Date.parse(a.completedAt);
|
||||
const bTime = Date.parse(b.completedAt);
|
||||
if (Number.isNaN(aTime) || Number.isNaN(bTime)) {
|
||||
return a.completedAt.localeCompare(b.completedAt);
|
||||
}
|
||||
return aTime - bTime;
|
||||
});
|
||||
|
||||
const result: Record<string, number> = {};
|
||||
let fallbackTurnCount = 1;
|
||||
for (const summary of sorted) {
|
||||
if (typeof summary.checkpointTurnCount === "number") {
|
||||
result[summary.turnId] = summary.checkpointTurnCount;
|
||||
fallbackTurnCount = Math.max(fallbackTurnCount, summary.checkpointTurnCount + 1);
|
||||
continue;
|
||||
}
|
||||
result[summary.turnId] = fallbackTurnCount;
|
||||
fallbackTurnCount += 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user