Skip to content

fix(schema+config): validate Config paths, raise on invalid privacy level, dedup XDG state - #525

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/privacy-and-config-validation
Apr 27, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/privacy-and-config-validation

Conversation

@Sinity

@Sinity Sinity commented Apr 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #481.

Four of the six items in #481 were already resolved on master in earlier audit-fix waves (likely #504 and predecessors). This PR addresses the two real outstanding defects plus tightens `Config` construction.

Problem

Sub-item Status
`name` not in content field denylist Already fixed (`schemas/privacy.py:97` includes `name`, `body`, `message`, `input`, `output`)
`max_length=0` treated as falsy Already fixed (`schemas/privacy.py:220`: `max_length if max_length is not None else _SAFE_ENUM_MAX_LEN`)
`POLYLOGUE_FORCE_PLAIN` color suppression Already fixed (`logging.py:151`: `colors=sys.stderr.isatty() and not force_plain`)
`privacy_config.py` XDG path duplication Already fixed (uses `config_root()` from `polylogue.paths`)
`helper_source_state.py` XDG path duplication Outstanding — duplicates the `XDG_STATE_HOME` fallback inline; if `_roots.py` changes, it diverges silently
`Config` accepts invalid paths; `PrivacyConfig` swallows invalid level Outstanding — relative paths and typo'd levels both succeed silently

Solution

XDG state path duplication

`polylogue/cli/helper_source_state.py:source_state_path` reimplemented the `XDG_STATE_HOME` fallback inline. Replace with `state_home()` from `polylogue.paths` so the fallback stays single-source.

Silent fallback on invalid privacy level

`_privacy_level_value` returned `"standard"` for any unrecognized input — a typo in TOML or a CLI flag silently mapped to "standard". Raise `ValueError` on unknown levels; preserve the explicit `None → "standard"` default.

`Config` path validation

`Config` dataclass had no post-init validation. Relative paths silently shift meaning across processes (CLI from `$PWD` vs MCP server vs systemd unit) — different archive locations for the same nominal `Config(...)`. Add `post_init` requiring `archive_root`, `render_root`, and `db_path` to be absolute `Path`s; raise `ConfigError` otherwise.

Verification

```
$ nix develop -c devtools verify --quick
verify: all checks passed

$ nix develop -c pytest -q tests/unit/core/test_config.py tests/unit/core/test_privacy_config.py
58 passed in 8.72s

$ nix develop -c pytest -q tests/ --ignore=tests/integration
5595 passed, 10 xfailed
```

New tests:

  • `test_privacy_level_value_rejects_unknown_level` + positive cases for known levels including `None`.
  • `test_config_rejects_relative_{archive_root,render_root,db_path}`.

…evel, dedup XDG state

Closes #481.

Four of the six items in #481 were already resolved on master in earlier
audit-fix waves (#504 and predecessors): the content-field denylist now
includes name/body/message/input/output, the max_length=0 falsy bug is
fixed, POLYLOGUE_FORCE_PLAIN already suppresses ConsoleRenderer colors,
and privacy_config.py now imports config_root from polylogue.paths. The
two items addressed here are the remaining real defects.

XDG state path duplication (polylogue/cli/helper_source_state.py)

source_state_path reimplemented XDG_STATE_HOME resolution inline. If the
fallback in polylogue/paths/_roots.py changes, the duplicate diverges.
Replace the inline logic with state_home() from polylogue.paths.

Silent fallback on invalid privacy level (polylogue/schemas/privacy_config.py)

_privacy_level_value silently returned "standard" for any unrecognized
input. A typo in a TOML file or CLI flag would map to "standard" without
warning. Raise ValueError on unknown levels; preserve the explicit
None -> "standard" default.

Config path validation (polylogue/config.py)

Config dataclass had no post-init validation. Relative paths silently
shift meaning across processes (CLI from $PWD vs MCP server vs systemd
unit), producing different archive locations for the same Config(). Add
__post_init__ that requires archive_root, render_root, and db_path to be
absolute Paths; raise ConfigError otherwise.

Tests:
- test_privacy_level_value_rejects_unknown_level (and a positive case
  for known levels including None default).
- test_config_rejects_relative_{archive_root,render_root,db_path}.

Verification: devtools verify --quick green; full unit suite 5595 passed.

Co-Authored-By: Claude <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 59 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 026c1258-eef2-44d6-bbb5-e133bf097449

📥 Commits

Reviewing files that changed from the base of the PR and between 574ad60 and 514e6ca.

📒 Files selected for processing (5)
  • polylogue/cli/helper_source_state.py
  • polylogue/config.py
  • polylogue/schemas/privacy_config.py
  • tests/unit/core/test_config.py
  • tests/unit/core/test_privacy_config.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/privacy-and-config-validation

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

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

@Sinity
Sinity merged commit d2cd2da into master Apr 27, 2026
13 of 14 checks passed
@Sinity
Sinity deleted the feature/fix/privacy-and-config-validation branch April 27, 2026 04:24
@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ 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".

Copilot AI 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.

Pull request overview

This PR addresses the remaining two outstanding items from issue #481 by tightening runtime configuration validation and ensuring schema privacy configuration does not silently accept invalid values, while also deduplicating XDG state-path resolution.

Changes:

  • Add Config.__post_init__ validation to require absolute Path values for archive_root, render_root, and db_path (raising ConfigError otherwise).
  • Make _privacy_level_value reject unknown privacy levels by raising ValueError (while keeping None -> "standard").
  • Replace inline XDG state path fallback logic with polylogue.paths.state_home() and add/extend unit tests for these behaviors.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
polylogue/config.py Adds post-init validation to prevent relative/invalid path configuration at construction time.
polylogue/schemas/privacy_config.py Makes privacy level parsing strict by raising on unknown levels instead of silently defaulting.
polylogue/cli/helper_source_state.py Deduplicates XDG state dir resolution by using state_home() for last-source state storage.
tests/unit/core/test_config.py Adds tests asserting Config rejects relative archive_root, render_root, and db_path.
tests/unit/core/test_privacy_config.py Adds tests asserting unknown privacy levels raise, and known levels (including None) behave as expected.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ 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".

Sinity added a commit that referenced this pull request May 7, 2026
…evel, dedup XDG state (#525)

## Summary

Closes #481.

Four of the six items in #481 were already resolved on master in earlier
audit-fix waves (likely #504 and predecessors). This PR addresses the
two real outstanding defects plus tightens \`Config\` construction.

## Problem

| Sub-item | Status |
| --- | --- |
| \`name\` not in content field denylist | Already fixed
(\`schemas/privacy.py:97\` includes \`name\`, \`body\`, \`message\`,
\`input\`, \`output\`) |
| \`max_length=0\` treated as falsy | Already fixed
(\`schemas/privacy.py:220\`: \`max_length if max_length is not None else
_SAFE_ENUM_MAX_LEN\`) |
| \`POLYLOGUE_FORCE_PLAIN\` color suppression | Already fixed
(\`logging.py:151\`: \`colors=sys.stderr.isatty() and not force_plain\`)
|
| \`privacy_config.py\` XDG path duplication | Already fixed (uses
\`config_root()\` from \`polylogue.paths\`) |
| \`helper_source_state.py\` XDG path duplication | **Outstanding** —
duplicates the \`XDG_STATE_HOME\` fallback inline; if \`_roots.py\`
changes, it diverges silently |
| \`Config\` accepts invalid paths; \`PrivacyConfig\` swallows invalid
level | **Outstanding** — relative paths and typo'd levels both succeed
silently |

## Solution

### XDG state path duplication

\`polylogue/cli/helper_source_state.py:source_state_path\` reimplemented
the \`XDG_STATE_HOME\` fallback inline. Replace with \`state_home()\`
from \`polylogue.paths\` so the fallback stays single-source.

### Silent fallback on invalid privacy level

\`_privacy_level_value\` returned \`"standard"\` for any unrecognized
input — a typo in TOML or a CLI flag silently mapped to "standard".
Raise \`ValueError\` on unknown levels; preserve the explicit \`None →
"standard"\` default.

### \`Config\` path validation

\`Config\` dataclass had no post-init validation. Relative paths
silently shift meaning across processes (CLI from \`\$PWD\` vs MCP
server vs systemd unit) — different archive locations for the same
nominal \`Config(...)\`. Add \`__post_init__\` requiring
\`archive_root\`, \`render_root\`, and \`db_path\` to be absolute
\`Path\`s; raise \`ConfigError\` otherwise.

## Verification

\`\`\`
$ nix develop -c devtools verify --quick
verify: all checks passed

$ nix develop -c pytest -q tests/unit/core/test_config.py
tests/unit/core/test_privacy_config.py
58 passed in 8.72s

$ nix develop -c pytest -q tests/ --ignore=tests/integration
5595 passed, 10 xfailed
\`\`\`

New tests:
- \`test_privacy_level_value_rejects_unknown_level\` + positive cases
for known levels including \`None\`.
- \`test_config_rejects_relative_{archive_root,render_root,db_path}\`.

Co-authored-by: Claude <[email protected]>
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.

fix(schema+config): privacy field denylist + PLAIN logging leak + config path duplication

2 participants