Skip to content

Add persistent gas metering, multi-script selection, and setup/CLI improvements#10

Open
SandraOrtiz-wq wants to merge 4 commits into
python_testingfrom
codex/implement-advanced-relay-features
Open

Add persistent gas metering, multi-script selection, and setup/CLI improvements#10
SandraOrtiz-wq wants to merge 4 commits into
python_testingfrom
codex/implement-advanced-relay-features

Conversation

@SandraOrtiz-wq
Copy link
Copy Markdown
Collaborator

Motivation

  • Provide durable local tracking of Google Apps Script usage so the relay can detect daily resets and avoid exhausting a single deployment ID.
  • Reduce noisy per-request logging and surface compact, actionable gas/quota status to the CLI.
  • Make setup idempotent and user-friendly while enabling multi-script and exit-node configuration for higher throughput and flexible relay chains.
  • Improve adaptive transport stability by pausing route switching when runtime metrics indicate elevated loss/variance.

Description

  • New SQLite-backed gas meter at src/core/gas_meter.py that records per-script_id calls, errors, and bytes_out, supports daily UTC reset, and selects the least-used/healthiest script.
  • Integrated gas meter into DomainFronter (src/relay/domain_fronter.py) to persist counts on each recorded execution, log a compact gas summary every 30s, detect daily resets, warn and auto-switch when a script reaches 90% quota, and fall back when all scripts are exhausted.
  • Replaced round-robin script selection with a gas-aware selector and updated blacklist logic to cooperate with the new selector in DomainFronter.
  • Added GasMeter usage to CLI main.py with --list-scripts and --reset-gas flags to view or reset per-script counters, preserving backward-compatible script_id handling.
  • Reworked the interactive setup wizard (setup.py) to accept multiple script IDs, probe provided script endpoints, optionally configure an exit node (VPS/Cloudflare Worker), toggle relay-chain and features, and write an idempotent config.json with a backup.
  • Added an adaptive-transport stabilization pause in src/core/adaptive_transport/engine.py that temporarily blocks route switching when runtime metrics indicate high variance/loss.
  • Added unit tests: tests/test_gas_meter.py for GasMeter behavior and tests/test_adaptive_loss_pause.py for the adaptive loss-pause logic.

Testing

  • Ran PYTHONPATH=src pytest -q tests/test_gas_meter.py tests/test_adaptive_loss_pause.py and all tests passed (2 passed).
  • An initial pytest invocation without PYTHONPATH=src failed during collection due to import-path setup, which was resolved by running tests with PYTHONPATH=src as shown above.
  • Tests exercise GasMeter.record_call/get_usage/select_best_script and the adaptive engine's loss-pause triggering and behaved as expected.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant