fix(anolisa): tail logs --limit to recent matches - #2618
Conversation
anolisa logs defaulted to the first 50 JSONL hits, so a growing central log hid every later operation. Keep a sliding window of the most recent matches (still oldest-first), matching anolisa bug. Co-authored-by: Cursor <cursoragent@cursor.com> Assisted-by: Cursor:2026.08.11-e8db854 Signed-off-by: zyw02 <zyw02@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 03ee051aa8
ℹ️ 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".
kongche-jbw
left a comment
There was a problem hiding this comment.
Review baseline: 435951fc25da0ca48cab9bc78924c51179d7200a...03ee051aa85571c9a371f5cfa33576e0baf8173c
[P2] 避免在完整历史扫描期间持有日志锁
src/anolisa/crates/anolisa-core/src/central_log.rs:288 把原先的 break
改为 pop_front 后,任何带 limit 的查询(CLI 默认 50)都要反序列化整个无界
JSONL。查询全程持有共享 flock,而 append 需要独占锁;大日志上运行
anolisa logs 会让并发审计写入等待 O(file-size) 扫描结束。
Possible direction: 在锁内取得稳定文件长度后释放锁并只读该前缀,或从尾部按完整行
反向扫描;补充受控并发测试,证明长历史尾查询不会在整个扫描期间阻塞 append。
[P2] 同步更新 query 的公开契约
src/anolisa/crates/anolisa-core/src/central_log.rs:230 仍写着 limit 保留
“first N”,但同文件的 LogFilter.limit 已改为“most recent N”。库调用方会看到
相反的公开契约,并可能据此写出错误预期。
Possible direction: 更新方法 rustdoc,并用一个 3 条记录、limit=2 的 doctest 固化
返回后两条且保持文件顺序的契约。
Review flagged a stale first-N query rustdoc and a shared flock held for the whole JSONL deserialize. Snapshot a stable length under the lock, scan that prefix unlocked, and document most-recent N. Co-authored-by: Cursor <cursoragent@cursor.com> Assisted-by: Cursor:2026.08.11-e8db854 Signed-off-by: zyw02 <zyw02@users.noreply.github.com>
|
@kongche-jbw both P2s on
Validation: Please re-review this head. |
kongche-jbw
left a comment
There was a problem hiding this comment.
Review baseline: 435951fc25da0ca48cab9bc78924c51179d7200a...568ce67915cc47cb3697607639b8e8629bc764ee
[P2] 移除锁回归测试的墙钟竞态
src/anolisa/crates/anolisa-core/src/central_log.rs:984
这里只等待 5 ms 就假定查询已完成快照并进入扫描;若查询线程尚未被调度,
append 会先写入,查询便把新记录纳入快照,最终记录断言会随机失败。
同时,250 ms 的墙钟上限会把繁忙 CI 上的调度停顿误判为锁等待。
Possible direction: 用测试钩子或屏障确认 query 已越过 unlock 并暂停扫描,
再断言 append 在释放扫描屏障前完成;移除固定 sleep 和性能阈值,保留同一路径的回归覆盖。
The overlap test slept 5ms then treated a 250ms append as lock contention, so scheduling delay could fail CI. Park query after unlock with a condvar so append finishes before the scan resumes. Co-authored-by: Cursor <cursoragent@cursor.com> Assisted-by: Cursor:2026.08.11-e8db854 Signed-off-by: zyw02 <zyw02@users.noreply.github.com>
|
@kongche-jbw the P2 on
Validation: Please re-review this head. |
kongche-jbw
left a comment
There was a problem hiding this comment.
Review baseline: 435951fc25da0ca48cab9bc78924c51179d7200a...b74a25d96e55e055a1823140f5e132a71b282d99
未发现阻塞问题。
Remaining risks:
- 未运行全量
cargo test --locked;并发文件锁只在 Linux/aarch64 环境验证,未覆盖 macOS。 - PR 当前仅显示 CLA 检查,尚无仓库 CI 结果可供交叉核验。
Verification scope:
- 已复查完整 diff、相邻实现与测试,以及全部 conversation、review、inline thread 和 timeline。
cargo fmt --all -- --checkcargo test --locked -p anolisa-core --lib central_logcargo test --locked -p anolisa-core --doccargo test --locked -p anolisa-cli query_combined_filter_honors_zero_and_one_limitscargo clippy --all-targets --locked -- -D warningscargo doc --workspace --no-depslimited_query_releases_lock_before_scanning_history重复运行 50/50 通过。
ikunkun-sys
left a comment
There was a problem hiding this comment.
Review baseline: d80cd127c0f64133ad9d8277e51792d3fa36b2b9...b74a25d96e55e055a1823140f5e132a71b282d99 (synthetic merge 24c5419d6a8ccf9eca8592c45e0dd18ed641e96d)
[P2] 按仓库规则整理 fix 归因与提交历史
AGENTS.md:382-387
03ee051a 修复了 main 上 7a6e0d72 引入的 first-N 行为,但其 trailers 中没有必需的 Fixes:。随后 568ce679 修复 03ee051a 引入的锁窗口/文档问题,b74a25d9 又修复 568ce679 引入的测试竞态;这两个 review follow-up 仍是独立的 fix commits。
这与仓库规则冲突:main 上已有缺陷需要正确的 Fixes: 归因,同一 PR 内引入的问题必须 fixup/autosquash,不能保留独立 fix commit。当前最终代码行为验证通过,但合并前仍需补齐归因并整理为原子提交历史。
Verification: Rust 1.88.0、Linux x86_64 的 synthetic merge 上,workspace fmt、Clippy、docs、cargo test --workspace --locked 均通过;锁重叠测试重复 50/50 通过。
ikunkun-sys
left a comment
There was a problem hiding this comment.
Review baseline: b74a25d96e55e055a1823140f5e132a71b282d99 (unchanged since review #4956800515)
Requesting changes for the verified blocking item from that review:
[P2] 按仓库规则整理 fix 归因与提交历史
03ee051a 修复 main 上 7a6e0d72 引入的缺陷,但没有 Fixes:;568ce679 和 b74a25d9 又作为独立 fix commits 修复本 PR 前序提交引入的问题。该历史仍违反 AGENTS.md:382-387 的强制归因与 autosquash 规则。
当前代码验证和远端 CI 均已通过;本次 request changes 只阻塞上述提交历史问题。
Why
anolisa logscapped the central JSONL scan at the first N matches (default 50). Once the log grew, later operations disappeared from the default view.anolisa bugalready kept the newest rows; logs should use the same tail window so operators see the failure that just happened.What changed
CentralLog::querykeeps a sliding window of the most recent filter matches instead of stopping at the first N. Results stay chronological (oldest of that window first).querytakes a shared flock only long enough to snapshot a stable file length, then scans that prefix without holding the lock so a default--limittail does not block concurrentappendfor an O(file-size) deserialize.limited_query_releases_lock_before_scanning_historyparks after unlock, completesappendwhile the scan is still parked, then resumes; the snapshot must not include that concurrent write.--limitis documented as the most recent N (still max 1000; 0 returns none).CentralLog::querymatchesLogFilter.limit(most recent N, file order). A doctest locks 3 records / limit=2 → last two, oldest-first.query_limit_applies_after_filterexpects the last two warn-or-above records;query_limit_tails_matches_inside_since_windowtails inside--since; CLI combined-filter limit=1 keeps the later error, not the earlier warn.Related issue
fixes #2617
User / Agent impact
anolisa logsandanolisa logs --limit Nnow show the newest matching records. Scripts that depended on seeing the oldest N hits from a large log will see the newest N instead (still oldest-first inside the window).--sincebehavior is unchanged except that--limittails inside that window.Risk and compatibility
--limit/LogFilter.limitnow means most-recent N rather than first-N. That is the intended operator contract for an append-only audit log; library callers ofCentralLog::querywith a limit see the same tail semantics.Validation
Focused:
query_limit_applies_after_filter,query_limit_tails_matches_inside_since_window,limited_query_releases_lock_before_scanning_history(50/50 locally),query_combined_filter_honors_zero_and_one_limits. Fullcargo test --lockedas root still hits the existing--install-mode useradapter notice suite (not caused by this diff).Documentation and rollback
CLI
--limithelp andLogFilter.limit/CentralLog::queryrustdoc now state most-recent N. No user-guide change (guide does not claim first-N). Revert this commit series to restore first-N scanning.Review follow-up
Current head:
b74a25d96e55e055a1823140f5e132a71b282d99.This head keeps the tail
--limitcontract, the short lock window, alignedqueryrustdoc + doctest, and a deterministic overlap test (post-unlock hold, then append, then resume scan). No 5 ms sleep or 250 ms append SLO.