Skip to content

Fix Request Logs clean history purge - #3751

Merged
diegosouzapw merged 4 commits into
cheaper-inference:release/v3.8.24from
rdself:coder/thorough-clean-history
Jun 13, 2026
Merged

diegosouzapw merged 4 commits into
cheaper-inference:release/v3.8.24from
rdself:coder/thorough-clean-history

Conversation

@rdself

@rdself rdself commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Make the Request Logs "Clean history" action perform a full request-history purge instead of retention-only cleanup.
  • Clear call_logs, legacy request_detail_logs, and local JSON artifacts under DATA_DIR/call_logs, including orphaned artifact files.
  • Add a dedicated maintenance API route and update the Request Logs UI copy plus API/troubleshooting/compliance docs.

Testing

  • DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx --import ./open-sse/utils/setupPolyfill.ts --test tests/unit/database-settings-maintenance.test.ts
  • DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx --import ./open-sse/utils/setupPolyfill.ts --test tests/unit/call-log-file-rotation.test.ts
  • npm run check:openapi-routes
  • npm run check:fabricated-docs (exits 0; reports existing doc-drift warnings)
  • npm run typecheck:core
  • In-app browser smoke: logged in to /dashboard/logs, opened the Clean history confirmation, confirmed the destructive copy mentions DB rows, legacy detail rows, and DATA_DIR/call_logs, and observed the empty success state after confirmation.

Copilot AI review requested due to automatic review settings June 13, 2026 04:13
@rdself
rdself requested a review from diegosouzapw as a code owner June 13, 2026 04:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new “purge request history” capability that clears all request log DB rows (including legacy detail rows) and removes local call-log artifact files, wiring it into the Request Logs dashboard action and documenting the new endpoint.

Changes:

  • Implemented artifact-directory purge + “delete all call logs” helper and integrated it into DB cleanup.
  • Added POST /api/settings/purge-request-history route and updated the dashboard to call it and display results.
  • Added unit tests and updated docs/OpenAPI to reflect the new manual purge behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/unit/database-settings-maintenance.test.ts Adds test coverage for purging call logs, artifacts, and legacy detail rows via cleanup + new route.
src/lib/usage/callLogs.ts Introduces deleteAllCallLogs() that wipes call_logs and purges artifact directory.
src/lib/usage/callLogArtifacts.ts Adds purgeCallLogArtifactDirectory() which deletes ${DATA_DIR}/call_logs.
src/lib/db/cleanup.ts Updates purgeCallLogs() to also delete artifacts and report deletedArtifacts.
src/app/api/settings/purge-request-history/route.ts New endpoint that purges call logs + detailed logs and returns combined results.
src/app/api/settings/purge-call-logs/route.ts Extends existing response to include deletedArtifacts.
src/app/(dashboard)/dashboard/logs/page.tsx Switches “Clean history” to call the new endpoint and show detailed deletion counts.
docs/security/COMPLIANCE.md Documents manual request-history cleanup behavior and scope.
docs/reference/openapi.yaml Documents the new purge-request-history endpoint.
docs/reference/API_REFERENCE.md Adds the new endpoint to the settings endpoint table.
docs/guides/TROUBLESHOOTING.md Notes what the Request Logs “Clean history” action deletes.
docs/getting-started/TROUBLESHOOTING.md Same troubleshooting note for getting-started docs.

Comment thread src/lib/usage/callLogArtifacts.ts Outdated
Comment on lines +311 to +323
export function purgeCallLogArtifactDirectory(baseDir = CALL_LOGS_DIR) {
if (!baseDir || !fs.existsSync(baseDir)) return 0;

let deletedArtifacts = 0;
try {
deletedArtifacts = listCallLogArtifactFiles(baseDir).length;
} catch {
deletedArtifacts = 0;
}

fs.rmSync(baseDir, { recursive: true, force: true });
return deletedArtifacts;
}
Comment thread src/lib/usage/callLogs.ts Outdated
Comment on lines +510 to +519
export function deleteAllCallLogs(): DeleteResult {
const db = getDbInstance();
const result = db.prepare("DELETE FROM call_logs").run();
const deletedArtifacts = purgeCallLogArtifactDirectory();

return {
deletedRows: result.changes,
deletedArtifacts,
};
}
Comment on lines +1 to +6
import { NextResponse } from "next/server";
import { buildErrorBody } from "@omniroute/open-sse/utils/error";
import { purgeCallLogs, purgeDetailedLogs } from "@/lib/db/cleanup";
import { isAuthenticated } from "@/shared/utils/apiAuth";

export async function POST(request: Request) {
Comment on lines +1806 to +1818
/api/settings/purge-request-history:
post:
tags: [Settings]
summary: Clear request log history
description: Deletes `call_logs`, legacy `request_detail_logs`, and local request artifact files under `DATA_DIR/call_logs`.
security:
- ManagementSessionAuth: []
responses:
"200":
description: Request history cleared
"401":
description: Unauthorized

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new endpoint /api/settings/purge-request-history to permanently clear request log rows, legacy detail logs, and local call-log artifacts, updating the UI, documentation, and unit tests accordingly. The review feedback suggests localizing the hardcoded English status messages and modal properties on the logs page using the project's translation helper.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 81 to 87
setCleanHistoryStatus(
deleted || deletedArtifacts
? `Cleaned ${deleted} log entr${deleted === 1 ? "y" : "ies"} and ${deletedArtifacts} artifact${
deleted || deletedArtifacts || deletedDetailedLogs
? `Cleaned ${deleted} log entr${deleted === 1 ? "y" : "ies"}, ${deletedArtifacts} artifact${
deletedArtifacts === 1 ? "" : "s"
}.`
: "No expired log history needed cleanup."
}, and ${deletedDetailedLogs} legacy detail row${deletedDetailedLogs === 1 ? "" : "s"}.`
: "No request log history was found."
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The user-facing status messages for the clean history action are hardcoded in English. Since the project uses next-intl for internationalization (as seen by useTranslations("logs")), these strings should be localized using the translation helper t(...) with proper pluralization support to adhere to the project's i18n standards.

Suggested change
setCleanHistoryStatus(
deleted || deletedArtifacts
? `Cleaned ${deleted} log entr${deleted === 1 ? "y" : "ies"} and ${deletedArtifacts} artifact${
deleted || deletedArtifacts || deletedDetailedLogs
? `Cleaned ${deleted} log entr${deleted === 1 ? "y" : "ies"}, ${deletedArtifacts} artifact${
deletedArtifacts === 1 ? "" : "s"
}.`
: "No expired log history needed cleanup."
}, and ${deletedDetailedLogs} legacy detail row${deletedDetailedLogs === 1 ? "" : "s"}.`
: "No request log history was found."
);
setCleanHistoryStatus(
deleted || deletedArtifacts || deletedDetailedLogs
? t("cleanHistorySuccess", {
deleted,
deletedArtifacts,
deletedDetailedLogs
})
: t("noHistoryFound")
);

Comment on lines 202 to 205
title="Clean log history?"
message="This clears expired log history and prunes related artifacts using the current retention policy. The live page will refresh after cleanup."
message="This permanently clears all request log rows, legacy detail rows, and local artifact files under DATA_DIR/call_logs. The live page will refresh after cleanup."
confirmText="Clean history"
cancelText="Cancel"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ConfirmModal properties (title, message, confirmText, cancelText) are hardcoded in English. These should be localized using the t(...) translation helper to ensure consistent internationalization across the application.

Suggested change
title="Clean log history?"
message="This clears expired log history and prunes related artifacts using the current retention policy. The live page will refresh after cleanup."
message="This permanently clears all request log rows, legacy detail rows, and local artifact files under DATA_DIR/call_logs. The live page will refresh after cleanup."
confirmText="Clean history"
cancelText="Cancel"
title={t("cleanHistoryTitle")}
message={t("cleanHistoryMessage")}
confirmText={t("cleanHistoryConfirm")}
cancelText={t("cleanHistoryCancel")}

@kilo-code-bot

kilo-code-bot Bot commented Jun 13, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
docs/reference/openapi.yaml 1846 The 500 response schema for /api/settings/purge-request-history has error: type: object without required fields or properties. This is incomplete - the handler returns buildErrorBody() which produces { error: { message: string, type?: string, code?: string } }. Should reference #/components/schemas/ErrorResponse for proper documentation.

WARNING

File Line Issue
src/lib/usage/callLogArtifacts.ts 332 In purgeCallLogArtifactDirectory, when fs.rmSync fails, deletedArtifacts is reset to 0, losing the count that was computed before the attempted deletion. This makes it impossible to report how many files were supposed to be deleted.
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
src/app/api/settings/purge-call-logs/route.ts 20 The 500 response for /api/settings/purge-call-logs uses buildErrorBody() but the endpoint is not documented in openapi.yaml.
docs/reference/API_REFERENCE.md 416 The API reference documents /api/settings/purge-request-history but the OpenAPI spec (openapi.yaml) does not document /api/settings/purge-call-logs which also exists. Documentation asymmetry.
Files Reviewed (9 files)
  • docs/reference/openapi.yaml - 1 issue
  • src/lib/usage/callLogArtifacts.ts - 1 issue
  • src/lib/db/cleanup.ts
  • src/app/api/settings/purge-call-logs/route.ts
  • src/app/api/settings/purge-request-history/route.ts
  • src/app/(dashboard)/dashboard/logs/page.tsx
  • src/i18n/messages/en.json
  • tests/unit/database-settings-maintenance.test.ts
  • docs/reference/API_REFERENCE.md

@diegosouzapw
diegosouzapw changed the base branch from main to release/v3.8.24 June 13, 2026 04:39
type: integer
errors:
type: integer
error:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: Incomplete 500 response schema - the error object lacks required properties (message, type, code) that buildErrorBody returns. Should reference #/components/schemas/ErrorResponse

fs.rmSync(baseDir, { recursive: true, force: true });
} catch (error) {
console.error("[callLogArtifacts] Failed to purge call log artifacts:", error);
result.deletedArtifacts = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Lost count on deletion failure - deletedArtifacts reset to 0 when fs.rmSync fails, losing the count computed before deletion attempt

@kilo-code-bot

kilo-code-bot Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

Severity Count
CRITICAL 1
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
docs/reference/openapi.yaml 1846 The 500 response schema has error: type: object without defining required properties (message, type, code). The handler returns buildErrorBody() which produces { error: { message: string, type?: string, code?: string } }. Should reference #/components/schemas/ErrorResponse for proper documentation.

WARNING

File Line Issue
src/lib/usage/callLogArtifacts.ts 332 In purgeCallLogArtifactDirectory, when fs.rmSync fails, deletedArtifacts is reset to 0, losing the count computed before the attempted deletion. This makes it impossible to report how many files were supposed to be deleted.
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
src/app/api/settings/purge-call-logs/route.ts 20 The 500 response uses buildErrorBody() but this endpoint is not documented in openapi.yaml, creating documentation asymmetry.
docs/reference/API_REFERENCE.md 416 purge-request-history is documented but /api/settings/purge-call-logs is missing from the API reference.
Files Reviewed (9 files)
  • docs/reference/openapi.yaml - 1 issue
  • src/lib/usage/callLogArtifacts.ts - 1 issue
  • src/lib/db/cleanup.ts
  • src/app/api/settings/purge-call-logs/route.ts
  • src/app/api/settings/purge-request-history/route.ts
  • src/app/(dashboard)/dashboard/logs/page.tsx
  • src/i18n/messages/en.json
  • tests/unit/database-settings-maintenance.test.ts
  • docs/reference/API_REFERENCE.md

Reviewed by laguna-m.1-20260312:free · 3,223,735 tokens

@diegosouzapw
diegosouzapw merged commit 15ab183 into cheaper-inference:release/v3.8.24 Jun 13, 2026
1 check passed
@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks @rdself! 🙌 Merged into release/v3.8.24. The old Clean history was retention-only despite the wording, so making it a true purge (DB rows + legacy detail rows + on-disk DATA_DIR/call_logs artifacts, orphans included) matches the user's expectation — and the updated confirmation copy makes the destructive scope explicit. Bonus: routing the legacy purge route through buildErrorBody closes a latent Rule #12 leak. Solid TDD on both the artifact purge and the full route. Will ship in the upcoming release.

diegosouzapw added a commit that referenced this pull request Jun 13, 2026
…contributor credits

- Restructure [3.8.24] into ✨ Features / 🔒 Security / 🐛 Fixed / 📝 Maintenance
- Add bullets for every PR landed since v3.8.23 that was missing:
  marketplace (#3656), strict-mode CC defaults (#3776), emergency-fallback flag (#3752),
  xhigh effort (#3756), Codex memory WS (#3749), IPv6 egress (#3777),
  marketplace SSRF (#3774), CodeQL/Dependabot (#3778), anthropic sampling (#3780),
  thinking passthrough (#3775), mcp dist entry (#3765), streamed tool args (#3762),
  logs light-mode (#3760), clean-history purge (#3751), quality-gates (#3757),
  docs gaps (#3453), file-size re-baseline (#3770), E415 publish guard, i18n prune
- Move misplaced #3775 bullet out of [Unreleased] into [3.8.24]
- Date [3.8.23] header (TBD -> 2026-06-12, the release tag date)
@diegosouzapw diegosouzapw mentioned this pull request Jun 13, 2026
@rdself
rdself deleted the coder/thorough-clean-history branch June 24, 2026 03:25
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
Make the Request Logs Clean history action a full request-history purge instead of retention-only: clears call_logs, legacy request_detail_logs, and local JSON artifacts under DATA_DIR/call_logs (including orphans), via a dedicated POST /api/settings/purge-request-history route. Also hardens the legacy purge-call-logs route to route errors through buildErrorBody (Rule cheaper-inference#12). Integrated into release/v3.8.24.
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…contributor credits

- Restructure [3.8.24] into ✨ Features / 🔒 Security / 🐛 Fixed / 📝 Maintenance
- Add bullets for every PR landed since v3.8.23 that was missing:
  marketplace (cheaper-inference#3656), strict-mode CC defaults (cheaper-inference#3776), emergency-fallback flag (cheaper-inference#3752),
  xhigh effort (cheaper-inference#3756), Codex memory WS (cheaper-inference#3749), IPv6 egress (cheaper-inference#3777),
  marketplace SSRF (cheaper-inference#3774), CodeQL/Dependabot (cheaper-inference#3778), anthropic sampling (cheaper-inference#3780),
  thinking passthrough (cheaper-inference#3775), mcp dist entry (cheaper-inference#3765), streamed tool args (cheaper-inference#3762),
  logs light-mode (cheaper-inference#3760), clean-history purge (cheaper-inference#3751), quality-gates (cheaper-inference#3757),
  docs gaps (cheaper-inference#3453), file-size re-baseline (cheaper-inference#3770), E415 publish guard, i18n prune
- Move misplaced cheaper-inference#3775 bullet out of [Unreleased] into [3.8.24]
- Date [3.8.23] header (TBD -> 2026-06-12, the release tag date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants