Skip to content

feat: usage ledger wiring, 429 retry classification, no per-step transcript clone - #66

Merged
ajianaz merged 1 commit into
developfrom
feat/reliability-cost-hygiene
Sep 12, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/reliability-cost-hygiene

Conversation

@ajianaz

@ajianaz ajianaz commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

What (description of the change)

Three tight cost/reliability changes: (1) Provider::last_usage (default None) + OpenAiProvider capturing the response usage object; the turn loop writes one durable UsageRecord per provider step, anchored to the last committed entry, via a transition-free replay-safe usage-only commit. (2) Retry classification extended: 429/rate-limit joins timeout as transient. (3) Removed the per-step s.entries().to_vec() clone — complete() borrows the storage slice.

Why (the problem you're solving)

tole status has always shown 0/0 tokens because provider usage was never captured although the whole ledger + display path existed. Live E2E today hit 429 five times in one session — the timeout-only retry classification missed the most common transient. The per-step full-transcript clone is a needless O(n) allocation per provider step on long sessions (Manus context-engineering post: prefill dominates agent cost — every needless allocation on the request path compounds).

Testing (how you verified this works)

  • New tests: usage_rows_are_written_durably_per_step (2 steps → 2 rows, anchored to real entries, CLI-sum compatible), no_usage_rows_without_provider_usage (mock without usage → 0 rows), provider_429_rate_limit_retried_once; 3 existing retry tests updated to the new audit label. Full suite 155 green, both feature profiles, fmt + clippy -D warnings clean, CodeCora scan clean.
  • Live E2E with the fresh release binary: real mission reports usage: 1545 in / 4 out tokens in tole status (was 0/0).

…script clone

Cost & reliability hygiene, three tight changes:

- Usage ledger: OpenAiProvider captures the response's usage object and
  exposes it via the new Provider::last_usage (default None - mocks stay
  free). The turn loop writes one durable UsageRecord per provider step,
  anchored to the last committed entry (exactly the request's input
  scope), as a transition-free replay-safe Record::Usage line. tole
  status now shows real token totals instead of 0/0.
- Retry classification: 429/http-rate-limit responses join timeouts as
  transient (live E2E hit 429 five times in one session today); audit
  entry renamed to 'provider transient failure, retrying'.
- The per-step s.entries().to_vec() clone is gone: complete() borrows
  the storage slice directly.

Live-verified: fresh run reports 1545 in / 4 out tokens via status.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit adfaea5 into develop Sep 12, 2026
13 checks passed
@ajianaz
ajianaz deleted the feat/reliability-cost-hygiene branch September 12, 2026 06:36
ajianaz added a commit that referenced this pull request Sep 12, 2026
…ecovery (#68)

* chore(release): v0.3.0 — reliability & long-running work

Version bump 0.2.0 -> 0.3.0 (minor: real features per house versioning),
CHANGELOG entries for #57-#66, publish workflow extended to ship
tole-cli (version-pinned core dependency, published after core),
cli manifest pins tole-core 0.3.0.

* fix(ci): run security checks on PRs targeting main too

The main ruleset REQUIRES 'Cargo Audit' and 'Trivy FS Scan', but
security.yml only produced them for PRs targeting develop - release PRs
to main were permanently blocked (the documented impossible-required-
check trap: admin cannot bypass required checks). Align the trigger set
with ci.yml (develop, main).

* fix: harden replay safety, guard resume, jail validation, torn-line recovery

CodeCora full-scan findings triaged pre-tag (1 CRITICAL + 3 MAJOR real):
- turn: derive ReplaySafety from tool risk (CRITICAL #33) - a crash after
  a Write/Destructive effect ran must not blindly re-execute on resume;
  Guarded now forces re-consultation of the approver.
- turn: Guarded resume actually consults the approver and settles the
  intent either way (MAJOR #34) - Allow replays once; deny/absent settles
  the sandwich as failed instead of livelocking every future resume.
- jails: component-based path validation everywhere (MAJOR #6, INFO #12)
  - Windows drive-prefixed/rooted relatives escape via join despite not
  being is_absolute(); substring '..' both misses them and rejects benign
  names. Uniform across WriteFileTool, core file_tools, read_file.
- storage: torn-line accounting (MAJOR #47) - good_bytes counted before
  parse made a newline-terminated invalid final line look consumed; the
  truncation never fired and the next append bricked the session. Now
  counted only after a successful parse; empty lines still counted.
Tests: guarded deny (settles, no livelock), guarded allow (fires exactly
once), full workspace green; fmt/clippy clean; CodeCora diff review clean.

---------

Co-authored-by: ajianaz <[email protected]>
ajianaz added a commit that referenced this pull request Sep 22, 2026
…119) (#124)

- openai complete(): a non-2xx response is now surfaced as
  'http status: N — <scrubbed body snippet>' instead of being mangled
  by read_json into a misleading 'malformed response'. The phrasing
  is load-bearing: the turn loop's transient-retry classification
  (#66) matches 'http status:' so 429/5xx keep auto-retrying.
- git add lexical jail: reject Windows drive-letter absolute paths
  (C:\..., C:/...) that slipped past the '/'/'\\' checks (cora
  full-scan #30); colon at position 1 only, 'weird:name.txt' stays
  legal. Unit tests cover all four absolute shapes + relative pass.

Co-authored-by: ajianaz <[email protected]>
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