Skip to content

[codex] Align local state persistence and schedule docs#5

Merged
DavyMorgan merged 3 commits into
mainfrom
fix/repo-runtime-mismatches
Apr 12, 2026
Merged

[codex] Align local state persistence and schedule docs#5
DavyMorgan merged 3 commits into
mainfrom
fix/repo-runtime-mismatches

Conversation

@DavyMorgan

Copy link
Copy Markdown
Collaborator

What changed

  • persist and restore last_rebase in the local SQLite state path so db.py matches the Cloudflare Worker/D1 behavior
  • add a regression test covering save_state/load_state round-tripping last_rebase
  • update the local engine help text and README schedule language to match the actual Worker cadence: 5-minute updates, daily rebalance, weekly reconstitution plus rebalance
  • add .trees/ to .gitignore so local worktrees stay untracked

Why

There were two repo/runtime mismatches:

  1. local db.py dropped last_rebase, so local runs were not behavior-equivalent to production around rebase tracking
  2. the local entrypoint/docs still described older 30-minute/weekly/biweekly schedules, while the deployed Worker runs on 5-minute/daily/weekly cadences

Impact

  • local SQLite runs now preserve rebase metadata the same way production does
  • the docs and CLI help now describe the real schedule users and maintainers see in production
  • .trees/ worktrees can be used safely without risking accidental pushes

Validation

  • /Users/yu_zheng/workspace/gp300/.venv/bin/python -m pytest -q test_db.py
  • /Users/yu_zheng/workspace/gp300/.venv/bin/python -m pytest -q
  • /Users/yu_zheng/workspace/gp300/.venv/bin/python main.py --help

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 12, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
gp300 6607fbe Commit Preview URL

Branch Preview URL
Apr 12 2026, 06:43 PM

@DavyMorgan DavyMorgan marked this pull request as ready for review April 12, 2026 18:36
Copilot AI review requested due to automatic review settings April 12, 2026 18:36

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

Aligns local SQLite state persistence and user-facing schedule documentation with the production Cloudflare Worker/D1 behavior, particularly around last_rebase tracking and cron cadence.

Changes:

  • Persist/restore last_rebase in the local state JSON blob via db.save_state/db.load_state.
  • Add a regression test ensuring last_rebase round-trips through local persistence.
  • Update README + main.py --help schedule language and ignore local .trees/ worktrees.

Reviewed changes

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

Show a summary per file
File Description
db.py Persists last_rebase into the local state blob and restores it on load.
test_db.py Adds a regression test for last_rebase round-tripping through SQLite state.
README.md Updates schedule text and local run/test commands.
main.py Updates CLI usage/help strings to reflect the real cadence.
.gitignore Ignores .trees/ to prevent accidental commits of worktrees.

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

Comment thread main.py
Comment on lines 41 to 53
def main():
parser = argparse.ArgumentParser(description="G&P 300 Index Engine")
parser.add_argument(
"--update", action="store_true", help="Regular price update (30-min cycle)"
"--update", action="store_true", help="Scheduled 5-minute price update"
)
parser.add_argument(
"--rebalance", action="store_true", help="Recompute weights (weekly cycle)"
"--rebalance", action="store_true", help="Scheduled daily rebalance"
)
parser.add_argument(
"--reconstitute",
action="store_true",
help="Re-select constituents (biweekly cycle)",
help="Scheduled weekly reconstitution + rebalance",
)

Copilot AI Apr 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/engine.run_full_pipeline docstring still describes reconstitute as biweekly and rebalance as weekly, which now conflicts with the updated CLI/help text (5-minute/daily/weekly). Consider updating the engine docstring too so schedule documentation is consistent across the codebase.

Copilot uses AI. Check for mistakes.
Comment thread test_db.py Outdated
Comment on lines +11 to +27
ts = datetime(2026, 4, 12, 18, 30, tzinfo=timezone.utc)
last_rebase = datetime(2026, 4, 6, 0, 0, tzinfo=timezone.utc)
state = IndexState(
value=1000.0,
divisor=0.0005,
weighted_entropy=0.5,
num_constituents=0,
timestamp=ts,
constituents=[],
last_rebase=last_rebase,
)

db.save_state(conn, state)
loaded = db.load_state(conn)

assert loaded is not None
assert loaded.last_rebase == last_rebase

Copilot AI Apr 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test opens a SQLite connection but never closes it. Closing the connection (e.g., via try/finally or a fixture) avoids leaking file handles and reduces flakiness on platforms with strict file locking.

Suggested change
ts = datetime(2026, 4, 12, 18, 30, tzinfo=timezone.utc)
last_rebase = datetime(2026, 4, 6, 0, 0, tzinfo=timezone.utc)
state = IndexState(
value=1000.0,
divisor=0.0005,
weighted_entropy=0.5,
num_constituents=0,
timestamp=ts,
constituents=[],
last_rebase=last_rebase,
)
db.save_state(conn, state)
loaded = db.load_state(conn)
assert loaded is not None
assert loaded.last_rebase == last_rebase
try:
ts = datetime(2026, 4, 12, 18, 30, tzinfo=timezone.utc)
last_rebase = datetime(2026, 4, 6, 0, 0, tzinfo=timezone.utc)
state = IndexState(
value=1000.0,
divisor=0.0005,
weighted_entropy=0.5,
num_constituents=0,
timestamp=ts,
constituents=[],
last_rebase=last_rebase,
)
db.save_state(conn, state)
loaded = db.load_state(conn)
assert loaded is not None
assert loaded.last_rebase == last_rebase
finally:
conn.close()

Copilot uses AI. Check for mistakes.
Comment thread README.md Outdated
Comment on lines +146 to +150
# Run the CLI locally
python -m cli
python3 -m cli

# Run tests
python test_engine.py
python3 -m pytest -q

Copilot AI Apr 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README now uses python3 explicitly for running the CLI/tests. This can be less portable on some environments (notably Windows) where the command is typically python/py. Consider using python -m ... (or mentioning both) to keep the instructions cross-platform.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator Author

@copilot review

Copilot AI commented Apr 12, 2026

Copy link
Copy Markdown

@copilot review

All three review findings were addressed in commit 6607fbe:

  1. Engine docstring (src/engine.py): Updated reconstitute/rebalance param descriptions from "biweekly"/"weekly" to "weekly reconstitution flow"/"daily rebalance flow" to match the production cadence.
  2. Connection leak (test_db.py): Wrapped the test body in a try/finally block so conn.close() is always called.
  3. README portability (README.md): Changed python3 -m cli / python3 -m pytest to python -m cli / python -m pytest with a note to use python3 when needed.

@DavyMorgan DavyMorgan merged commit 5dcde70 into main Apr 12, 2026
2 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.

3 participants