refactor: nuke dead exports, dead files, dead DB column, dead zero-value wrappers
Full-codebase ts-prune + manual audit sweep. Every change below is a pure
deletion (or a 2-line re-wire where a dead function was supposed to be
alive). No scope additions.
Dead wrappers / phantom features
- shouldAutoApproveApproval: zero-value wrapper over shouldAutoApprove.
Four call sites now import shouldAutoApprove from execution-policy
directly.
- evaluateRotation(session, connectorId, thresholdsOverride): the
connectorId arg was never read (underscored), and thresholdsOverride
was only exercised by the test suite — no production caller. Signature
collapses to evaluateRotation(session). DEFAULT_THRESHOLDS /
RotationThresholds exports and their tests go with it.
- installLogRedactor: defensive console wrapper that was never wired
from worker-entry. buildRedactor handles the known threat (env-value
leaks); the pattern-based redactTokens stays for tests and future
composition.
Dead files
- resume-interrupted-tasks.ts: helper function never imported.
- service-graph-orchestration-deps.ts: three factory closures
superseded by the inline closures in create-orchestration-service.
Dead exports
- listConnectorsByAuthKind (shared/connector-catalog)
- getLocalePromptInstruction + whole localization.ts file
- ImportantDocType
- main-side ConnectorAuthKind (duplicated the shared one; not referenced)
- CheckpointEngineService, RunHousekeepingService types
- WorkspaceResolution type
- cmdOrCtrlSymbol
- AgentEventPush, CredentialPayload type aliases
- parseApprovalPayloadJson, parseEnvValue, ProviderCard
- getSOP — buildSOPSection reads the SOPS map directly; the individual
getter had no callers. Deduped to a flat array.
- renderWakeReason in wake-reasons/en.ts: byte-for-byte duplicate of the
one in wake-reasons/index.ts.
Forgotten wiring (not cleanup, but adjacent)
- registerAgentStandupRoute: the GET /api/agents/me/standup endpoint is
advertised in every system prompt and wake-reason doc, but the route
handler was never registered in api-server/index.ts. Agents have been
hitting 404 since Pi Mono. Registered.
Dead DB column
- v44 migration drops runs.context_snapshot_json. Column was added by
v16-v25, never written or read, and v43's deliberate preservation
was an interim measure. Same idempotent table-rebuild pattern as
v41/v43.
Test tree
- Phantom-feature threshold override tests removed (3). The rest of
the rotation suite re-expressed against the real maxRuns=20 floor.
495/495 unit tests pass. typecheck + build clean.
This commit is contained in:
1 parent
e0e43d6127
commit
f041336721
33 files changed
+143
-481
No files matched your search
@@ -2,7 +2,6 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
inferTaskType,
|
||||
getConnectorStrengths,
|
||||
ROLE_DEPARTMENT_HINTS as _ROLE_DEPARTMENT_HINTS,
|
||||
} from "../../src/main/connector-matching";
|
||||
|
||||
describe("connector-matching", () => {
|
||||
|
||||
@@ -13,7 +13,7 @@ vi.mock("electron", () => ({
|
||||
}));
|
||||
|
||||
import { AppDatabase } from "../../src/main/database";
|
||||
import { createSessionManagementService, DEFAULT_THRESHOLDS } from "../../src/main/session-management-service";
|
||||
import { createSessionManagementService } from "../../src/main/session-management-service";
|
||||
import type { ConnectorId } from "@shared/types";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -121,17 +121,17 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
});
|
||||
|
||||
// Simulate runs until we reach the maxRuns threshold (20)
|
||||
for (let i = 0; i < DEFAULT_THRESHOLDS.maxRuns; i++) {
|
||||
for (let i = 0; i < 20; i++) {
|
||||
db.incrementSessionUsage(sessionId, 1000, 500, `run-${i}`);
|
||||
}
|
||||
|
||||
// Get the updated session from DB
|
||||
const session = db.getSessionById(sessionId);
|
||||
expect(session).not.toBeNull();
|
||||
expect(session!.runCount).toBe(DEFAULT_THRESHOLDS.maxRuns);
|
||||
expect(session!.runCount).toBe(20); // matches maxRuns threshold in session-management-service
|
||||
|
||||
// Evaluate rotation -- should trigger
|
||||
const result = sessionService.evaluateRotation(session!, "gemini-cli");
|
||||
const result = sessionService.evaluateRotation(session!);
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
expect(result.reason).toBe("max_runs");
|
||||
});
|
||||
@@ -146,8 +146,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
adapterType: "gemini-cli",
|
||||
});
|
||||
|
||||
// Accumulate tokens past the threshold in one big call
|
||||
// DEFAULT_THRESHOLDS.maxTokens = 500_000 (total input + output)
|
||||
// Accumulate tokens past the 500_000 maxTokens threshold in one big call
|
||||
db.incrementSessionUsage(sessionId, 300000, 250000, "big-run");
|
||||
|
||||
const session = db.getSessionById(sessionId);
|
||||
@@ -155,7 +154,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
const totalTokens = session!.totalInputTokens + session!.totalOutputTokens;
|
||||
expect(totalTokens).toBe(550000);
|
||||
|
||||
const result = sessionService.evaluateRotation(session!, "gemini-cli");
|
||||
const result = sessionService.evaluateRotation(session!);
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
expect(result.reason).toBe("max_tokens");
|
||||
});
|
||||
@@ -171,7 +170,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
});
|
||||
|
||||
// Accumulate enough to trigger rotation
|
||||
for (let i = 0; i < DEFAULT_THRESHOLDS.maxRuns; i++) {
|
||||
for (let i = 0; i < 20; i++) {
|
||||
db.incrementSessionUsage(sessionId, 1000, 500, `run-${i}`);
|
||||
}
|
||||
|
||||
@@ -266,7 +265,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
|
||||
const session = db.getSessionById(sessionId)!;
|
||||
// Pi-mono delegates compaction to pi-agent-core; AgentCompany still applies rotation uniformly.
|
||||
const result = sessionService.evaluateRotation(session, "claude-pro");
|
||||
const result = sessionService.evaluateRotation(session);
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
expect(result.reason).not.toBeNull();
|
||||
});
|
||||
@@ -288,7 +287,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
|
||||
const session = db.getSessionById(sessionId)!;
|
||||
// Pi-mono delegates compaction to pi-agent-core; AgentCompany still applies rotation uniformly.
|
||||
const result = sessionService.evaluateRotation(session, "openai-codex");
|
||||
const result = sessionService.evaluateRotation(session);
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
expect(result.reason).not.toBeNull();
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ vi.mock("electron", () => ({
|
||||
|
||||
import { AppDatabase } from "../../src/main/database";
|
||||
import { getConnectorDefinition } from "../../src/main/connectors";
|
||||
import { createSessionManagementService, DEFAULT_THRESHOLDS } from "../../src/main/session-management-service";
|
||||
import { createSessionManagementService } from "../../src/main/session-management-service";
|
||||
import type { ConnectorId, TaskSessionRecord } from "@shared/types";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -291,7 +291,7 @@ describe("session management service", () => {
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
const result = svc.evaluateRotation(session, "gemini-cli");
|
||||
const result = svc.evaluateRotation(session);
|
||||
expect(result.shouldRotate).toBe(false);
|
||||
expect(result.reason).toBeNull();
|
||||
});
|
||||
@@ -314,7 +314,7 @@ describe("session management service", () => {
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
const result = svc.evaluateRotation(session, "gemini-cli");
|
||||
const result = svc.evaluateRotation(session);
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
expect(result.reason).toBe("max_runs");
|
||||
});
|
||||
@@ -337,7 +337,7 @@ describe("session management service", () => {
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
const result = svc.evaluateRotation(session, "gemini-cli");
|
||||
const result = svc.evaluateRotation(session);
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
expect(result.reason).toBe("max_tokens");
|
||||
});
|
||||
@@ -361,7 +361,7 @@ describe("session management service", () => {
|
||||
createdAt: oldDate,
|
||||
updatedAt: oldDate,
|
||||
};
|
||||
const result = svc.evaluateRotation(session, "gemini-cli");
|
||||
const result = svc.evaluateRotation(session);
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
expect(result.reason).toBe("max_age_hours");
|
||||
});
|
||||
@@ -389,91 +389,12 @@ describe("session management service", () => {
|
||||
createdAt: new Date(Date.now() - 200 * 60 * 60 * 1000).toISOString(), // Way old
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
const result = svc.evaluateRotation(session, "claude-pro");
|
||||
const result = svc.evaluateRotation(session);
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
expect(result.reason).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// configurable thresholds (D-01)
|
||||
// -------------------------------------------------------------------------
|
||||
describe("configurable thresholds (D-01)", () => {
|
||||
it("evaluateRotation with custom thresholds override { maxRuns: 5 } triggers at 5 runs", () => {
|
||||
const svc = createSessionManagementService({ db, logger: mockLogger });
|
||||
const session: TaskSessionRecord = {
|
||||
id: "sess-1",
|
||||
companyId: "co-1",
|
||||
agentId: "agent-1",
|
||||
adapterType: "gemini-cli",
|
||||
lastRunId: null,
|
||||
lastError: null,
|
||||
runCount: 5,
|
||||
totalInputTokens: 100,
|
||||
totalOutputTokens: 100,
|
||||
rotatedAt: null,
|
||||
rotationReason: null,
|
||||
handoffMarkdown: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
const result = svc.evaluateRotation(session, "gemini-cli", { maxRuns: 5 });
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
expect(result.reason).toBe("max_runs");
|
||||
});
|
||||
|
||||
it("partial override { maxTokens: 100000 } uses override for tokens but defaults for runs and age", () => {
|
||||
const svc = createSessionManagementService({ db, logger: mockLogger });
|
||||
const session: TaskSessionRecord = {
|
||||
id: "sess-1",
|
||||
companyId: "co-1",
|
||||
agentId: "agent-1",
|
||||
adapterType: "gemini-cli",
|
||||
lastRunId: null,
|
||||
lastError: null,
|
||||
runCount: 10, // Below default 20
|
||||
totalInputTokens: 60000,
|
||||
totalOutputTokens: 40000, // Total 100000 = meets override threshold
|
||||
rotatedAt: null,
|
||||
rotationReason: null,
|
||||
handoffMarkdown: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
const result = svc.evaluateRotation(session, "gemini-cli", { maxTokens: 100000 });
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
expect(result.reason).toBe("max_tokens");
|
||||
});
|
||||
|
||||
it("omitting override uses DEFAULT_THRESHOLDS", () => {
|
||||
const svc = createSessionManagementService({ db, logger: mockLogger });
|
||||
const session: TaskSessionRecord = {
|
||||
id: "sess-1",
|
||||
companyId: "co-1",
|
||||
agentId: "agent-1",
|
||||
adapterType: "gemini-cli",
|
||||
lastRunId: null,
|
||||
lastError: null,
|
||||
runCount: 19, // Just below default 20
|
||||
totalInputTokens: 200000,
|
||||
totalOutputTokens: 200000, // Total 400000, below default 500000
|
||||
rotatedAt: null,
|
||||
rotationReason: null,
|
||||
handoffMarkdown: null,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
const result = svc.evaluateRotation(session, "gemini-cli");
|
||||
expect(result.shouldRotate).toBe(false);
|
||||
expect(result.reason).toBeNull();
|
||||
|
||||
// Verify DEFAULT_THRESHOLDS values
|
||||
expect(DEFAULT_THRESHOLDS.maxRuns).toBe(20);
|
||||
expect(DEFAULT_THRESHOLDS.maxTokens).toBe(500_000);
|
||||
expect(DEFAULT_THRESHOLDS.maxAgeHours).toBe(72);
|
||||
});
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// token accumulation
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user