Skip to content

Conversation

@shikhar
Copy link
Member

@shikhar shikhar commented Jan 21, 2026

Fixes #46, #39

@greptile-apps
Copy link

greptile-apps bot commented Jan 21, 2026

Greptile Summary

Changed binary encoding of ObjectKey length from storing the actual value to storing length - 1, enabling support for the full 1024-character keys that are already allowed by validation in src/types.rs. The 10-bit field previously supported 0-1023, but now supports 1-1024 by encoding the value minus one (similar to how kind_len was already encoded).

Key changes:

  • Bumped cache version from 2 to 3 (incompatible format change)
  • Added validation to reject zero-length keys in CacheKeyHeader::new
  • Changed boundary check from key_len >= 1024 to key_len > 1024
  • Updated encoding to store key_len - 1 in the 10-bit field
  • Updated decoding to add 1 when extracting the key length
  • Updated all tests to reflect new maximum (1024) and validation requirements

This fix resolves the mismatch between validation (allowing 1024-char keys) and encoding (previously rejecting them), eliminating the 500 errors that occurred when attempting to cache objects with exactly 1024-character keys.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is well-tested with comprehensive unit tests and property-based tests covering the new 1024-character limit. The version bump ensures backward incompatibility is handled explicitly, preventing silent data corruption. The implementation is symmetric (encoding/decoding both apply the minus-one transformation), and the boundary validations are correct.
  • No files require special attention

Important Files Changed

Filename Overview
src/cache.rs Encodes key length as length - 1 to support full 1024-char keys; version bumped to 3

Sequence Diagram

sequenceDiagram
    participant Client
    participant CacheKey
    participant CacheKeyHeader
    participant Storage

    Note over Client,Storage: Encoding Process with Version 3
    Client->>CacheKey: encode with kind, object key, page id
    CacheKey->>CacheKeyHeader: create header with lengths
    
    alt Invalid key length
        CacheKeyHeader-->>CacheKey: Return error
    else Valid key length (1 to 1024 chars)
        Note over CacheKeyHeader: Encode length as (length minus one)
        CacheKeyHeader->>CacheKeyHeader: Pack into 5 byte header
        CacheKeyHeader-->>CacheKey: Return header bytes
        CacheKey->>Storage: Write header, kind, key
    end

    Note over Client,Storage: Decoding Process with Version 3
    Storage->>CacheKey: decode from storage
    CacheKey->>CacheKeyHeader: parse header bytes
    CacheKeyHeader->>CacheKeyHeader: Extract encoded length
    Note over CacheKeyHeader: Restore actual length by adding one
    CacheKeyHeader-->>CacheKey: Return actual key length
    CacheKey->>Storage: Read key bytes using length
    CacheKey-->>Client: Return decoded cache key
Loading

@shikhar shikhar merged commit d39cafb into main Jan 21, 2026
5 checks passed
@shikhar shikhar deleted the gh46 branch January 21, 2026 02:18
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.

[Detail Bug] Inconsistent ObjectKey max length between validation (1024) and encoding (<=1023) causes cache failures

2 participants