Skip to content

Add application-scoped state API (ctx.app_state)#2191

Open
diptanu wants to merge 1 commit intomainfrom
feature/app-state
Open

Add application-scoped state API (ctx.app_state)#2191
diptanu wants to merge 1 commit intomainfrom
feature/app-state

Conversation

@diptanu
Copy link
Collaborator

@diptanu diptanu commented Mar 2, 2026

Summary

Adds server and dataplane support for application-scoped state (ctx.app_state), enabling functions to share key-value state across request boundaries within the same application.

Some agents require updating context about users or objects they are managing. Application State is a way for applications to share state across request boundaries as they learn about the problem domain. For example, a fitness tracker agent managing fitness logs of multiple users can store per-user context in app_state as a flexible K/V store — much more practical than using rigid database schemas for evolving agent knowledge.

Changes

  • Proto: FunctionExecutorMetadata message on ContainerDescription + app state operation/result messages in function_executor.proto
  • Server: app_state_key_prefix() on DataPayload, FunctionExecutorMetadata populated in build_full_snapshot() and build_add_container_command()
  • Dataplane: AppStateHandler in state_ops.rs, app_state_uri_prefix on AllocationContext, wired through allocation_lifecycle.rs
  • Integration test: test_app_state.py covering set/get, downstream reads, cross-request persistence, overwrites, and default values

Companion PR

Test plan

  • cargo build -p indexify-server && cargo build -p indexify-dataplane — compiles
  • cargo test -p indexify-server — 268 tests pass
  • cargo test -p indexify-dataplane --no-run — compiles
  • Existing test_state.py (request state) — 11 tests pass, no regressions
  • New test_app_state.py — 6 integration tests pass:
    • set/get within single function
    • set in one function, read in downstream function
    • two different requests read/write each other's data
    • last-writer-wins overwrite across requests
    • default values for missing keys
    • None for missing keys without default

🤖 Generated with Claude Code

Adds server and dataplane support for application-scoped state, enabling
functions to share key-value state across request boundaries within the
same application. This complements the existing per-request ctx.state.

Proto changes:
- Add FunctionExecutorMetadata message with app_state_uri_prefix to
  ContainerDescription in executor_api.proto
- Add AllocationAppState operation/result messages to
  function_executor.proto
- Wire into AllocationState and AllocationUpdate

Server changes:
- Add app_state_key_prefix() to DataPayload for URI computation
- Populate FunctionExecutorMetadata on ContainerDescription in both
  build_full_snapshot() and build_add_container_command()

Dataplane changes:
- Add AppStateHandler with full reconcile logic in state_ops.rs
- Add app_state_uri_prefix to AllocationContext
- Read FunctionExecutorMetadata from container description in
  allocation_lifecycle.rs

Integration test:
- Add test_app_state.py covering set/get, downstream reads,
  cross-request persistence, overwrites, and default values

Companion PR: tensorlakeai/tensorlake#542

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@diptanu diptanu force-pushed the feature/app-state branch from 72bf048 to da7bceb Compare March 2, 2026 07:00
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