Closes #3698. Follow-up to #3594, which fixed `headroom/learn/writer.py` correctly but left three gaps. ## 1. The write half had no regression guard `test_apply_does_not_accumulate_carriage_returns_on_crlf_file` passes on `main` with the fix reverted — its assertion (`raw.count(b"\r") == raw.count(b"\r\n")`) holds for a CRLF-preserving file too. So the `newline="\n"` pins, which *are* the fix, were unguarded. This cannot be caught by asserting on file bytes on POSIX: CPython's C `TextIOWrapper` picks the newline translation target at compile time (`#ifdef MS_WINDOWS`), so monkeypatching `os.linesep` does not simulate Windows. The new test spies on `Path.write_text` and drives the real writer `.write()` methods. Stripping the kwargs from all seven sites: ``` tests/test_learn/test_writer.py ................................F E AssertionError: learn writers wrote without newline='\n': [ E .../data/memory/MEMORY.md, .../instructions.md, .../myproject/AGENTS.md, E .../myproject/CLAUDE.local.md, .../myproject/CLAUDE.md, E .../myproject/GEMINI.md, .../myproject/GROK.md] =================== 1 failed, 32 passed =================== ``` All seven named — and note the other 32 pass, including the old test, confirming it was never a guard. ## 2. The same bug was still live in the memory writers Ten call sites, all nine from the issue plus **`headroom/memory/sync.py:137`** (`_save_sync_state`), which the issue missed: `writers/base.py:168` · `writers/claude_writer.py:119` · `writers/cursor_writer.py:130` · `bridge.py:126, 394, 650` · `sync.py:137` · `sync_adapters/codex_agent.py:124` · `sync_adapters/claude_code.py:196, 239` These write files that **overlap** with the learn writers (`~/.claude/CLAUDE.md`, `AGENTS.md`), so on Windows a file flipped between LF and CRLF depending on which subsystem wrote last. **No live accumulation bug:** every reader of these files uses `read_text()`, which normalizes — that is the key difference from `learn/writer.py`'s `read_bytes().decode()`, which is what let `\r` pile up. Checked all of them (`bridge.py:114, 222, 617`, `writers/base.py:193`, `writers/cursor_writer.py:103`, `sync_adapters/claude_code.py:106, 163, 178, 216`, `sync_adapters/codex_agent.py:48, 83`, `sync.py:127`). **But the churn is more than cosmetic**, which the issue did not note: `claude_code.py:252` and `codex_agent.py:135` read via `read_bytes()` for `fingerprint()` change-detection hashing. An EOL flip changes the hash, so a CRLF/LF flip reads as a content change and triggers a spurious re-sync. Three new tests cover the writer, bridge and sync-adapter paths; all three fail with the pins stripped. ## 3. No unit test had ever run on Windows The sharded `test` job is ubuntu-only, and `build-wheel-windows` builds without testing — which is how a Windows-only bug shipped twice. Added `test-windows-newline`: consumes the existing `headroom-wheel-windows` artifact and runs only tests marked `windows_newline`. Marker registered in `pyproject.toml`. **Known limitation, documented in the job comment:** it is gated on the `packaging` paths-filter (that is what builds the wheel), so a pure-Python PR skips it. The ubuntu shards still run the same marked tests — they assert the kwarg, which fails on any platform — so this is the Windows-side backstop, not the only guard. Making it fire on every writer change would mean gating the Windows Rust wheel build on `code`, which is too expensive to do unasked. ## Verification - 4 guards proven to fail before, pass after. - `tests/test_learn/ tests/test_memory/ tests/test_memory_sync.py` → **950 passed, 4 skipped**. - Adjacent suites → 168 passed. `pytest tests -m windows_newline` → 4 passed, no marker warning. - `actionlint .github/workflows/*.yml` → exit 0. Action versions match the file's conventions (`checkout@v7`, `setup-python@v7`, `download-artifact@v8`). `CONTRIBUTING.md` states the invariant once under Coding standards: Headroom writes LF and normalizes on read, on every platform. ## Not in this PR Issue section 3's release-note line about the one-time EOL churn on Windows (the first `--apply` rewrites the whole file to LF). Harmless under `autocrlf=true`, but worth a release note; `CHANGELOG.md` edits are blocked by `changelog-guard.yml`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
6.4 KiB
Contributing to Headroom
Thanks for contributing! Please skim this before opening a PR : the policies exist because we've been burned skipping them, not because we love paperwork.
By participating, you agree to our Code of Conduct.
Where does my contribution go?
| Type | What to do |
|---|---|
| 🐛 Bug or small fix | Open a PR (with repro + test) |
| ✨ New feature / architectural change | Open an issue or ask in Discord first. |
| 🧹 Refactor-only | Don't. Only if a maintainer asked, as part of a concrete fix. |
🧪 Test/CI-only PR chasing a known main failure |
Don't. We're tracking it. |
| 📦 New dep or version bump | PR with written justification. |
| ❓ Question | Ask in Discord #help |
Open PR cap: 10 per author. Get existing ones merged before opening more.
Guiding principles
- Verification is the author's job, not the reviewer's.
- Supply chain is a real threat. Dependency changes get human review, every time.
Bug fixes
Every bug-fix PR must include:
- A reproduction — minimal code, failing test, or steps.
- A test that fails before your fix and passes after (unit, integration, or e2e).
If you genuinely can't write a test, say so explicitly and explain how you verified.
"Real behavior proof" — required on every external PR
We can't merge what we can't verify. Include a Real behavior proof section in the PR body covering:
- Setup you tested on (OS, Python, config, provider/model)
- Exact command or steps you ran after the patch
- After-fix evidence + observed result
- What you did not test
✅ Counts: screenshots, recordings, terminal output, copied live output, linked artifacts, redacted runtime logs. ❌ Does not count alone: unit tests, mocks, snapshots, lint, typechecks, green CI. Have them too — but they prove the test passes, not that the feature works.
PRs missing this may be autoclosed.
New features
Before writing code:
- Open a feature-request issue (or raise in Discord).
- Get a 👍 from a core maintainer before implementing.
- Include a short spec covering:
- API surface (public functions, config, CLI flags)
- Changes to existing behavior
- User stories — Given / When / Then, golden path + one edge case
- Failure modes
- Recovery / resilience
- Security considerations
Short and concrete beats long.
Dependencies & supply chain
A human maintainer reviews every dep change. PRs that add or bump a package must justify:
- Why this package (vs. doing it ourselves / using existing deps)
- Who maintains it (activity, release cadence, security history)
- Install surface (transitive deps, native code, install/runtime network)
- Why this version — permitted reasons: bug fix, security patch, required new functionality. Cosmetic bumps will be closed.
PR workflow
- Fork, branch from
main. - Install Node 18+ and run
uv sync --extra devthenmake install-git-hooks— installs repo pre-commit checks on every commit, commitlint on every commit message, and ci-precheck on every push. - One logical change per PR.
- Add tests.
uv run pytest·uv run ruff check .·uv run ruff format .- Do not edit
CHANGELOG.md— release-please generates it from your Conventional Commit PR title, so a clearfix(...)/feat(...)title is your changelog entry. A CI guard rejects manual edits. - Open the PR with a clear description +
Real behavior proof+ any spec/justification required, and keep the PR in draft until theReview Readinessboxes are complete.
Title format (conventional commits): feat:, fix:, docs:, test:, refactor:.
Commit message format is enforced locally by the repo's commit-msg hook and again in CI.
Review: CI green, one maintainer review, coverage held/improved.
Development setup
git clone https://github.com/headroomlabs-ai/headroom.git
cd headroom
python -m venv .venv && source .venv/bin/activate
node --version # Node 18+ required for commitlint hooks
python -m pip install --upgrade pip
python -m pip install -e ".[dev,relevance,proxy]"
python -m pytest
Headroom uses a pyproject.toml/maturin build backend. Older pip
versions may fail editable installs by looking for setup.py; upgrade pip
first or use uv sync --extra dev.
Dev Containers
Two configs ship for VS Code / Codespaces:
.devcontainer/devcontainer.json— Python 3.12,uv, Node.js,gh..devcontainer/memory-stack/devcontainer.json— adds Qdrant + Neo4j sidecars (useqdrant:6333,neo4j://neo4j:7687).
Inside, use: uv run ruff check ., uv run pytest, etc.
Optional automated review
This repository includes .github/copilot-instructions.md so maintainers can opt into GitHub Copilot code review without adding workflow billing noise to every PR.
Enable or disable automatic Copilot review in Settings → Rules → Rulesets → Automatically request Copilot code review. Keep it off unless maintainers explicitly want the extra review traffic.
Coding standards
- Ruff for lint + format, line length 100, PEP 8.
- Type hints on public functions; Google-style docstrings.
- Cover new behavior + edge cases; aim >80% coverage on new code.
- Python 3.10+. Optional features go behind extras.
- Headroom writes LF and normalizes on read, on every platform. Pass
newline="\n"to everywrite_text/openthat writes a context, memory, or state file, and normalize\r\n/\rwhen you read one back. Without the pin,TextIOWrappertranslates\nto\r\non Windows, and a reader that decodes bytes directly then re-writes accumulates carriage returns (#3594); even with a normalizing reader, two subsystems writing the same file (CLAUDE.md,AGENTS.md) flip it between LF and CRLF (#3698). Cover new write sites with@pytest.mark.windows_newline— those tests assert thenewline=kwarg (an artifact assertion cannot fail on POSIX) and also run onwindows-latestin CI.
Architecture principles
Safety first: never drop user/assistant content, never break tool call/response pairing, malformed content passes through unchanged, prefer false negatives.
Performance: transforms <50ms at P99, lazy-load optional deps, profile before optimizing.
Contributors are credited in CHANGELOG, the GitHub contributors page, and release notes. Thanks again. 💚