Skip to content

fix(cli): isolate resource-heavy maintenance commands #708

Closed

Description

@Sinity

Problem

Polylogue maintenance commands can trigger heavy disk I/O and CPU usage that competes with interactive desktop workloads. Observed on sinnix-prime (2026-05-02): Chrome freezing during polylogue doctor --repair --target session_insights with ~30 GiB read, I/O pressure full avg10 ~50%.

The deeper problem is that heavy CLI operations (reparse, materialize, doctor repair, index, embed) can run with opaque and effectively unbounded performance behavior — no throughput accounting, no built-in backpressure, no visibility into why a command is saturating the host.

Direction (revised 2026-05-02)

The initial implementation (#711) added a product-side --resource-mode flag with systemd/nice/ionice self-demotion. That was the wrong boundary. polylogue is a portable product CLI, not the host policy layer.

Revised direction:

Acceptance criteria

  • --resource-mode is removed from the public CLI surface.
  • Heavy CLI maintenance paths are classified but do not self-demote.
  • Polylogue records enough facts (records scanned/changed, bytes read/written, DB/blob/render/index counters, stage timings, RSS) for host observability to join with external monitors.
  • A generic resource-wrapper hook (e.g. POLYLOGUE_RESOURCE_WRAPPER env) is available so hosts can inject their own scope/slice policy without Polylogue encoding host-specific details.
  • Heavy interactive runs on a desktop without a resource wrapper active should warn.
  • polylogue run persists a compact performance ledger per run.
  • polylogued is the durable execution path for long-running/heavy operator work.

What landed and was reverted

Related

Ref #578

Activity

  1. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Implemented in #711.

    Scope covered:

    • Added a central polylogue.maintenance.resources policy for foreground heavy workloads.
    • polylogue doctor --repair/--cleanup now classifies mutating maintenance and applies the resource boundary before running selected maintenance.
    • Heavy foreground polylogue run stages (materialize, render, site, index, publish, watch-mode runs, and batch embed) go through the same resource boundary.
    • Default auto mode prefers a Linux user systemd-run --scope with low CPU/I/O weights; if unavailable it falls back to process-local nice/ionice; --resource-mode off is available for benchmarks/debugging.
    • Doctor JSON/plain output and run output report the effective resource mode.
    • Finished an in-flight fix from another agent: run --reparse now propagates force_write through pipeline execution, parsing services, and sync ingest writes so same-hash rows are replaced after parse status reset.

    Verification run:

    • focused ruff check/format on changed files;
    • focused doctor/resource/run/ingest pytest suites;
    • terminal snapshot updates for new help text, verified serially;
    • pytest -q tests/unit/proof/test_evidence_runners.py;
    • devtools render-all --check;
    • devtools verify-topology;
    • devtools verify-layering;
    • devtools affected-obligations --path docs/plans/topology-target.yaml;
    • devtools affected-obligations --path docs/topology-status.md;
    • devtools proof-pack --path ... --markdown;
    • devtools verify --quick locally and again via pre-push hook.

    Note: a broad pytest -q tests/unit/cli run was started but became unreliable because a concurrent live polylogue run --reparse --source codex parse materialize was saturating the system and causing PTY/subprocess timeouts. I reran the affected PTY/subprocess tests serially after that and they passed.

  2. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Closing after #711. The remaining daemon split/watch retirement questions belong to #620/#648 rather than this resource-boundary issue.

  3. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Clarification from the 2026-05-02 workstation incident: stopping/killing polylogue run --reparse ... was emergency load shedding, not a solution.

    The product bug is that reparse/materialize can run with opaque and effectively unbounded performance behavior:

    • no clear throughput/progress accounting for records scanned, records changed, bytes read/written, DB writes, blob writes, and render/index work;
    • no built-in pacing/backpressure when the host is under PSI I/O or memory pressure;
    • manual invocations such as polylogue run --reparse --source codex --resource-mode off parse materialize can bypass the systemd/user-service resource envelope;
    • the operator has to infer the culprit from external tools instead of Polylogue reporting its own performance state and expected remaining work.

    Acceptance should include making reparse performance observable and controlled, not just documenting how to kill it. The command should either self-place into a resource-managed scope or refuse/require an explicit unsafe flag when launched without resource controls on an interactive desktop.

  4. reopened this on May 2, 2026
  5. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Follow-up investigation from the 2026-05-02 workstation pressure incident.

    The resource-boundary layer from #711 exists, but it is still too easy for real workloads to bypass or overwhelm the desktop:

    • polylogue run --reparse ... --resource-mode off parse materialize bypasses the systemd scope/process demotion entirely. That may be useful for controlled benchmarks, but it is unsafe as a normal operator escape hatch on the workstation.
    • Heavy classification does not include parse/reparse by itself. In practice --reparse parse materialize was the live bad shape, but parse/reparse can scan and rewrite a large archive even before materialize/render/index.
    • The devshell still launches devtools status, devtools render-agents, uv sync, and arbitrary devtools verify/pytest work without a Polylogue-owned resource wrapper or durable run record. pyproject.toml defaults pytest to -n auto, so full verification can fan out aggressively.
    • Repo-local .local is ignored and currently holds multi-GB stale artifacts: about 21G total, including ~8.9G vetting output and ~11G browser-capture/chromium artifacts. The devshell cleans legacy Python caches but does not prune large repo-local generated state.
    • The live archive under $XDG_DATA_HOME/polylogue is still about 68G, dominated by ~40G blob store and ~3.4G render output. That may be legitimate data, but Polylogue should report why it is that size and what is reclaimable.
    • Pipeline logs have per-stage timings and counts, but not enough operator-facing throughput/pressure attribution: bytes read/written, DB write counts, blob writes, render bytes, records scanned vs changed, cgroup/scope identity, and PSI/backpressure state are not directly legible from the command.

    Concrete acceptance should be broader than "run in a scope":

    • --resource-mode off should be renamed/gated as an explicit unsafe benchmark/debug path or refused for heavy interactive desktop runs unless an unsafe env/flag is also present.
    • --reparse and parse stages over non-trivial archives should be classified as heavy and resource-managed by default.
    • devtools verify, benchmark/probe commands, and pytest fanout should either run through a devtools resource wrapper or emit a clear unmanaged-workload warning and durable run record.
    • The devshell should put disposable repo-local heavy state under a bounded cache root and prune stale .local/.cache artifacts by age/size.
    • polylogue run should persist a compact performance ledger per run: stage durations, records scanned/changed, bytes read/written, DB/blob/render/index work, effective resource mode, cgroup/scope, and pressure/backpressure observations.

    Killing a runaway reparse remains emergency load shedding only; this issue should stay open until Polylogue itself makes the workload bounded, observable, and hard to launch unsafely by accident.

  6. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Portability constraint: Polylogue should not encode this workstation's concrete resource policy.

    The Polylogue-side fix should be generic and host-integrable:

    • Keep generic resource-mode/resource-context concepts, but do not hard-code Sinnix device UUIDs, bandwidth caps, /cache policy, or timer decisions in Polylogue.
    • Add/accept an optional resource wrapper env or config hook (for example POLYLOGUE_RESOURCE_WRAPPER) so Sinnix can launch heavy run, reparse, devtools verify, and benchmark/probe work through its local sinnix-scope --class ... policy.
    • Persist resource context when available: requested/effective mode, resource class, cgroup path, systemd unit/scope, and timestamp window for joining with external monitors such as below.
    • Improve Polylogue's own workload ledger in portable terms: records scanned/changed, bytes read/written, DB/blob/render/index counters, stage timings, RSS, and reclaimable storage classification.
    • Warn/refuse unsafe heavy interactive runs when no resource wrapper/scope is active, but leave the concrete policy to the host.

    Sinnix can then own the machine-specific cgroup classes, I/O caps, /cache routing, and global pressure report without making Polylogue workstation-specific.

  7. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Direction correction from the 2026-05-02 workstation incident: polylogue CLI should not own workstation scheduling/resource policy.

    The previous #711 implementation made this a product-side --resource-mode systemd/nice/ionice mechanism. That was the wrong boundary:

    • polylogue is a portable product CLI, not the host policy layer.
    • Concrete resource policy belongs in Sinnix and daemon/service supervision.
    • The future durable execution path should be polylogued-owned for long-running/heavy operator work, with Sinnix supplying local cgroup/slice/device policy.
    • Polylogue should emit workload/run facts and eventually a queryable execution ledger (Add xtask-like execution history for Polylogue dev and operator workflows #716), not expose knobs like --resource-mode off or self-reexec into transient scopes.

    Current local fix removes the public --resource-mode option and deletes the CLI self-demotion/systemd-scope helper rather than adding more limits around it. Remaining acceptance for this issue should be reframed as:

    • heavy CLI maintenance/reparse paths are not advertised as the normal way to run workstation-scale jobs;
    • daemonized/supervised entrypoints own those jobs, or the host wrapper does;
    • Polylogue records enough facts for Sinnix/global observability to join with below/PSI/systemd data;
    • no Sinnix-specific paths, devices, timers, or cgroup caps land in Polylogue.
  8. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Closing per 2026-05-02/03 architectural decision: Polylogue CLI should not own workstation scheduling policy. The --resource-mode mechanism was added in #711, fixed in #715, and completely removed in 15b46574 refactor(cli): remove foreground resource policy. The remaining concerns are tracked in #717 (daemon-owned execution) and #716 (execution ledger). The env hook idea (POLYLOGUE_RESOURCE_WRAPPER) is a Sinnix host concern, not a Polylogue product concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cliarea:storagetype:perf

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions