Skip to content

feat(debug): Tier 2 debugging aids#17

Merged
Multipixelone merged 1 commit into
mainfrom
claude/tier2-debugging-aids
Jun 22, 2026
Merged

feat(debug): Tier 2 debugging aids#17
Multipixelone merged 1 commit into
mainfrom
claude/tier2-debugging-aids

Conversation

@Multipixelone

Copy link
Copy Markdown
Owner

Summary

PR 2 of the plan — Tier 2 (debugging aids), building on the merged Tier 1 safety rails (#16). These are observability/operability improvements; none touch the money-moving decision path. Tier 3 (operational features) remains for a follow-up.

2.1 Structured correlation logging

New logutil.correlated() wraps the worker and buy-flow loggers in a LoggerAdapter that prefixes each line with a short key=value token (provider/item/row) — the same token that already names the screenshot files ({ts}_{provider}_{item}_{tag}.png). One buy's log lines, screenshots, and Sheet row now grep together instead of being reconstructed by hand.

2.2 Full-page diagnostic screenshots

_screenshot previously captured full_page=False always, cropping error banners / mismatched cart lines / disabled controls below the fold — exactly what you need for triage. A module-level _FULL_PAGE_TAGS set (+ blocked_/challenge_/signin_ prefixes) now captures diagnostic tags full-page (no_price, no_place_order, cart_mismatch, timeout, crash, …), while the happy-path review/confirmation/dump shots stay header-only (they go over the notifier, where a tall PNG is just bulk).

2.3 doctor --check-login session probe

doctor only checked profile directory existence — an expired session was discovered only when a real order hit the sign-in wall. The opt-in --check-login flag relaunches each store profile read-only (reusing the buy flow's verify_session) and reports LOGGED-IN / LOGGED-OUT. Default doctor stays browser-free and instant; only the flag launches Chrome, and a launch failure is a warn, not a hard fail.

2.4 Screenshot retention / pruning

The shots dir (systemd StateDirectory) grew unbounded. New retention.prune_shots() deletes files older than ROOMIEORDER_SHOTS_RETENTION_DAYS (default 30, 0 disables). The worker prunes at startup and after each order (best-effort, never disrupts the loop); roomieorder prune-shots [--days N] runs the same sweep by hand.

Tests

pytest (191 passed / 11 skipped), ruff, and mypy src all green. New coverage:

  • test_logutil.py — prefix formatting, empty-field dropping, no-token passthrough
  • test_retention.py — age cutoff, disabled (0), missing dir, *_dom.html/*_probe.txt coverage
  • test_purchase.py_is_full_page_tag matrix + _screenshot passes the right full_page
  • test_cli.pyprune-shots (removes old / disabled), doctor --check-login (reports per-profile; default never probes)
  • test_config.pyshots_retention_days default + override

Docs

README command list (doctor --check-login, prune-shots), examples/env.example (ROOMIEORDER_SHOTS_RETENTION_DAYS), and AGENTS.md screenshot-tags section (adds the cart_mismatch tag from #16, the full-page behavior, and the retention note).

Not in this PR (Tier 3, follow-up)

verify-order, proactive session-freshness notify, healthcheck heartbeat, and the remaining 3.4 doc fixes (status-enum sync, catalog showcatalog).

🤖 Generated with Claude Code


Generated by Claude Code

Operational/debuggability improvements for the buy flow (PR 2 of the plan):

- Correlation logging (logutil.correlated): wrap the worker and buy-flow loggers
  in a LoggerAdapter that prefixes each line with a provider/item/row token —
  the same token that names the screenshot files — so one buy's log lines,
  shots, and Sheet row grep together.
- Full-page diagnostic screenshots: _screenshot now captures full-page for
  failure tags (no_price, no_place_order, cart_mismatch, blocked_*, challenge_*,
  signin_*, timeout, crash, …) so below-the-fold error banners aren't cropped;
  the review/confirmation/dump shots stay header-only for notifier size.
- doctor --check-login: optional read-only session probe that relaunches each
  store profile (reusing verify_session) and reports LOGGED-IN / LOGGED-OUT, so
  an expired session is caught before a real order hits the sign-in wall. Default
  doctor stays browser-free.
- Screenshot retention: a shots dir that grew unbounded is now pruned by the
  worker (startup + after each order) and via `roomieorder prune-shots`, gated by
  ROOMIEORDER_SHOTS_RETENTION_DAYS (default 30, 0 disables).

Tests cover the correlation prefix, full-page tag selection + _screenshot wiring,
prune_shots (age/disabled/missing-dir/artifact coverage), the new config vars,
and the prune-shots / doctor --check-login CLI surfaces.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J322vufhqKDvdJmukTZdkq
@Multipixelone Multipixelone merged commit a0ba74c into main Jun 22, 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.

2 participants