Skip to content

fix(logs): raise in-memory log buffer and support limit/offset - #784

Merged
Wibias merged 15 commits into
lidge-jun:devfrom
Wibias:fix/726-log-pagination
Jul 31, 2026
Merged

fix(logs): raise in-memory log buffer and support limit/offset#784
Wibias merged 15 commits into
lidge-jun:devfrom
Wibias:fix/726-log-pagination

Conversation

@Wibias

@Wibias Wibias commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #726

Raises in-memory log buffer and adds limit/offset support for log pagination.

Test plan

  • bun run typecheck
  • bun run test

Summary by CodeRabbit

  • New Features

    • Expanded request-log retention to 2,000 entries.
    • Added pagination and filtered total counts to the logs API.
    • Logs responses now include the time zone, total matching records, and log entries.
  • Bug Fixes

    • Improved stacked pull request base-repository validation.
  • Documentation

    • Updated logs API guidance across English, Japanese, Korean, Russian, and Simplified Chinese documentation.
  • Tests

    • Added coverage for pagination, retention limits, response validation, and the updated logs response format.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR expands request-log retention to 2,000 entries, adds filtered pagination and envelope responses to /api/logs, updates consumers and tests, corrects stacked PR base validation, and adds injectable GitHub star dependencies for test isolation.

Changes

Request-log pagination API

Layer / File(s) Summary
Request-log retention and pagination
src/server/request-log.ts, src/server/management/logs-usage-routes.ts, tests/request-log.test.ts, tests/management-api-logs-metrics.test.ts
The buffer stores up to 2,000 entries. Filtered reads support limit and offset. The endpoint returns { timeZone, total, logs }, with total calculated before pagination.
Dashboard and documentation contract
gui/src/pages/Logs.tsx, docs-site/src/content/docs/.../web-dashboard.md
The dashboard requests up to 2,000 logs and accepts array or wrapped responses. The localized guides document pagination and the response envelope.
Shared response parsing and test coverage
tests/helpers/logs-api.ts, tests/*
logsFromApiBody normalizes legacy arrays and wrapped responses. Log assertions validate the new response contract across management, timezone, provider, authentication, permission, and failover tests.

Stacked PR target validation

Layer / File(s) Summary
Stacked base repository comparison
.github/workflows/enforce-pr-target.yml, .github/scripts/enforce-pr-target.test.cjs
The workflow compares the other open PR’s base repository owner and name. The test verifies access to the optional base repository owner.

GitHub star test isolation

Layer / File(s) Summary
Star dependency override and route test wiring
src/github/star-state.ts, tests/sidebar-routes.test.ts
Star-state operations resolve injectable dependencies. Changing the override invalidates cached state. Sidebar route tests use a failing fake gh runner and reset the override after each test.

Test runtime adjustment

Layer / File(s) Summary
Legacy restore test timeout
tests/storage-cleanup.test.ts
The compressed-only legacy quarantine restore test uses a 20-second timeout.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: ingwannu, lidge-jun

Sequence Diagram(s)

sequenceDiagram
  participant LogsPage
  participant LogsEndpoint
  participant RequestLog
  LogsPage->>LogsEndpoint: GET /api/logs?limit=2000
  LogsEndpoint->>RequestLog: Apply filters and pagination
  RequestLog-->>LogsEndpoint: Return logs and pre-pagination total
  LogsEndpoint-->>LogsPage: Return timeZone, total, logs
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Several changes are unrelated to issue #726, including GitHub star dependency injection, PR target enforcement, storage timeout changes, and related test updates. Remove unrelated GitHub star, PR target enforcement, storage timeout, and associated test changes, or link issues that explicitly require them.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main changes: increasing the log buffer and adding limit/offset pagination.
Linked Issues check ✅ Passed The changes increase retention to 2,000 logs, add filtered totals and limit/offset pagination, update the frontend parser, and document the new API contract for issue #726.
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch fix/726-log-pagination
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7e59c02a9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server/request-log.ts Outdated
Comment thread src/server/management/logs-usage-routes.ts
Comment thread src/server/management/logs-usage-routes.ts Outdated
Comment thread src/server/request-log.ts
@github-actions github-actions Bot added the bug Something isn't working label Jul 30, 2026
@Wibias

Wibias commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

[shipping-github] Merge-ready

CI green after log-pagination test fixes + fork-stacked enforce-target prep (macOS/Windows/ubuntu). Stacks nothing; land before #790.

Fixes #726.

Wibias added 2 commits July 31, 2026 02:11
Align limit/offset with tail semantics, report filtered total before pagination, and document the logs response shape in the dashboard guide.
Keep upstream useDataSurface loader shape while requesting limit=2000
and parsing the {logs} envelope.
@Wibias

Wibias commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Verdict: approve-comment

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/scripts/enforce-pr-target.test.cjs:
- Line 68: Add behavioral assertions to the stacked-PR tests around the
fixture’s distinct base/head owners, verifying the matching-owner case and a
mismatched-owner negative case. Exercise the workflow decision rather than only
checking its source text, so the owner from other.base?.repo?.owner is confirmed
to participate in the repository-boundary comparison.

In `@gui/src/pages/Logs.tsx`:
- Around line 367-370: Update the log refresh flow around the fetch and body
parsing to request only a bounded newest page rather than all 2,000 entries.
Preserve the response envelope metadata, use total to determine whether older
pages remain, fetch them with offset-based pagination on demand, and merge
results by requestId while keeping management API state consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f3292994-a66a-4a4b-8687-86b5ca5f1b40

📥 Commits

Reviewing files that changed from the base of the PR and between 3569242 and c27e4ad.

📒 Files selected for processing (20)
  • .github/scripts/enforce-pr-target.test.cjs
  • .github/workflows/enforce-pr-target.yml
  • docs-site/src/content/docs/guides/web-dashboard.md
  • docs-site/src/content/docs/ja/guides/web-dashboard.md
  • docs-site/src/content/docs/ko/guides/web-dashboard.md
  • docs-site/src/content/docs/ru/guides/web-dashboard.md
  • docs-site/src/content/docs/zh-cn/guides/web-dashboard.md
  • gui/src/pages/Logs.tsx
  • src/server/management/logs-usage-routes.ts
  • src/server/request-log.ts
  • tests/claude-messages-endpoint.test.ts
  • tests/claude-native-passthrough.test.ts
  • tests/helpers/logs-api.ts
  • tests/management-api-logs-metrics.test.ts
  • tests/openai-api-virtual-models.test.ts
  • tests/openai-provider-option-e2e.test.ts
  • tests/request-log.test.ts
  • tests/server-403-permission-e2e.test.ts
  • tests/server-auth.test.ts
  • tests/server-combo-failover-e2e.test.ts

Comment thread .github/scripts/enforce-pr-target.test.cjs
Comment thread gui/src/pages/Logs.tsx
Wibias added 2 commits July 31, 2026 05:09
Windows runners honor Path over PATH, so the release-helper fakes never
ran and preflight saw the real branch instead of the faked main.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/release-helper.test.ts (1)

340-352: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Strengthen the launcher-bypass assertion

The release script uses Bun.spawn at scripts/release.ts:51 and scripts/release.ts:92, but both current calls correctly use commandInvocation. The test at tests/release-helper.test.ts:340-351 only checks that commandInvocation appears somewhere, so an additional unwrapped Bun.spawn, spawn, or execFile call would still pass.

Assert that every external-command path uses the shared launcher. A focused solution is to inject the launcher or assert that each Bun.spawn receives the commandInvocation result, while preserving direct spawning as the transport after resolution.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/release-helper.test.ts` around lines 340 - 352, The test around “every
external command goes through the shared launcher” is too weak because it only
checks that commandInvocation appears somewhere. Strengthen it to verify each
external-command invocation, including Bun.spawn, spawn, or execFile paths,
receives the result of commandInvocation while preserving direct spawning as the
transport after resolution.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@tests/release-helper.test.ts`:
- Around line 340-352: The test around “every external command goes through the
shared launcher” is too weak because it only checks that commandInvocation
appears somewhere. Strengthen it to verify each external-command invocation,
including Bun.spawn, spawn, or execFile paths, receives the result of
commandInvocation while preserving direct spawning as the transport after
resolution.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1ca680ec-88a3-4e58-a976-9ef6cb7f65ce

📥 Commits

Reviewing files that changed from the base of the PR and between c27e4ad and 51d9c56.

📒 Files selected for processing (1)
  • tests/release-helper.test.ts

Wibias added 2 commits July 31, 2026 06:03
Keep the upstream single Path-key shim env so Windows release-helper tests hit the fake git.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/release-helper.test.ts`:
- Around line 195-221: Resolve the conflict in the test setup around the
release-helper spawn configuration by removing all conflict markers and
retaining the inheritedEnv implementation. Keep the case-insensitive PATH
filtering, platform-specific pathKey selection, and resulting pathValue
assignment so the child process receives exactly one PATH variant.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 151220b5-9ba6-4cae-bb57-7315d8e708c0

📥 Commits

Reviewing files that changed from the base of the PR and between 51d9c56 and ca8c5d3.

📒 Files selected for processing (1)
  • tests/release-helper.test.ts

Comment thread tests/release-helper.test.ts Outdated
Wibias added 2 commits July 31, 2026 08:19
Merging current dev brought in a bare-array assertion that conflicts with
lidge-jun#726's {timeZone,total,logs} response shape.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
tests/logs-timezone.test.ts (1)

43-82: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Bind the regression test to the production formatter.

Lines 48-54 reimplement formatLogTimestamp. The assertions at Lines 61-80 call only this copy. A regression in gui/src/pages/Logs.tsx Lines 663 or 824 that stops passing serverTimeZone would still pass. The production formatLogDateTime path is also not covered.

Extract both pure formatters into a dependency-free module imported by gui/src/pages/Logs.tsx and this test, or add a GUI component test that renders the production path.

As per path instructions, the source behavior change needs a focused regression test that exercises the production implementation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/logs-timezone.test.ts` around lines 43 - 82, Replace the local
formatLogTimestamp test helper with coverage of the production formatter in
gui/src/pages/Logs.tsx, preferably by extracting formatLogDateTime and the
timestamp formatter into a dependency-free shared module imported by both
production code and this test. Ensure the regression assertions exercise the
serverTimeZone propagation and fallback behavior through the production
implementation, including the formatLogDateTime path.

Source: Path instructions

gui/src/pages/Logs.tsx (1)

357-377: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Clear serverTimeZone when apiBase changes.

If apiBase changes while Logs remains mounted, the previous zone stays in state until a new valid value arrives. If the new /api/settings request fails or omits timeZone, logs from the new server use the previous server's zone.

Reset the state at effect start. Also ignore completions from an obsolete effect.

Proposed fix
   useEffect(() => {
     const controller = new AbortController();
+    let active = true;
+    setServerTimeZone(undefined);
     void (async () => {
       try {
         const res = await fetch(`${apiBase}/api/settings`, { signal: controller.signal });
         if (!res.ok) return;
         const body = await res.json() as { timeZone?: unknown };
-        if (typeof body.timeZone === "string" && body.timeZone.trim()) {
+        if (active && typeof body.timeZone === "string" && body.timeZone.trim()) {
           setServerTimeZone(body.timeZone.trim());
         }
       } catch {
         // Offline or an older proxy without the field: keep browser-local formatting.
       }
     })();
-    return () => controller.abort();
+    return () => {
+      active = false;
+      controller.abort();
+    };
   }, [apiBase]);

As per path instructions, GUI state must stay consistent with the active management API response.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@gui/src/pages/Logs.tsx` around lines 357 - 377, Update the serverTimeZone
effect to clear the existing zone when apiBase changes, before starting the
settings request. Ensure asynchronous completions from obsolete effects cannot
update state after cleanup, while preserving browser-local formatting when the
new request fails or omits timeZone.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@gui/src/pages/Logs.tsx`:
- Around line 357-377: Update the serverTimeZone effect to clear the existing
zone when apiBase changes, before starting the settings request. Ensure
asynchronous completions from obsolete effects cannot update state after
cleanup, while preserving browser-local formatting when the new request fails or
omits timeZone.

In `@tests/logs-timezone.test.ts`:
- Around line 43-82: Replace the local formatLogTimestamp test helper with
coverage of the production formatter in gui/src/pages/Logs.tsx, preferably by
extracting formatLogDateTime and the timestamp formatter into a dependency-free
shared module imported by both production code and this test. Ensure the
regression assertions exercise the serverTimeZone propagation and fallback
behavior through the production implementation, including the formatLogDateTime
path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9758626a-ea5d-4f56-99a9-79e1fe1b1744

📥 Commits

Reviewing files that changed from the base of the PR and between ca8c5d3 and 0afd2d6.

📒 Files selected for processing (2)
  • gui/src/pages/Logs.tsx
  • tests/logs-timezone.test.ts

Wibias added 2 commits July 31, 2026 09:21
Route tests were spawning real gh.cmd and burning AUTH_TIMEOUT equal to
Bun's 5s deadline. Inject a fast fake via setStarDepsForTests, and give
the slow compressed trash restore 20s on Windows CI.
Resolve star-state and sidebar-routes conflicts by taking tip's
setStarDepsForTests / withStarDeps approach (supersedes this branch's
Windows gh hang workaround).
@Wibias

Wibias commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

[shipping-github] Addressed wake-gate DIRTY — merged upstream dev into fix/726-log-pagination. Kept tip setStarDepsForTests / withStarDeps for star-state + sidebar-routes (supersedes this branch's Windows gh hang workaround). Typecheck + focused logs/sidebar/auth tests green locally.

Wibias added 2 commits July 31, 2026 09:59
Give version --help and status --json spawnSync cases 20s so late-suite
Windows runners do not fail the 5s Bun default after a full suite.
@Wibias

Wibias commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Merging this.

Why it helps: dashboard /api/logs was hard-capped at 200 in-memory entries with no pagination, so conversation filters and stats looked incomplete (#726). This raises the buffer to 2,000, adds newest-first limit/offset with a filtered otal, and returns {timeZone,total,logs} so the GUI and docs can page correctly.

Ship it.

@Wibias
Wibias merged commit cd46a34 into lidge-jun:dev Jul 31, 2026
11 checks passed
@Wibias
Wibias deleted the fix/726-log-pagination branch July 31, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant