Skip to content

fix(cli): isolate heavy foreground maintenance - #711

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/maintenance-resource-boundary
May 2, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/maintenance-resource-boundary

Conversation

@Sinity

@Sinity Sinity commented May 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Add Polylogue-owned resource isolation for mutating maintenance and heavy foreground run stages, and finish the reparse force-write plumbing that was started in the worktree by another agent.

Problem

polylogue doctor --repair --target session_insights and similar foreground maintenance inherited interactive CPU and I/O priority. On a large archive this can saturate disk and make the desktop unusable. The same broad maintenance path also exposed an incomplete force_write thread: run --reparse reset parse status, but same-hash conversation rows could still be skipped by sync ingest replacement.

Solution

  • Add polylogue.maintenance.resources as the central classifier and applicator for heavy foreground workloads.
  • Route mutating doctor maintenance plus heavy run/batch embed stages through that policy.
  • Prefer a Linux user systemd-run --scope with low CPU/I/O weights, fall back to process-local nice/ionice, and expose --resource-mode auto|scope|process|off.
  • Report the effective resource mode in doctor JSON/plain output and run output.
  • Finish force_write propagation from run --reparse through run workflow, pipeline execution, parsing services, and sync ingest writes.
  • Refresh generated CLI, topology, and verification catalog docs.

Verification

  • ruff check polylogue/maintenance/resources.py polylogue/cli/commands/check.py polylogue/cli/commands/run.py polylogue/cli/shared/check_options.py polylogue/cli/shared/check_workflow.py polylogue/cli/shared/check_models.py polylogue/cli/shared/check_rendering_json.py polylogue/cli/shared/check_rendering_plain.py polylogue/cli/shared/run_workflow.py polylogue/pipeline/run_execution.py polylogue/pipeline/run_stages.py polylogue/pipeline/services/ingest_batch.py polylogue/pipeline/services/parsing.py polylogue/pipeline/services/parsing_workflow.py tests/unit/maintenance/test_resources.py tests/unit/cli/test_check.py tests/unit/cli/test_check_support_runtime.py tests/unit/cli/test_check_rendering_plain_runtime.py tests/unit/cli/test_run_command_runtime.py tests/unit/pipeline/test_ingest_batch.py
  • ruff format --check on the same files
  • pytest -q tests/unit/maintenance/test_resources.py tests/unit/cli/test_check_support_runtime.py tests/unit/cli/test_check_rendering_plain_runtime.py tests/unit/cli/test_run_command_runtime.py tests/unit/cli/test_check.py tests/unit/pipeline/test_ingest_batch.py
  • pytest -q -n0 tests/unit/cli/test_terminal_snapshots.py::TestCommandOutputs::test_check_output_snapshot tests/unit/cli/test_terminal_snapshots.py::TestCommandOutputs::test_run_help_output_snapshot tests/unit/cli/test_auth.py::TestAuthCommand::test_auth_unknown_service_fails tests/unit/cli/test_reset.py::TestResetCommandSubprocess::test_reset_database_requires_force
  • pytest -q tests/unit/proof/test_evidence_runners.py
  • devtools render-all --check
  • devtools verify-topology
  • devtools verify-layering
  • devtools proof-pack --path ... --markdown
  • devtools verify --quick
  • pre-push devtools verify --quick

Ref #708

Summary by CodeRabbit

  • New Features

    • Added --resource-mode option to run and doctor commands for controlling resource isolation during maintenance and pipeline execution.
    • Added path inspection output for run --preview displaying resolved sources and output paths.
  • Documentation

    • Updated CLI reference and configuration docs covering resource isolation modes and path inspection behavior.

Problem: foreground doctor repairs and heavy run stages inherited interactive CPU and I/O priority, which could starve the desktop during large archive maintenance. A concurrent reparse fix from another agent also left the force-write path only partially wired, so --reparse could still skip same-hash row replacement after resetting parse status.

What changed: add a central maintenance resource-boundary policy with systemd-scope preference, process demotion fallback, JSON/plain reporting, and --resource-mode overrides. Route mutating doctor maintenance plus heavy run/embed stages through it. Finish force_write propagation from run --reparse through pipeline execution, parsing services, and sync ingest writes.

Verification: ruff check/format on changed files; pytest focused maintenance/resource, doctor, run, snapshot, and ingest tests; devtools render-all --check; devtools verify-topology; devtools verify-layering; devtools verify --quick. Ref #708.
Copilot AI review requested due to automatic review settings May 2, 2026 16:15
@coderabbitai

coderabbitai Bot commented May 2, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR adds resource isolation for mutating maintenance tasks and heavy pipeline stages through a new resource-boundary system that supports systemd scope, process demotion, and test harness detection, with a --resource-mode CLI option and force_write threading for reparse handling.

Changes

Resource Isolation System

Layer / File(s) Summary
Core Policies & Types
polylogue/maintenance/resources.py
Introduces ResourceMode, ResourceWorkload, and ResourceBoundaryRequest/ResourceBoundaryReport dataclasses. Implements normalize_resource_mode(), doctor_resource_request(), pipeline_resource_request(), and the main apply_resource_boundary() controller. Supports systemd transient scope re-exec, process demotion via nice/ionice, and test harness detection.
CLI Options
polylogue/cli/shared/check_options.py, polylogue/cli/commands/run.py
Added --resource-mode [auto|scope|process|off] option (default auto) to both polylogue doctor and polylogue run commands with help text for resource isolation control.
Workflow & Service Signatures
polylogue/cli/shared/check_workflow.py, polylogue/cli/commands/check.py, polylogue/cli/commands/run.py, polylogue/pipeline/run_execution.py, polylogue/pipeline/run_stages.py, polylogue/pipeline/services/parsing.py, polylogue/pipeline/services/parsing_workflow.py, polylogue/cli/shared/run_workflow.py
Extended function signatures to thread resource_mode: str through check/doctor workflows and force_write: bool through ingest pipeline (parsing service, parsing workflow, run execution, run stages).
Ingest Force-Write Handling
polylogue/pipeline/services/ingest_batch.py
Added force_write parameter to process_ingest_batch, _write_conversation_entry, and _write_conversation. When enabled, bypasses content-hash-unchanged check to force writes during reparse, ensuring conversation data is rewritten even with matching hashes.
Workflow Integration
polylogue/cli/shared/check_workflow.py, polylogue/cli/commands/run.py
Integrated resource boundary computation into doctor maintenance via apply_resource_boundary(doctor_resource_request(...)) and into run command stages via apply_resource_boundary(pipeline_resource_request(...)). Prints effective resource mode/status when boundaries are heavy.
Output Rendering
polylogue/cli/shared/check_models.py, polylogue/cli/shared/check_rendering_plain.py, polylogue/cli/shared/check_rendering_json.py
Added resource_boundary: ResourceBoundaryReport | None field to CheckCommandResult. Plain text output conditionally prints "Resource mode: ..." line; JSON output includes resource_mode dict in maintenance payload when boundary is present.
Tests & Documentation
tests/unit/maintenance/test_resources.py, tests/unit/cli/test_check.py, tests/unit/cli/test_check_rendering_plain_runtime.py, tests/unit/cli/test_check_support_runtime.py, tests/unit/cli/test_run_command_runtime.py, tests/unit/pipeline/test_ingest_batch.py, docs/cli-reference.md, docs/configuration.md, tests/unit/cli/__snapshots__/test_terminal_snapshots.ambr, docs/plans/topology-target.yaml, docs/topology-status.md, docs/verification-catalog.md
New unit tests for resource mode classification, boundary application, and opt-out behavior; updated command/rendering tests to include resource_mode="auto" and verify resource_boundary output; documented resource isolation policy and --resource-mode option; updated generated metadata files and line references.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI
    participant ResourceMgr as Resource Boundary<br/>Manager
    participant OS as OS/Systemd
    participant Workflow
    participant Report as Resource Report<br/>Renderer

    User->>CLI: Run 'polylogue doctor --resource-mode auto'
    CLI->>CLI: Normalize resource_mode
    CLI->>ResourceMgr: doctor_resource_request(repair,cleanup,preview,mode)
    ResourceMgr->>ResourceMgr: Classify workload & heavy flag
    CLI->>ResourceMgr: apply_resource_boundary(request)
    alt Heavy + auto/scope mode
        ResourceMgr->>OS: Check systemd-run available?
        OS-->>ResourceMgr: Yes/No
        alt Systemd available
            ResourceMgr->>OS: Re-exec in systemd-run --scope
            OS->>OS: Isolate with cgroup/demotion
            OS-->>ResourceMgr: Report applied
        else Fallback to process demotion
            ResourceMgr->>OS: nice() + ionice()
            OS-->>ResourceMgr: Report demoted
        end
    else Not heavy or off mode
        ResourceMgr-->>ResourceMgr: Skip, report "not_applicable"
    end
    ResourceMgr-->>CLI: ResourceBoundaryReport
    CLI->>Workflow: Execute maintenance/run
    Workflow->>Workflow: Perform work
    Workflow-->>CLI: Result
    CLI->>Report: Render resource_boundary report
    Report-->>User: Display "Resource mode: effective_mode (status)"
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • fix(cli): isolate resource-heavy maintenance commands #708: This PR directly implements the resource isolation feature for polylogue doctor maintenance and heavy foreground run stages, adding the --resource-mode CLI option, the core apply_resource_boundary() system, and integration across doctor, run, and ingest workflows.

Suggested labels

type:feature, area:cli, area:pipeline, area:maintenance

Poem

🐰 Hippity-hop, the resources align,
Systemd scopes and nice times divine,
Heavy work now plays fair and kind,
Resource bounds keep chaos behind!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.42% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely summarizes the main change: adding resource isolation for heavy foreground maintenance operations. It is specific, clear, and directly reflects the primary objective of the pull request.
Description check ✅ Passed The description comprehensively follows the template with all major sections (Summary, Problem, Solution, Verification) complete and detailed. It explains the motivation, implementation approach, and extensive verification steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/maintenance-resource-boundary

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Polylogue Proof Pack

Refs: origin/master..HEAD
Changed paths: 26

Affected Domains

  • architecture_discipline — 2 claim(s), maturity growing
  • spec_completeness — 1 claim(s), maturity seed
  • unclassified — 4 claim(s), maturity seed
Additional routed domains with zero affected claims
  • docs_media — maturity seed

Focused Gates

  • devtools render-all --check — generated surface or renderer changed
  • devtools verify-manifests — structural manifest changed
  • devtools affected-obligations --path docs/plans/topology-target.yaml — refresh structural obligation routing
  • devtools verify-topology — topology projection changed
  • devtools affected-obligations --path docs/topology-status.md — refresh structural obligation routing
  • pytest tests/unit/cli — CLI command surface changed
  • pytest tests/unit/proof/test_evidence_runners.py — CLI proof runners exercise command output
  • devtools render-cli-reference --check — CLI reference is generated from command help

Required PR Gates

  • devtools verify --quick — full PR gate remains explicit
  • devtools verify — full PR gate remains explicit

Optional Confidence Gates

  • devtools build-package — deployment readiness gate; run when packaging or release confidence matters
  • nix flake check — deployment readiness gate; run when packaging or release confidence matters

Known Gaps

  • none for domains with affected claims
Additional gaps in zero-claim routed domains
  • docs_media: docs_media: No scenario for documentation freshness verification [owner: scenario-coverage; next: devtools scenario-projections], docs_media: README examples and media are not yet generated from executable scenario projections. [owner: docs-media; next: devtools render-docs-surface --check], docs_media: Screenshots and VHS media have no committed nonblank/readability verification. [owner: docs-media; next: devtools render-docs-surface --check]

Oracle / Cost

  • oracle mix: {"construction_sanity": 174, "drift_check": 2}
  • cost tier: {"static": 171, "unit": 5}
  • stable affected obligations: 176
  • agent judgment cells: 0

@Sinity
Sinity merged commit 18c9b6a into master May 2, 2026
13 of 18 checks passed
@Sinity
Sinity deleted the feature/fix/maintenance-resource-boundary branch May 2, 2026 16:17

@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: 43ad4f66c2

ℹ️ 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 polylogue/cli/commands/run.py Resolved
Comment thread polylogue/maintenance/resources.py Resolved
@Sinity
Sinity removed the request for review from Copilot May 2, 2026 16:38
Sinity added a commit that referenced this pull request May 2, 2026
## Summary

Handle `systemd-run --user --scope` launch failures as unavailable resource isolation rather than exiting the original command with the `systemd-run` status.

## Problem

The resource boundary work from #711 made `auto` mode prefer transient systemd scopes for heavy foreground maintenance. A nonzero `systemd-run` exit is not the same as successful re-exec inside a scope: in `auto` mode it should fall through to process-local demotion, and in explicit `scope` mode it should report an unavailable scope with the diagnostic.

## Solution

- Capture `systemd-run` output and treat nonzero return codes as `ScopeLaunchUnavailableError`.
- Preserve the existing `SystemExit(0)` path when scope launch succeeds.
- Add a focused test for explicit scope-mode launch failure and diagnostic propagation.

## Verification

- `ruff check polylogue/maintenance/resources.py tests/unit/maintenance/test_resources.py`
- `ruff format --check polylogue/maintenance/resources.py tests/unit/maintenance/test_resources.py`
- `mypy tests/unit/maintenance/test_resources.py`
- `pytest -q tests/unit/maintenance/test_resources.py`
- `devtools verify --quick`
- pre-push hook: `devtools verify --quick`

Ref #708
Sinity added a commit that referenced this pull request May 7, 2026
Summary

Add Polylogue-owned resource isolation for mutating maintenance and heavy foreground run stages, and finish force-write propagation for reparse runs.

Problem

Foreground `doctor --repair` and heavy `run` stages inherited interactive CPU and I/O priority, which could starve the desktop during large archive maintenance. An in-flight reparse fix also left `force_write` only partially wired, so `run --reparse` could reset parse status while same-hash conversation rows still skipped replacement.

Solution

Added `polylogue.maintenance.resources` as the central classifier and applicator for heavy foreground workloads. Mutating doctor maintenance and heavy run/embed stages now use `--resource-mode auto|scope|process|off`, preferring a user systemd transient scope and falling back to process-local nice/ionice. Doctor JSON/plain output and run output report the effective mode.

Finished `force_write` propagation from `run --reparse` through run workflow, pipeline execution, parsing services, and sync ingest writes. Added regression coverage for same-hash forced replacement.

Verification

- `ruff check` and `ruff format --check` on changed runtime/test files
- `pytest -q tests/unit/maintenance/test_resources.py tests/unit/cli/test_check_support_runtime.py tests/unit/cli/test_check_rendering_plain_runtime.py tests/unit/cli/test_run_command_runtime.py tests/unit/cli/test_check.py tests/unit/pipeline/test_ingest_batch.py`
- `pytest -q -n0 tests/unit/cli/test_terminal_snapshots.py::TestCommandOutputs::test_check_output_snapshot tests/unit/cli/test_terminal_snapshots.py::TestCommandOutputs::test_run_help_output_snapshot tests/unit/cli/test_auth.py::TestAuthCommand::test_auth_unknown_service_fails tests/unit/cli/test_reset.py::TestResetCommandSubprocess::test_reset_database_requires_force`
- `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`
- pre-push `devtools verify --quick`

Ref #708
Sinity added a commit that referenced this pull request May 7, 2026
## Summary

Handle `systemd-run --user --scope` launch failures as unavailable resource isolation rather than exiting the original command with the `systemd-run` status.

## Problem

The resource boundary work from #711 made `auto` mode prefer transient systemd scopes for heavy foreground maintenance. A nonzero `systemd-run` exit is not the same as successful re-exec inside a scope: in `auto` mode it should fall through to process-local demotion, and in explicit `scope` mode it should report an unavailable scope with the diagnostic.

## Solution

- Capture `systemd-run` output and treat nonzero return codes as `ScopeLaunchUnavailableError`.
- Preserve the existing `SystemExit(0)` path when scope launch succeeds.
- Add a focused test for explicit scope-mode launch failure and diagnostic propagation.

## Verification

- `ruff check polylogue/maintenance/resources.py tests/unit/maintenance/test_resources.py`
- `ruff format --check polylogue/maintenance/resources.py tests/unit/maintenance/test_resources.py`
- `mypy tests/unit/maintenance/test_resources.py`
- `pytest -q tests/unit/maintenance/test_resources.py`
- `devtools verify --quick`
- pre-push hook: `devtools verify --quick`

Ref #708
@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

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.

@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant