mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-06 15:52:22 +01:00
Isolate voice recovery failures and control generation test time
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
1b6323c164
commit
ad79c7e805
6 files changed
+127
-21
No files matched your search
@@ -147,3 +147,38 @@ passes all 469. Tests are not counted twice. Expected controlled failures and
|
||||
listener warnings remain in logs. Only documentation changes follow these checks.
|
||||
Fresh current-head reviews, CI and parent landing remain required. No full local
|
||||
matrix, provider acceptance, external wake or deployed sleep result is claimed.
|
||||
|
||||
|
||||
## Wildcard failure and deterministic generation acceptance, October 28
|
||||
|
||||
Current-head CI `40633667141` fails server shard 1 at the feature-change test's
|
||||
34,050 ms result against its 25,000 ms bound; verification fails as an aggregate.
|
||||
This is an actual required assertion failure, distinct from the older interrupted
|
||||
build and missing policy script. The old test mixed automatically advancing fake
|
||||
time with real database latency. It now disables automatic clock advancement,
|
||||
drives 20 explicit scheduler turns, waits for each pass without advancing the
|
||||
clock, and requires every invalidated call to close before the unrelated periodic
|
||||
authority deadline. Removing generation replay still fails with missing closures.
|
||||
The test no longer benchmarks host/database speed or raises its business bound.
|
||||
|
||||
A real committed-session regression also reproduces wildcard starvation: while
|
||||
one broad reconstruction backs off, a newly ending exact call is not closed.
|
||||
The worker now retains the broad retry but considers ready exact hints and cached
|
||||
due calls independently. Each due call still reloads state and authorization in
|
||||
its owning check before effects. Failed exact scopes retain their own fence;
|
||||
the existing stale-cache failure regression still passes. Removing wildcard
|
||||
isolation fails the new exact-call assertion. Broad reconstruction becomes quiet
|
||||
after its successful retry, with no continuing SQL afterward.
|
||||
|
||||
The full-row execution lookup and lean inventory lookup now share the live-state,
|
||||
scope and cursor predicate. Their projections remain intentionally different.
|
||||
An initial edit script rejected the header cursor name before applying the timing
|
||||
and predicate changes; the intermediate 19-case result covers only the earlier
|
||||
worker repair. It is not the final repair evidence. The corrected source passes
|
||||
all 19 lifecycle cases and 191 complete voice-store/shared/startup cases: 210
|
||||
distinct targeted cases. Production server typecheck and build pass. Both guarded
|
||||
regressions fail at their intended effect assertion and restore source afterward.
|
||||
The fresh voice-store database self-migrates. Existing controlled failure logs
|
||||
and signal-listener warnings remain recorded. The older 725-case acceptance
|
||||
belongs to its stated revision and is not added to this count. Fresh current-head
|
||||
reviews and all CI remain required before merging after receiver discovery.
|
||||
@@ -1608,3 +1608,13 @@ CI. Voice server/package code and tests remain identical to the 725-case tested
|
||||
head. The policy checker and its Node tests pass. The [voice audit](2026-10-25-voice-maintenance-sleep-audit.md#trusted-policy-checkout-compatibility-october-27)
|
||||
keeps the four old failed gates, including the independent runner shutdown,
|
||||
separate from current local evidence. Fresh review and CI remain required.
|
||||
|
||||
|
||||
## Voice review follow-up, October 28
|
||||
|
||||
Voice recovery isolates a failed broad inventory retry from ready exact hints
|
||||
and cached due calls, while retaining on-use authority checks and exact-scope
|
||||
fences. The generation test uses controlled scheduler turns instead of elapsed
|
||||
SQL time. All 210 current targeted cases, production typecheck and server build
|
||||
pass; guarded mutations catch both regressions. The [voice audit](2026-10-25-voice-maintenance-sleep-audit.md#wildcard-failure-and-deterministic-generation-acceptance-october-28)
|
||||
keeps the actual CI assertion failure and earlier failed attempts separate.
|
||||
@@ -260,3 +260,38 @@ executes successfully, and its complete Node test file passes locally. No sleep
|
||||
implementation, test assertion or workflow gate is weakened. Fresh CI must prove
|
||||
the full build and aggregate gates; the interrupted build is not relabeled as a
|
||||
pass. Fresh Ponytail and Greptile acceptance still precede any merge.
|
||||
|
||||
|
||||
## Wildcard failure and deterministic generation acceptance, October 28
|
||||
|
||||
Current-head CI `40633667141` fails server shard 1 at the feature-change test's
|
||||
34,050 ms result against its 25,000 ms bound; verification fails as an aggregate.
|
||||
This is an actual required assertion failure, distinct from the older interrupted
|
||||
build and missing policy script. The old test mixed automatically advancing fake
|
||||
time with real database latency. It now disables automatic clock advancement,
|
||||
drives 20 explicit scheduler turns, waits for each pass without advancing the
|
||||
clock, and requires every invalidated call to close before the unrelated periodic
|
||||
authority deadline. Removing generation replay still fails with missing closures.
|
||||
The test no longer benchmarks host/database speed or raises its business bound.
|
||||
|
||||
A real committed-session regression also reproduces wildcard starvation: while
|
||||
one broad reconstruction backs off, a newly ending exact call is not closed.
|
||||
The worker now retains the broad retry but considers ready exact hints and cached
|
||||
due calls independently. Each due call still reloads state and authorization in
|
||||
its owning check before effects. Failed exact scopes retain their own fence;
|
||||
the existing stale-cache failure regression still passes. Removing wildcard
|
||||
isolation fails the new exact-call assertion. Broad reconstruction becomes quiet
|
||||
after its successful retry, with no continuing SQL afterward.
|
||||
|
||||
The full-row execution lookup and lean inventory lookup now share the live-state,
|
||||
scope and cursor predicate. Their projections remain intentionally different.
|
||||
An initial edit script rejected the header cursor name before applying the timing
|
||||
and predicate changes; the intermediate 19-case result covers only the earlier
|
||||
worker repair. It is not the final repair evidence. The corrected source passes
|
||||
all 19 lifecycle cases and 191 complete voice-store/shared/startup cases: 210
|
||||
distinct targeted cases. Production server typecheck and build pass. Both guarded
|
||||
regressions fail at their intended effect assertion and restore source afterward.
|
||||
The fresh voice-store database self-migrates. Existing controlled failure logs
|
||||
and signal-listener warnings remain recorded. The older 725-case acceptance
|
||||
belongs to its stated revision and is not added to this count. Fresh current-head
|
||||
reviews and all CI remain required before merging after receiver discovery.
|
||||
@@ -151,20 +151,25 @@ const support = external ? { supported: true } : await getEmbeddedPostgresTestSu
|
||||
await quiet(5000);
|
||||
});
|
||||
it("reapplies a feature change that arrives between inventory pages", async () => {
|
||||
vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"], shouldAdvanceTime: false });
|
||||
await futureInventory(205);
|
||||
const settings = instanceSettingsService(db), service = voiceSessionRecovery(db, { authorize, inspect, close });
|
||||
const refresh = service.refresh; let changedAt: number | undefined;
|
||||
const refresh = service.refresh; let changed = false;
|
||||
service.refresh = async (...args) => {
|
||||
const result = await refresh(...args);
|
||||
if (!args[0] && !result.complete && changedAt === undefined) {
|
||||
changedAt = Date.now(); await settings.updateExperimental({ enableChatConnectors: false });
|
||||
if (!args[0] && !result.complete && !changed) {
|
||||
changed = true; await settings.updateExperimental({ enableChatConnectors: false });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
try {
|
||||
await start(service); await settled();
|
||||
await start(service);
|
||||
for (let pass = 0; pass < 20; pass++) {
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
await vi.waitFor(() => expect(coordinator!.nextWakeAt() !== null || idleWorkSnapshot().active === 0).toBe(true), { interval: 0 });
|
||||
}
|
||||
expect(new Set(close.mock.calls.map(([row]) => row.id)).size).toBe(205);
|
||||
expect(Date.now() - changedAt!).toBeLessThan(25_000);
|
||||
await settled();
|
||||
await quiet();
|
||||
} finally {
|
||||
await coordinator?.stop(); coordinator = undefined;
|
||||
@@ -289,6 +294,28 @@ const support = external ? { supported: true } : await getEmbeddedPostgresTestSu
|
||||
expect(inspect.mock.calls.slice(0, 25).some(([candidate]) => candidate.id === row.id)).toBe(true);
|
||||
await settled(); expect(inspect).toHaveBeenCalledTimes(31); await quiet();
|
||||
});
|
||||
it("keeps exact hints and cached due calls moving while wildcard reconstruction backs off", async () => {
|
||||
vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"], shouldAdvanceTime: false });
|
||||
const cached = await session({ updatedAt: new Date(Date.now() - 20_000) });
|
||||
const dueAt = cached.updatedAt.getTime() + 30_000;
|
||||
const service = await start(), refresh = service.refresh;
|
||||
service.refresh = async (scope, signal) => {
|
||||
if (!scope) throw new Error("wildcard unavailable");
|
||||
return refresh(scope, signal);
|
||||
};
|
||||
await db.transaction(tx => notifyVoiceRecovery(tx));
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
await vi.waitFor(() => expect(errors).toHaveLength(1), { interval: 0 });
|
||||
const exact = await session({ state: "ending" });
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
await vi.waitFor(() => expect(close).toHaveBeenCalledWith(expect.objectContaining({ id: exact.id })), { interval: 0 });
|
||||
await vi.advanceTimersByTimeAsync(Math.max(0, dueAt - Date.now()));
|
||||
await vi.waitFor(() => expect(inspect).toHaveBeenCalledWith(expect.objectContaining({ id: cached.id })), { interval: 0 });
|
||||
expect(errors).toHaveLength(1);
|
||||
service.refresh = refresh; errors.length = 0;
|
||||
await vi.advanceTimersByTimeAsync(Math.max(0, coordinator!.nextWakeAt()! - Date.now()));
|
||||
await settled(); await quiet();
|
||||
});
|
||||
it("does not inspect stale cached work until a failed scope refresh succeeds", async () => {
|
||||
const row = await session({ updatedAt: new Date(Date.now() - 20_000) });
|
||||
const service = voiceSessionRecovery(db, { authorize, inspect, close }), original = service.refresh;
|
||||
|
||||
@@ -26,13 +26,14 @@ export function registerVoiceRecoveryWork(
|
||||
map.set(id, { count, retryAt: Date.now() + Math.min(300_000, 30_000 * 2 ** (count - 1)) });
|
||||
}
|
||||
function dirtyScopes() {
|
||||
return [...dirty].filter(hint => !scans.has(hint) || scopeFailures.has(hint))
|
||||
return [...dirty].filter(hint => hint !== "*" || !scopeFailures.has(hint))
|
||||
.filter(hint => !scans.has(hint) || scopeFailures.has(hint))
|
||||
.map(hint => { try { return voiceRecoveryScope(hint); } catch { return undefined; } });
|
||||
}
|
||||
function next() {
|
||||
let nextAt: number | null = null;
|
||||
const take = (at: number) => { nextAt = nextAt === null ? at : Math.min(nextAt, at); };
|
||||
for (const hint of dirty.has("*") ? ["*"] : dirty) take(Math.max(earliest, scopeFailures.get(hint)?.retryAt ?? 0));
|
||||
for (const hint of dirty) take(Math.max(earliest, scopeFailures.get(hint)?.retryAt ?? 0));
|
||||
const unavailable = dirtyScopes();
|
||||
for (const entry of entries.values()) if (!unavailable.some(scope => matches(entry, scope)))
|
||||
take(Math.max(earliest, entry.dueAt, failures.get(entry.id)?.retryAt ?? 0));
|
||||
@@ -49,8 +50,8 @@ export function registerVoiceRecoveryWork(
|
||||
earliest = Date.now() + 1000;
|
||||
const errors: unknown[] = [];
|
||||
const ready = [...dirty].filter(hint => (scopeFailures.get(hint)?.retryAt ?? 0) <= Date.now());
|
||||
const requested = dirty.has("*")
|
||||
? ready.includes("*") ? ["*", ...ready.filter(hint => hint !== "*")].slice(0, 25) : []
|
||||
const requested = ready.includes("*")
|
||||
? ["*", ...ready.filter(hint => hint !== "*")].slice(0, 25)
|
||||
: ready.slice(0, 25);
|
||||
for (const hint of requested) dirty.delete(hint);
|
||||
for (let index = 0; index < requested.length; index++) {
|
||||
|
||||
@@ -24,6 +24,14 @@ export function voiceSessionRecovery(db: Db, operations: {
|
||||
inspect(session: Session): Promise<{ endedAt?: unknown } | null>;
|
||||
close(session: Session): Promise<unknown>;
|
||||
}) {
|
||||
function sessionConditions(scope?: VoiceRecoveryScope, cursor?: string) {
|
||||
return and(inArray(chatVoiceSessions.state, [...LIVE_VOICE_STATES]),
|
||||
scope?.kind === "session" ? eq(chatVoiceSessions.id, scope.id) : undefined,
|
||||
scope?.kind === "endpoint" ? eq(chatVoiceSessions.endpointId, scope.id) : undefined,
|
||||
scope?.kind === "connection" ? eq(toolConnections.id, scope.id) : undefined,
|
||||
scope?.kind === "company" ? eq(chatVoiceSessions.companyId, scope.id) : undefined,
|
||||
cursor ? gt(chatVoiceSessions.id, cursor) : undefined);
|
||||
}
|
||||
async function candidates(scope?: VoiceRecoveryScope, signal?: AbortSignal) {
|
||||
const rows: Candidate<Session>[] = [];
|
||||
let cursor: string | undefined;
|
||||
@@ -34,12 +42,7 @@ export function voiceSessionRecovery(db: Db, operations: {
|
||||
.from(chatVoiceSessions)
|
||||
.innerJoin(chatEndpoints, and(eq(chatEndpoints.id, chatVoiceSessions.endpointId), eq(chatEndpoints.companyId, chatVoiceSessions.companyId)))
|
||||
.innerJoin(toolConnections, and(eq(toolConnections.id, chatEndpoints.connectionId), eq(toolConnections.companyId, chatVoiceSessions.companyId)))
|
||||
.where(and(inArray(chatVoiceSessions.state, [...LIVE_VOICE_STATES]),
|
||||
scope?.kind === "session" ? eq(chatVoiceSessions.id, scope.id) : undefined,
|
||||
scope?.kind === "endpoint" ? eq(chatVoiceSessions.endpointId, scope.id) : undefined,
|
||||
scope?.kind === "connection" ? eq(toolConnections.id, scope.id) : undefined,
|
||||
scope?.kind === "company" ? eq(chatVoiceSessions.companyId, scope.id) : undefined,
|
||||
cursor ? gt(chatVoiceSessions.id, cursor) : undefined))
|
||||
.where(sessionConditions(scope, cursor))
|
||||
.orderBy(chatVoiceSessions.id).limit(100);
|
||||
rows.push(...page);
|
||||
if (page.length < 100) return rows;
|
||||
@@ -104,12 +107,7 @@ export function voiceSessionRecovery(db: Db, operations: {
|
||||
.from(chatVoiceSessions)
|
||||
.innerJoin(chatEndpoints, and(eq(chatEndpoints.id, chatVoiceSessions.endpointId), eq(chatEndpoints.companyId, chatVoiceSessions.companyId)))
|
||||
.innerJoin(toolConnections, and(eq(toolConnections.id, chatEndpoints.connectionId), eq(toolConnections.companyId, chatVoiceSessions.companyId)))
|
||||
.where(and(inArray(chatVoiceSessions.state, [...LIVE_VOICE_STATES]),
|
||||
scope?.kind === "session" ? eq(chatVoiceSessions.id, scope.id) : undefined,
|
||||
scope?.kind === "endpoint" ? eq(chatVoiceSessions.endpointId, scope.id) : undefined,
|
||||
scope?.kind === "connection" ? eq(toolConnections.id, scope.id) : undefined,
|
||||
scope?.kind === "company" ? eq(chatVoiceSessions.companyId, scope.id) : undefined,
|
||||
scan.cursor ? gt(chatVoiceSessions.id, scan.cursor) : undefined))
|
||||
.where(sessionConditions(scope, scan.cursor))
|
||||
.orderBy(chatVoiceSessions.id).limit(100);
|
||||
const enabled = page.length ? (await instanceSettingsService(db).getExperimental()).enableChatConnectors : false;
|
||||
const next = new Map(scan.parents);
|
||||
|
||||
Reference in new issue
Block a user