Skip to content

Add trusted TQQQ snapshot package boundary - #216

Closed
Pigbibi wants to merge 3 commits into
mainfrom
codex/qsl-p2-tqqq-trusted-snapshot-package-20260729
Closed

Add trusted TQQQ snapshot package boundary#216
Pigbibi wants to merge 3 commits into
mainfrom
codex/qsl-p2-tqqq-trusted-snapshot-package-20260729

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Bounded P2 TQQQ trusted snapshot package

  • Exact base: 6def35cef7433af57371f668afb75e6123e225c2 (tree 1dd563d90b497ed185db97954ad623a4263cfe03).
  • Tests-first RED: PYTHONPATH=src python3 -m pytest -q tests/test_soxl_tqqq_clean_cutover_snapshot.py failed during collection because soxl_tqqq_clean_cutover_snapshot did not exist.
  • Adds the factory-only frozen TrustedSnapshotPackage, typed external digest/session bindings, descriptor-safe strict readback, canonical JSON validation, and runtime-generated checked-in schema parity.
  • Validation: focused pytest 29 passed; full PYTHONPATH=src python3 -m pytest -q 598 passed, 3 skipped; focused and full Ruff passed; git diff --check and compileall passed.
  • Boundary: offline fixtures only (offline_fixture=true), no provider/data/plugin/replay/broker/cloud/live behavior, and size=0.

Co-Authored-By: Codex <noreply@openai.com>

@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: 2457f9f2e1

ℹ️ 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 on lines +351 to +353
payload = _parse_canonical_json(package.canonical_bytes)
_validate_payload(payload, package.external_bindings)
return package

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recheck the content digest at the consumer boundary

When a factory-created instance's slots are changed through object.__setattr__ (which bypasses frozen=True), this path validates the replacement JSON but never compares sha256(canonical_bytes) with external_bindings.content_sha256. A different, structurally valid fixture therefore retains a stale external digest and is returned as trusted; recompute and verify the content digest before returning the package.

Useful? React with 👍 / 👎.

Comment on lines +58 to +60
try:
return json.dumps(value, ensure_ascii=False, separators=(",", ":"), sort_keys=True).encode("utf-8")
except (TypeError, ValueError) as exc:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject non-finite values during canonical serialization

When a caller passes a non-finite float such as NaN or Infinity, json.dumps defaults to allow_nan=True, so this function returns non-JSON tokens instead of raising SnapshotValidationError; _parse_canonical_json then explicitly rejects those same bytes. Set allow_nan=False so the public canonicalizer cannot generate artifacts that the package reader considers invalid.

Useful? React with 👍 / 👎.

Comment on lines +37 to +38
CANONICAL_DECIMAL_PATTERN = r"(?:[1-9][0-9]*|[1-9][0-9]*\.[0-9]*[1-9])"
_DECIMAL_RE = re.compile(rf"^{CANONICAL_DECIMAL_PATTERN}$")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Allow canonical fractional adjusted closes below one

For any clean-cutover fixture containing a positive split-adjusted price below 1, such as "0.5", this pattern rejects the row even though it is a canonical positive decimal. This conflicts with the existing TQQQ snapshot contract, which accepts every positive finite adjusted close and covers leveraged-ETF history from 2010; add a 0.<nonzero fraction> alternative while continuing to reject zero and the noncanonical .5 form.

Useful? React with 👍 / 👎.

Comment on lines +81 to +84
if any(not _is_canonical_session(session) for session in value):
_invalid("expected_sessions contains an invalid session")
if tuple(sorted(value)) != value or len(set(value)) != len(value):
_invalid("expected_sessions must be sorted and unique")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject weekend dates from the session binding

When both expected_sessions and the payload contain a canonical weekend date such as 2024-01-06, these checks accept it and the factory returns a trusted QQQ/TQQQ package. The existing TQQQ snapshot validator rejects dayofweek >= 5, and a U.S. equity calendar cannot contain Saturday or Sunday sessions, so validate the weekday here before treating the external coverage as trustworthy.

Useful? React with 👍 / 👎.

Co-Authored-By: Codex <noreply@openai.com>

@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: f6e8e91d1f

ℹ️ 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 on lines +366 to +368
if type(bindings) is not ExternalBindings:
_invalid("bindings must be an ExternalBindings value")
raw = _read_trusted_file(trusted_root=trusted_root, relative_path=relative_path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Revalidate bindings before creating the trusted package

When a valid ExternalBindings instance is altered through object.__setattr__ before being passed here, this type check does not rerun its field validation. For example, changing source_sha256 to "invalid" still lets the factory return a TrustedSnapshotPackage, even though the consumer validator subsequently rejects that same package; code relying on the documented guarantee that factory output is already trusted can therefore receive malformed external bindings. Call _validate_external_bindings(bindings) at the factory boundary before reading or constructing the package.

Useful? React with 👍 / 👎.

Co-Authored-By: Codex <noreply@openai.com>
@Pigbibi Pigbibi closed this Jul 29, 2026
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