Skip to content

Return structured errors for excessive KV retention - #494

Open
prk-Jr wants to merge 2 commits into
mainfrom
fix/323-structured-ttl-limit
Open

prk-Jr wants to merge 2 commits into
mainfrom
fix/323-structured-ttl-limit

Conversation

@prk-Jr

@prk-Jr prk-Jr commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Return KvError::TtlLimitExceeded { requested, maximum } when typed or raw KV TTL writes exceed the portable 365-day cap, including writes through named handles. Callers can distinguish a retention rejection without parsing a generic validation message.
  • Preserve the 60-second minimum, 365-day cap, pre-backend rejection, and HTTP 400 mapping. This implements the structured-error alternative in Allow supported KV retention windows beyond one year #323; multi-year retention and configurable caps remain deferred.
  • Document explicit downstream retention handling in place of unconditional warning-and-clamp behavior. Raising the cap requires a provider-aware contract: the pinned Fastly SDK converts TTL seconds to u32, with zero fallback on overflow; Spin does not support TTL writes.

Changes

Crate / File Change
edgezero-core/src/key_value_store.rs Add the structured error and HTTP mapping; test named typed/raw writes at inclusive limits, adjacent invalid durations, two years, and Duration::MAX, with backend-call assertions.
docs/guide/kv.md Explain the portable policy, error handling compatibility, and downstream migration.
docs/superpowers/specs/2026-11-13-kv-ttl-limit-error-design.md Record the chosen contract, alternatives, and preservation requirements.
docs/superpowers/plans/2026-11-13-kv-ttl-limit-error.md Record the completed implementation and verification plan.

Closes

Closes #323.

Test plan

Historical author-reported local verification below (original head unrecorded unless an explicit SHA is given). These results, counts, timings and negative controls were not rerun in this audit, and their underlying local logs were unavailable; checked boxes retain the original report. At the current head 5e63adc2, all 28 reported hosted checks are passing.

Verified locally using Rust/Cargo 1.98.1 and Node 24.20.0. Cargo checks/tests used --locked --offline.

  • cargo test --workspace --all-targets — 1,554 passed, zero failed, one existing ignored test. Local-server fixtures needed socket access outside the restricted sandbox.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • cargo check --workspace --all-targets --features "fastly cloudflare spin"
  • WASM compilation checks: Fastly wasm32-wasip1, Spin wasm32-wasip2, Cloudflare wasm32-unknown-unknown, each with its adapter feature.
  • Docs: npm run lint, npm run format, and npm run build.
  • Regression failed on the previous generic over-cap error and passes with the structured error. Named-handle cases verify exact error fields and no backend call for rejected TTLs.
  • Core rustdoc completed; two existing warnings in untouched manifest.rs and test_env.rs, none in changed KV docs.
  • Excluded examples/app-demo workspace tests — not run.
  • Provider runtime writes/manual edgezero serve testing — not run; adapter implementations and supported TTL bounds are unchanged.

Focused local regression command from the repository root:

cargo +1.98.1 test --locked -p edgezero-core key_value_store::tests

This command uses an in-memory backend through actual KV handles; it requires no provider account or credentials.

Checklist

  • Changes follow CLAUDE.md conventions.
  • No Tokio dependencies added to core or adapter crates.
  • No route parameter changes or new direct application http imports.
  • Named-handle tests exercise KvRegistry; production store wiring is unchanged.
  • New code has regression tests.
  • No secrets or credentials committed.

@prk-Jr prk-Jr self-assigned this Nov 13, 2026
@prk-Jr
prk-Jr marked this pull request as ready for review November 13, 2026 08:23
@prk-Jr prk-Jr added this to the 202611 milestone Nov 13, 2026

@dhruv8sh dhruv8sh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

PR Review

Summary

Adds a structured KvError::TtlLimitExceeded { requested, maximum } for TTLs above MAX_TTL while keeping the HTTP 400 mapping. The change is narrow, well tested, and covers every "Done when" item in #323. Approving.

😃 Praise

  • Tight scope: a one-line change in the validator, HTTP 400 is kept, and adapters are untouched.

Findings

Non-blocking

  • 📝 Silent behaviour change for existing matchers: callers that matched over-cap TTLs as KvError::Validation(_) will now fall through to their catch-all branch. Because KvError is already #[non_exhaustive], nothing fails to compile. The HTTP status is still 400, and docs/guide/kv.md already documents this, so a changelog or release note entry would be enough.
  • 📝 Fastly claim checked: the Fastly SDK converts the TTL with ttl.as_secs().try_into().unwrap_or_default() into a u32 (fastly-0.13.1/src/kv_store/handle.rs:412). 365 days fits, so the current cap is safe. Any future configurable cap must reject values above u32::MAX seconds on Fastly; otherwise the TTL silently becomes 0.
  • 🌱 Ready for a configurable cap: maximum always equals MAX_TTL for now. Because the error reports the cap that was actually applied, the per-store cap the issue prefers can be added later without breaking the API.

CI Status

  • fmt: PASS
  • clippy: PASS
  • tests: PASS
  • feature check (fastly cloudflare spin): PASS

@ChristianPavilonis ChristianPavilonis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

😃 Clear retention-policy contract. The structured error preserves the existing TTL bounds, pre-backend rejection, and HTTP 400 mapping. The migration guidance in docs/guide/kv.md:206–241 clearly distinguishes the portable cap from provider capabilities and explains how callers can replace silent clamping with an explicit policy decision.

No new defects found. Formatting, all-feature Clippy, workspace tests, feature compilation, all three adapter WASM compilation checks, and docs checks passed.

@prk-Jr

prk-Jr commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Addressed the non-blocking migration-note feedback in c31e8f9: CHANGELOG.md now has an Unreleased entry explaining that excessive TTLs return TtlLimitExceeded instead of Validation, so existing matchers need explicit handling even though their catch-all branches still compile. It links the existing migration guide and records unchanged TTL bounds, pre-backend rejection and HTTP 400. Configurable caps and multi-year retention remain deferred; no adapter behavior changed. Local Rust and docs gates pass; hosted CI for the new revision is complete: all 29 reported checks passed.

This branch has not been deployed

No deployments
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.

Allow supported KV retention windows beyond one year

3 participants