Skip to content

feat(harvest): --since date filter for Codex harvest (recency scoping) - #117

Merged
ooiyeefei merged 1 commit into
mainfrom
feat/harvest-since-filter
May 31, 2026
Merged

ooiyeefei merged 1 commit into
mainfrom
feat/harvest-since-filter

Conversation

@ooiyeefei

@ooiyeefei ooiyeefei commented May 31, 2026 •

Copy link
Copy Markdown
Owner

Closes #116.

Why

Codex harvest scopes by cwd (folder), so a session that ran in this repo's folder but was about a different/old subject still gets harvested. Real example: harvesting Spanweave's repo pulled in a "Issue #24 specify decisions for demo login rate limiting" record — that was the old workflow-engine's throwaway demo app, not Spanweave (which has no login or rate-limiting). Folder ≠ topic.

What

spanweave harvest --tool codex --since YYYY-MM-DD filters to sessions updated on/after the date — recent work is the most relevant. Date comes from the rollout's frontmatter updated_at, falling back to the date-prefixed filename; undateable records are excluded under --since (can't prove recency). Inclusive comparison. Codex-only (Claude memory has no per-session dates). The cross-project memory_summary.md is excluded whenever --since is set. Bad dates → clean click.BadParameter error (exit 2, no traceback).

Verified independently (not just agent report)

Real ~/.codex against the Spanweave repo path:

  • since=None → 4 records (incl. the off-topic "issue W24: Integration tests + E2E validation #24 login rate limiting")
  • since=2026-05-20 → 1 record; off-topic ones excluded ✓
  • since=2027-01-01 → 0 (boundary correct)

Full suite 345 passed · ruff clean · pyright 0 errors. +9 tests.

Note

--since is a recency lever, not a topic classifier — dates don't perfectly separate subjects (a clean and an off-topic record can share a date). It's the right 80/20 tool; true topic-scoping (keyword/semantic) remains future work under #116's spirit.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added --since YYYY-MM-DD option to the spanweave harvest command to restrict Codex native-memory harvesting to sessions updated on or after a specified date.
    • Sessions are filtered by their update date, with fallback to filename date if unavailable.
  • Tests

    • Added test coverage for date filtering behavior and invalid date error handling.

Codex harvest scopes by cwd (folder), so same-folder/different-subject sessions
leak in (#116). Add --since YYYY-MM-DD to harvest only sessions updated on/after
a date — the most-recent work is the most relevant. Uses rollout frontmatter
updated_at, falling back to the date-prefixed filename. Codex-only; the
cross-project memory_summary.md is excluded when --since is set.

Closes #116.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: b49bbf7a-1ce2-4249-a0f5-3cbbfacdcbd0

📥 Commits

Reviewing files that changed from the base of the PR and between 78b4610 and 4feb02d.

📒 Files selected for processing (5)
  • spanweave/cli/commands/harvest.py
  • spanweave/harvest/__init__.py
  • spanweave/harvest/codex.py
  • tests/test_harvest_codex.py
  • tests/test_harvest_command.py

📝 Walkthrough

Walkthrough

The PR adds a --since YYYY-MM-DD option to the spanweave harvest CLI, restricting Codex native-memory harvesting to sessions updated on or after a specified date. The option is validated at the CLI layer, threaded through orchestration, and implemented as a date-based filter in the core Codex reading logic, with comprehensive test coverage.

Changes

Codex recency filtering via --since option

Layer / File(s) Summary
CLI --since option and validation
spanweave/cli/commands/harvest.py
The harvest_command adds a --since Click option with a _validate_since callback to parse and validate ISO dates, passes the option through to harvest_tool, and updates help text with a usage example.
Harvest tool orchestration
spanweave/harvest/__init__.py
The harvest_tool function accepts the new since parameter and forwards it to harvest_codex_memory. Docstring clarifies that since only affects Codex harvesting.
Codex recency filter implementation
spanweave/harvest/codex.py
Adds date-parsing and effective-date-resolution helpers, extends read_codex_records and harvest_codex_memory to accept since, and applies the recency filter during rollout-summary iteration. Cross-project memory_summary.md is excluded when since is set.
Unit tests for recency filtering
tests/test_harvest_codex.py
Introduces helpers to generate dated rollout summaries and test scenarios. New tests verify filter behavior: exclusion of older sessions, inclusive boundary dates, fallback to filename dates, handling of undateable records, and exclusion of cross-project summaries.
CLI integration tests for --since option
tests/test_harvest_command.py
Adds tests that verify harvest --tool codex --since <date> stages only recent sessions and that invalid --since dates produce clean error output.

Sequence Diagram

sequenceDiagram
  participant User
  participant CLI
  participant HarvestTool
  participant CodexRead
  participant Filter
  User->>CLI: harvest --tool codex --since 2026-05-20
  CLI->>CLI: validate since as ISO date
  CLI->>HarvestTool: harvest_tool(codex, since=2026-05-20)
  HarvestTool->>CodexRead: harvest_codex_memory(since=2026-05-20)
  CodexRead->>CodexRead: parse since to date object
  CodexRead->>Filter: iterate rollout summaries
  Filter->>Filter: resolve effective date (updated_at or filename)
  Filter->>Filter: compare date >= since?
  Filter->>CodexRead: include/exclude record
  CodexRead->>User: return harvested sessions from 2026-05-20 onward
Loading

🎯 3 (Moderate) | ⏱️ ~20 minutes

A harvest of dates takes care,
When sessions from the past we spare;
With --since the filter's keen,
Only recent rolls convene! 🌾


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

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

@ooiyeefei
ooiyeefei merged commit 4db0271 into main May 31, 2026
7 checks passed
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.

harvest: Codex scoping is by cwd (folder), not topic — same-folder/different-subject sessions leak in

1 participant