Skip to content

fix: allow clearing logs without request body#2813

Open
pg-adm1n wants to merge 1 commit into
thedotmack:mainfrom
pg-adm1n:replicate-pr-2675-fix
Open

fix: allow clearing logs without request body#2813
pg-adm1n wants to merge 1 commit into
thedotmack:mainfrom
pg-adm1n:replicate-pr-2675-fix

Conversation

@pg-adm1n

@pg-adm1n pg-adm1n commented Jun 6, 2026

Copy link
Copy Markdown

Summary

  • Allow POST /api/logs/clear to run without a request body, matching the viewer's clear request.
  • Keep the existing Log file cleared via UI audit log entry after a successful clear.
  • Add regression coverage for the bodyless clear request.

Reproduction

  1. Start the local claude-mem viewer and open the Console drawer.
  2. Click the trash / clear logs button.
  3. Confirm the clear action.

Before this change, the viewer showed Failed to clear logs: Bad Request and the log file was not truncated.

Root Cause

The viewer calls authFetch('/api/logs/clear', { method: 'POST' }) without a body. The route previously wrapped the handler in validateBody(z.object({}).passthrough()), so req.body === undefined failed validation and returned 400 Bad Request before the log file was truncated.

Expected Behavior

The bodyless clear request should return success and remove the previous log contents. The route still records the existing Log file cleared via UI audit entry after a successful clear.

Validation

  • bun test tests/services/logs-routes-tail-read.test.ts

This replaces #2674 with a narrower patch focused only on the bodyless clear request.

@pg-adm1n

pg-adm1n commented Jun 6, 2026

Copy link
Copy Markdown
Author

Hi @thedotmack, I accidentally closed the previous PR #2675 due to a misoperation. This is the new PR replicating the exact changes. Please let me know when you have time to review and merge this. Thanks!

@greptile-apps

greptile-apps Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes the POST /api/logs/clear endpoint failing with 400 Bad Request when the viewer's clear button issued the request without a body. The root cause was a validateBody(z.object({}.passthrough())) middleware guard that rejected req.body === undefined.

  • LogsRoutes.ts: Drops the validateBody middleware and its associated Zod schema from the clear route; cleans up the now-unused express, z, and validateBody imports.
  • tests/services/logs-routes-tail-read.test.ts: Adds two regression tests — one confirming the log file is truncated on a bodyless POST, one covering the no-file-exists path.
  • create-server-beta-service.ts: Removes a duplicate ModeManager import introduced in an earlier commit.

Confidence Score: 5/5

Safe to merge — the change is a targeted middleware removal on a single non-destructive endpoint, backed by new regression tests.

The fix is a one-line route registration change (drop a validation middleware that was rejecting valid bodyless requests). The handler itself is unchanged, the audit log entry is preserved, and two new tests directly exercise the repaired path. No other routes or shared logic are touched.

No files require special attention.

Important Files Changed

Filename Overview
src/services/worker/http/routes/LogsRoutes.ts Removed the validateBody(clearLogsSchema) middleware from POST /api/logs/clear so the handler accepts requests without a body; cleaned up unused express, z, and validateBody imports.
tests/services/logs-routes-tail-read.test.ts Added two regression tests for the bodyless clear request: one verifying the log file is truncated, and one verifying graceful handling when the file does not exist yet.
src/server/runtime/create-server-beta-service.ts Removed a duplicate ModeManager import that appeared twice in the base file; the symbol is still imported at the top of the file and is used by loadServerBetaMode and createServerBetaService.
plugin/scripts/context-generator.cjs Rebuilt minified plugin bundle; reflects upstream source changes.

Sequence Diagram

sequenceDiagram
    participant Viewer as Viewer UI
    participant Express as Express App
    participant VB as validateBody middleware (removed)
    participant Handler as handleClearLogs

    Note over Viewer,Handler: Before this PR (broken path)
    Viewer->>Express: POST /api/logs/clear (no body)
    Express->>VB: "req.body === undefined"
    VB-->>Viewer: 400 Bad Request

    Note over Viewer,Handler: After this PR (fixed path)
    Viewer->>Express: POST /api/logs/clear (no body)
    Express->>Handler: req (body ignored)
    Handler->>Handler: writeFileSync(logFile, '')
    Handler->>Handler: logger.info(Log file cleared via UI)
    Handler-->>Viewer: "200 { success: true, message: Log file cleared }"
Loading

Reviews (2): Last reviewed commit: "fix: allow clearing logs without request..." | Re-trigger Greptile

@pg-adm1n pg-adm1n force-pushed the replicate-pr-2675-fix branch from e19bad2 to e8982e1 Compare June 6, 2026 15:33
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.

1 participant