Repository navigation
fix(logging): keep logs.tail cost proportional to the window - #172885
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
|
Codex review: needs maintainer review before merge. What this changesThis PR caches complete-record PEM context between log polls and restores the default redaction prefilter. Example: Incremental polling of a 79 MB Gateway log after appending 32 records.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses a verified logging performance problem with maintainer-approved scope, and source review found no definite introduced bug. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe shared log-tail reader reads configured raw log files, selects complete records, applies credential redaction, and returns lines with byte cursors to Gateway RPC, CLI, and diagnostic consumers. flowchart LR
A[Raw Gateway log] --> B[Log tail reader]
C[Cursor and window limits] --> B
D[Process context anchor] --> B
B --> E[Record and batch redaction]
E --> F[Lines and byte cursor]
F --> G[Gateway CLI and diagnostics]
Technical reviewBest possible solution: Retain the shared reader optimization while preserving complete-record cursors and existing egress masking. Do we have a high-confidence way to reproduce the issue? Current-main source scans backward to byte zero when no PEM delimiter resolves context and loses default-array identity during normalization; the body supplies comparative benchmarks, but this review executed no target code. Is this the best way to solve the issue? The optimization stays within the existing reader and matcher owners, preserves masking and cursor contracts, and uses a bounded process cache with explicitly accepted invalidation limits. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f3f61f8474f8. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +86, Tests +135. Total +221 across 5 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 15, 2026, 3:29 AM ET / 07:29 UTC. |
ada13be to
051ea25
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 051ea251ea
ℹ️ 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".
| redactionAnchor = { | ||
| file, | ||
| dev: contextStat.dev, | ||
| ino: contextStat.ino, | ||
| offset: cursor, | ||
| states, | ||
| }; |
There was a problem hiding this comment.
Retain anchors for concurrent tail cursors
When two Control UI clients poll the same growing log at different times, both start an interval at cursor C; the first request publishes C′ here, so the second request rejects the sole cached anchor because C′ is greater than its contextStart C and falls back to scanning from byte zero. Since every request overwrites this single slot, one client can repeat the full-file scan every two seconds, preserving the Gateway stalls this change is intended to remove. The Gateway exposes this function process-wide to every logs.tail client (src/gateway/server-methods/logs.ts:15), while each Logs page polls independently (ui/src/pages/logs/logs-page.tsx:36,83), so retain usable anchors for multiple cursor offsets rather than only the latest one.
AGENTS.md reference: AGENTS.md:L74-L74
Useful? React with 👍 / 👎.
Cache the PEM open/closed state at the last returned cursor per (file, dev, ino) so incremental polls scan only new bytes instead of walking back to byte 0, and restore default-pattern identity in redactSensitiveLines so the transport redactor's prefilter applies again. Refs #172507
051ea25 to
9a3d765
Compare
|
Merged via squash auto-merge.
|
Cache the PEM open/closed state at the last returned cursor per (file, dev, ino) so incremental polls scan only new bytes instead of walking back to byte 0, and restore default-pattern identity in redactSensitiveLines so the transport redactor's prefilter applies again. Refs #172507 (cherry picked from commit 1541902)
…w#172885) Cache the PEM open/closed state at the last returned cursor per (file, dev, ino) so incremental polls scan only new bytes instead of walking back to byte 0, and restore default-pattern identity in redactSensitiveLines so the transport redactor's prefilter applies again. Refs openclaw#172507
Cache the PEM open/closed state at the last returned cursor per (file, dev, ino) so incremental polls scan only new bytes instead of walking back to byte 0, and restore default-pattern identity in redactSensitiveLines so the transport redactor's prefilter applies again. Refs #172507 (cherry picked from commit 1541902)
Related: #172507
What Problem This Solves
Fixes: the Control UI Logs page slows down and stalls the Gateway as the day's log file grows. Every 2-second poll rescanned the whole log file and re-redacted the tail without its fast path. On a 79 MB log, each poll took about 350–475 ms of Gateway main-thread time.
User Impact
User impact: leaving the Logs page open costs a few milliseconds per poll no matter how large the daily log is. Gateway responsiveness no longer gets worse over the day. Redaction output is unchanged.
Why This Change Was Made
logs.tailnow caches one anchor: the last complete-record cursor plus whether a PEM block is open there, keyed by file, device and inode. The backward scan stops at the anchor, and the state is carried forward across the window with the existing delimiter scanner. Incremental polls therefore read only new bytes.statandopen.log-taildoes not special-case PEM.redactSensitiveLinesregression. Since the 10.3 redaction rewrite this was about 3x slower than v2026.10.1. Normalizing the PEM pattern built a new pattern array. The transport redactor only uses its built-in prefilter when it gets the exact default array, so the copy turned the prefilter off. The default array is now passed back when the patterns match it one for one.Evidence
Benchmark: a real 8.8 MB Gateway JSON log and a 79 MB concatenation of it. Calls use
readConfiguredLogTail({limit:500,maxBytes:250000}), then 10 incremental polls that each append 32 records. Three interleaved runs on a loaded host:redactSensitiveLineson a real 250 KB, 370-line tail, 30 runs, median thread CPU: v2026.10.1 25.5 ms, main 95.6 ms, this PR 46.0 ms.visitRedactMatchesat 72.9% total.visitRedactMatchesdrops to 0.8% after the fix.Regression tests at the
readConfiguredLogTailboundary:statandopenLocal commands:
pnpm test src/logging/redact*.test.ts src/logging/log-tail*.test.ts src/logging/logger-redaction-behavior.test.ts src/logging/diagnostic-support-redaction.test.ts src/logging/redacting-stream.test.ts(180 passed),pnpm tsgo, oxfmt,git diff --check.CI: the
checks-ui-e2efailures are inherited from main at that time, not caused by this PR.session-management.sidebar"nests spawned sessions",session-management.promotion, andsidebar-agent-firstgeometry.src/logging/redact-patterns.ts, which this PR does not change.