Repository navigation
perf(daemon): observe and retry live catch-up convergence - #1033
Conversation
Problem: root CLI startup still imported command and surface helpers that pulled archive-adjacent stacks, while docs rendering paid repeated CLI subprocess costs and the pages builder waited on live stats queries. This kept help/import and generated-surface workflows slower than the current performance targets. What changed: register all root/query commands through lazy Click proxies, split query verb names into a lightweight module, move formatting and machine-envelope dependencies off the startup path, add package-root lazy submodule access, render CLI help and page feeder surfaces in-process, read site stats from conversation_stats directly, and add affected-test verification with a content-aware verify cache. Verification: devtools render-all --check; python -X importtime -c 'from polylogue.cli.click_app import cli' with no archive/storage/rendering/daemon/surfaces imports; focused CLI/devtools pytest set passed with 89 passed, 4 skipped; devtools verify --affected --skip-slow --force --json passed in 51.91s.
…yloads
Add pydantic `field_validator(mode="before")` on
`SessionInferencePayload.work_events` and `phases` to backfill
`timing_provenance` and `date_provenance` when older archived documents
lack those fields.
The validators run at deserialization time and only set defaults when the
fields are missing (`setdefault`), preserving any explicit values already
on the document. The provenance values are derived from `start_time` /
`end_time` / `canonical_session_date`:
- `timing_provenance`: timestamped_range | start_timestamp_only |
end_timestamp_only | untimestamped
- `date_provenance`: event_timestamp | date_only | none
This makes deserialization of legacy archive payloads (pre-`timing_provenance`
schema) succeed instead of failing with missing-field errors when those
defaults can't be inferred from the existing class-level defaults
("untimestamped" / "none") because they ignore available timestamps.
Coverage:
tests/unit/storage/test_session_insight_mapper_fallbacks.py — 6 passed
Problem: daemon catch-up could keep rereading source files and derived convergence failures were hard to distinguish from raw ingest success. Operators also lacked durable progress and read-amplification evidence while polylogued was under IO pressure. What changed: add durable live-ingest stage events, catch-up status projection, convergence-debt status, conversation-id convergence retry hooks, bulk cursor planning in catch-up and batch append planning, legacy provenance normalization for typed insight payloads, and Nix/systemd service resource controls. Generated verification docs and terminal snapshots were refreshed for the updated CLI lazy-loading surface. Verification: PATH="/realm/project/polylogue/.cache/no-notify-bin:/home/sinity/.codex/tmp/arg0/codex-arg0Voz8KF:/nix/store/dk9qhjgg469lv6mriys7v4c59igarmvx-bubblewrap-0.11.1/bin:/nix/store/4bwbk4an4bx7cb8xwffghvjjyfyl7m2i-bash-interactive-5.3p9/bin:/nix/store/jjxngswsb214vb58qx485jhmilf0kxxy-coreutils-9.10/bin:/realm/project/polylogue/.direnv/sinnix-scope/bin:/realm/project/polylogue/.venv/bin:/nix/store/66lksljlljdd5ppgvfk8g89y8xgqcxd7-patchelf-0.15.2/bin:/nix/store/qd70v8g0561vm8m33kmnp79z00cgyi5n-gcc-wrapper-15.2.0/bin:/nix/store/sanx9fg8mry8mq92zhlm5qvb83qlxrlx-gcc-15.2.0/bin:/nix/store/pf30k3mg7n6bibc1k6609gyq7glk00k2-glibc-2.42-61-bin/bin:/nix/store/jjxngswsb214vb58qx485jhmilf0kxxy-coreutils-9.10/bin:/nix/store/kfwagnh6i1mysf7vxq679rzh30z9zj3g-binutils-wrapper-2.46/bin:/nix/store/p2vkw5s89ff1fs2d2rxqxiqil9s0jpcm-binutils-2.46/bin:/nix/store/0r6k8xa2kgqyp3r4v2w7yrb80ma2iawm-python3-3.13.12/bin:/nix/store/9xinbvah2sr4k5g05g7w48q2klf2va5f-uv-0.11.8/bin:/nix/store/sl5031w08yhja3hhfkwxpm187c9f9qkb-devtools/bin:/nix/store/c0277k5giric1mn9dklllavbzvxl6hzb-git-2.53.0/bin:/nix/store/97mrhz21xc7dx218i36m6s9jyi7q5469-ruff-0.15.12/bin:/nix/store/nrc6fg23g7q6qm5dfd63kfg74l613cyi-python3.13-mypy-1.19.1/bin:/nix/store/fvs3zhpvndbca8mppb829174ckdrdgcv-py-spy-0.4.0/bin:/nix/store/p60rxkda75nmha060ikxhkzy4dmpz53i-python3.13-pyinstrument-5.1.2/bin:/nix/store/s63r3nfiy3gni9ikx2ka7cwl5hz8imzi-bat-0.26.1/bin:/nix/store/hqg1pdb50bny98165djnr627h9y8fk5i-glow-2.1.2/bin:/nix/store/sqpq9fbwhs2r48z1amlib3cpf1y4qxmi-vhs-0.11.0/bin:/nix/store/jjxngswsb214vb58qx485jhmilf0kxxy-coreutils-9.10/bin:/nix/store/vhsirn9m1ifmnw5g1qczzhvqkx6lw1if-findutils-4.10.0/bin:/nix/store/hx084k7pgz4n0vgkvil9gbcnl8y6p1xf-diffutils-3.12/bin:/nix/store/af4a8i43kc2ss4rnmf0swkk2mprsw6xq-gnused-4.9/bin:/nix/store/wf7lr2hf43546jc5kwqh3dbxnpcnw1mn-gnugrep-3.12/bin:/nix/store/lakv43kv98sl6h0ba6wnyg513mcq61vl-gawk-5.4.0/bin:/nix/store/rnvb7bvp53v2dw7pcwh9xb89x5z4rjib-gnutar-1.35/bin:/nix/store/9lhr1c3l9qzv8pzp3idmii1nwvxxjys3-gzip-1.14/bin:/nix/store/zj6r42syyswkhrr174bzppj3n7xhq936-bzip2-1.0.8-bin/bin:/nix/store/yvrwcs1a45rj8142n0l2w9q9s6akamjr-gnumake-4.4.1/bin:/nix/store/i27rhb3nr65rkrwz36bchkwmav6ggsmn-bash-5.3p9/bin:/nix/store/zj7mxwji29zvj9vl70iip7gw4h6ljfam-patch-2.8/bin:/nix/store/2nm5c858fh52s6mhcffm07s3biaxys44-xz-5.8.3-bin/bin:/nix/store/iscmg3ivhx7z67dz14lrg7p77gnsa4dw-file-5.45/bin:/realm/project/polylogue/.direnv/bin:/home/sinity/.local/bin:/run/wrappers/bin:/home/sinity/.nix-profile/bin:/nix/profile/bin:/home/sinity/.local/state/nix/profile/bin:/etc/profiles/per-user/sinity/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/nix/store/kfwagnh6i1mysf7vxq679rzh30z9zj3g-binutils-wrapper-2.46/bin:/nix/store/m0yqmmh44v2ykpr7gd6hp6yrvzpcqbjd-hyprland-qtutils-0.1.5/bin:/nix/store/jx13ah7k2zp0w21r2qncpdji93ylcncl-pciutils-3.14.0/bin:/nix/store/vqpm0alli7j5fvqxwrq9rg4csnkwk0j8-pkgconf-wrapper-2.5.1/bin:/nix/store/myjlf11fwy8yw3127hxsfyidxz6srg6x-kitty-0.46.2/bin:/nix/store/pjcg9z9zj4hqa7y8jjgsx06rc31q6r8s-imagemagick-7.1.2-19/bin:/nix/store/whrp41kk2qd790h8xg4v4giw5z0cmxa7-ncurses-6.6-dev/bin" devtools verify passed on 2026-05-15 with pytest 6348 passed, 2 skipped, 2 xfailed, 2 xpassed.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (46)
📝 WalkthroughWalkthroughThis PR introduces durable convergence-debt retry tracking with exponential backoff, conversation-scoped convergence stages, and live ingest observability (stage events and metrics) via new SQLite tables. It also refactors the CLI to use lazy command registration and defers heavyweight imports to reduce startup overhead. Supporting changes include session inference normalization, direct database access in devtools, and affected-test detection for selective verification. ChangesConvergence Debt Tracking & Live Ingest Observability with CLI Import Optimization
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 56d56c8bcf
ℹ️ 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".
| if latest is not None and latest.status == "running": | ||
| return "converging" if latest.phase in {"convergence", "fts", "insights", "full_worker_wait"} else "catching_up" |
There was a problem hiding this comment.
Ignore stale running stage events when deriving catch-up mode
Mode selection treats the latest stage event with status == "running" as active work even when there is no running ingest attempt. After a crash/interruption, live_ingest_attempt is marked interrupted, but old stage events remain running, so status can stay stuck in catching_up/converging indefinitely and misreport daemon state.
Useful? React with 👍 / 👎.
Summary Avoid full-file fingerprint reads during daemon catch-up when a source path has the same byte size and an existing content fingerprint but its device/inode changed under the cursor. Problem The deployed daemon still hammered disk after #1033. `py-spy dump` showed startup stuck in `fingerprint_file()` from `LiveWatcher._plan_catch_up()`. A production cursor classification found 10,916 files / 31.35 GB in the `fingerprint_read` path solely because stored `st_dev/st_ino` no longer matched the filesystem, even though paths, sizes, parser fingerprints, and stored content fingerprints were stable. Solution Treat stable path + stable byte size + recorded content fingerprint as the catch-up skip path independent of inode/device churn. Appends still trigger work via `size > byte_offset`, truncations still fall through, and legacy cursors without fingerprints still populate cursor state. Verification - `pytest tests/unit/sources/test_live_watcher.py -q --tb=short` → 60 passed - `pytest tests/integration/test_live_read_amplification.py -q --tb=short` → 5 passed - `ruff check polylogue/sources/live/watcher.py tests/unit/sources/test_live_watcher.py` → All checks passed - `devtools verify-file-budgets` → clean - `devtools render-all` → generated surfaces refreshed - Pre-push `devtools verify --quick` → exit_code 0 - PR checks: CodeQL, CodeRabbit, GitGuardian pass
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
This PR carries the current Polylogue performance stack through the merge path: CLI/render startup deferral, legacy insight provenance normalization, and the daemon catch-up/convergence work. The daemon now records durable live-ingest stage events, exposes catch-up/read-amplification status, keeps raw ingest success separate from derived convergence debt, retries conversation-scoped debt without resolving back to source files, and bulk-loads cursor state during catch-up and append planning.
Problem
Production
polyloguedcatch-up was observable only through coarse logs while it could still generate heavy physical reads. A derived-stage failure could make the live path look like raw ingest had failed, causing repeated source work instead of clear derived debt. Host friendliness also belonged in systemd packaging, not ad-hoc app-level throttling or daemon scope reduction.Solution
live_ingest_stage_eventandlive_convergence_debtdurable tables plus typed daemon status projections for catch-up and convergence debt.Nice, idle IO scheduling,IOWeight,MemoryHigh, andMemoryMax.Verification
PATH="$PWD/.cache/no-notify-bin:$PATH" devtools verifypassed on 2026-05-15.6348 passed, 2 skipped, 2 xfailed, 2 xpassed107.94sdevtools verify --quickand passed on 2026-05-15.pytest tests/unit/daemon/test_daemon_convergence.py tests/unit/daemon/test_daemon_cli.py tests/unit/sources/test_live_watcher.py tests/unit/cli/test_source_selection_helpers.py tests/unit/devtools/test_render_all.py tests/unit/devtools/test_quality_registry.py tests/unit/devtools/test_scenario_projections.py tests/unit/devtools/test_artifact_graph.py tests/unit/cli/test_insights.py -q --tb=shortpytest tests/unit/cli/test_terminal_snapshots.py --snapshot-update -q --tb=shortDeployment Notes
Deployment is intentionally not folded into the app PR. After merge, update the Sinnix flake input for Polylogue, switch the NixOS generation, restart/deploy
polylogued, then validate the real archive usingpolylogued status --json, stage-event rows, convergence-debt rows, journal logs, and physical read deltas.Summary by CodeRabbit
New Features
Improvements
Documentation