Skip to content

feat(storage): read the gateway ownership of a page of Tasks in one call - #1466

Draft
Robbie Cronin (robert-cronin) wants to merge 6 commits into
stack/512/31-adapter-e2efrom
stack/512/32-gateway-task-batch
Draft

Robbie Cronin (robert-cronin) wants to merge 6 commits into
stack/512/31-adapter-e2efrom
stack/512/32-gateway-task-batch

Conversation

@robert-cronin

Copy link
Copy Markdown
Member

Stacked on the adapter E2E layer. GET /tasks and the attention scan look up each Task's gateway ownership on its own, one GetGatewayEventForTask call per Task. On embedded SQLite that is cheap. With an out-of-tree adapter, every call is a round trip to the database, so listing a namespace's Tasks costs one round trip per Task before anything comes back. This layer adds a batch read to the contract and uses it in both places.

Base is stack/512/31-adapter-e2e; the diff below is this layer only.

What changes

  • Contract (revision 20): GatewayEventStore.ListGatewayEventsForTasks(ctx, keys []GatewayTaskKey) returns the event GetGatewayEventForTask would return for each distinct key that has one, in key order. Keys without an event are left out.
    • It takes up to MaxGatewayTaskKeys (500) keys. More keys, or a key without a namespace, Task name or Task UID, is ErrValidation; ValidateGatewayTaskKeys gives adapters the same check.
    • It checks a Task data fence as the single lookup does.
  • Wire (protocol revision 13): Gateway.ListGatewayEventsForTasks streams its events as a list. An event carries its message text, so 500 of them aren't bounded in size. GatewayEventStore is now served from revision 13, so the controller requires an adapter on that revision.
  • SQLite runs the single-key query for each distinct key inside one fence check.
  • API:
    • The GET /tasks page function and the attention scan each read a page's gateway events in one batch into a request-scoped map. The gateway identity check reads through that map and falls back to the per-Task lookup for any Task the batch didn't cover.
    • When a batch fails, the API looks each Task up on its own as before, so a Task whose ownership can't be read is refused exactly as before. Nothing is authorized from a batch that didn't complete.
  • Docs: storage-contracts.md records revision 20, protocol revision 13 and the new list stream.

Left alone:

  • /trace must read the latest event sequence first, because that sequence bounds its event listing, so its two reads can't run together.
  • /events could run its two reads in parallel. That would save one round trip but weaken the ordering clients see between latestSeq and the last listed event.

An out-of-tree adapter needs ListGatewayEventsForTasks to report revision 20.

Testing

  • storagetest:
    • "a list of Task keys returns what each single lookup returns" covers order, duplicates, a replaced UID, another namespace, validation and the 500-key bound;
    • the Task data fence list includes the new read.
    • Both pass against SQLite in process and over the wire (go test ./internal/store/sqlite -run 'Conformance|OverWire|Wire').
  • go test ./internal/api/...:
    • TestListTasksReadsGatewayOwnershipInOneBatch: one batch and no single lookups, and a Task that only its durable record marks as gateway-owned stays hidden.
    • TestListTasksFallsBackToSingleLookupsWhenTheBatchFails: single lookups give the same result, and the request answers 503 when they fail too.
    • TestAttentionReadsGatewayOwnershipInOneBatch.
    • The batch tests fail without the prefetch.
  • make test, full golangci-lint on the root and pkg/storage modules, go test ./cmd/build/helmify/..., a clean make manifests generate, make verify-generated and go test ./hack/repocheck: pass.

Part of #512.

Signed-off-by: Robert Cronin <robert.owen.cronin@gmail.com>
@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The cache retains full event payloads across pages, including filtered-out tasks, causing request memory to grow with the entire scan rather than just the current page.

1 open issue
9 files not reviewed
  • internal/storageclient/storagefault/wrappers_gen.go: Generated file
  • pkg/storage/v1/wire/storagepb/gateway.pb.go: Generated file
  • pkg/storage/v1/wire/storagepb/gateway_grpc.pb.go: Generated file
  • pkg/storage/v1/wire/wiretest/zz_generated.overlay.go: Generated file
  • pkg/storage/v1/wire/zz_generated.codecs_test.go: Generated file
  • pkg/storage/v1/wire/zz_generated.mapping.go: Generated file
  • pkg/storage/v1/wire/zz_generated.provider.go: Generated file
  • pkg/storage/v1/wire/zz_generated.recorder_test.go: Generated file
  • pkg/storage/v1/wire/zz_generated.service.go: Generated file
What changed in this PR

This PR reduces remote-storage round trips for Task gateway ownership checks, advancing the external storage support in #512 while preserving per-Task fallback on batch failures.

Changes:

  • Adds a validated batch lookup for up to 500 Task keys, with SQLite support and streamed wire responses.
  • Uses request-scoped prefetching for Task listings and attention scans.
  • Updates contract revisions, documentation, and API and storage conformance coverage.
File Description
pkg/​storage/​v1/​wire/​zz_generated.service.go Adds generated batch client and server handling.
pkg/​storage/​v1/​wire/​zz_generated.recorder_test.go Records batch calls in wire tests.
pkg/​storage/​v1/​wire/​zz_generated.provider.go Raises the gateway family protocol requirement.
pkg/​storage/​v1/​wire/​zz_generated.mapping.go Adds Task-key wire conversions.
pkg/​storage/​v1/​wire/​zz_generated.codecs_test.go Registers Task-key codec coverage.
pkg/​storage/​v1/​wire/​wiretest/​zz_generated.overlay.go Routes batch conformance calls over the wire.
pkg/​storage/​v1/​wire/​storagepb/​gateway_grpc.pb.go Adds generated streaming RPC bindings.
pkg/​storage/​v1/​wire/​protocol.go Raises protocol revision to 13.
pkg/​storage/​v1/​store.go Extends the gateway store interface.
pkg/​storage/​v1/​storagetest/​events_gateway.go Tests batch ordering, deduplication, and validation.
pkg/​storage/​v1/​storagetest/​conditional.go Adds batch-read fence coverage.
pkg/​storage/​v1/​provider.go Raises contract revision to 20.
pkg/​storage/​v1/​methods.go Classifies the batch method as a state read.
pkg/​storage/​v1/​gateway_types.go Defines Task keys, validation, and batch limits.
pkg/​storage/​proto/​orka/​storage/​v1/​gateway.proto Defines batch messages and streaming RPC.
internal/​store/​sqlite/​gateway_store.go Implements deduplicated lookups within one fence check.
internal/​store/​public_contract.go Exposes internal aliases for batch types and limits.
internal/​storageclient/​storagefault/​wrappers_gen.go Adds batch fault-injection wrapping.
internal/​api/​task_access.go Uses prefetched events for ownership checks.
internal/​api/​handlers.go Prefetches ownership for Task listing pages.
internal/​api/​gateway_task_events.go Implements request caching and single-lookup fallback.
internal/​api/​gateway_task_events_test.go Tests batching, visibility, and failure fallback.
internal/​api/​attention_handlers.go Prefetches ownership during attention scans.
docs/​development/​storage-contracts.md Documents batch semantics and revision requirements.

Review effort: Balanced

Comment thread internal/api/gateway_task_events.go Resolved
Signed-off-by: Robert Cronin <robert.owen.cronin@gmail.com>
…k-batch

Signed-off-by: Robert Cronin <robert.owen.cronin@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the change to batch Task gateway ownership lookups and reduce remote storage round trips.

No open issues 🎉

1 resolved since last review
9 files not reviewed
  • internal/storageclient/storagefault/wrappers_gen.go: Generated file
  • pkg/storage/v1/wire/storagepb/gateway.pb.go: Generated file
  • pkg/storage/v1/wire/storagepb/gateway_grpc.pb.go: Generated file
  • pkg/storage/v1/wire/wiretest/zz_generated.overlay.go: Generated file
  • pkg/storage/v1/wire/zz_generated.codecs_test.go: Generated file
  • pkg/storage/v1/wire/zz_generated.mapping.go: Generated file
  • pkg/storage/v1/wire/zz_generated.provider.go: Generated file
  • pkg/storage/v1/wire/zz_generated.recorder_test.go: Generated file
  • pkg/storage/v1/wire/zz_generated.service.go: Generated file

Review effort: Balanced

…k-batch

Signed-off-by: Robert Cronin <robert.owen.cronin@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the batch gateway-ownership lookup changes.

No open issues 🎉

9 files not reviewed
  • internal/storageclient/storagefault/wrappers_gen.go: Generated file
  • pkg/storage/v1/wire/storagepb/gateway.pb.go: Generated file
  • pkg/storage/v1/wire/storagepb/gateway_grpc.pb.go: Generated file
  • pkg/storage/v1/wire/wiretest/zz_generated.overlay.go: Generated file
  • pkg/storage/v1/wire/zz_generated.codecs_test.go: Generated file
  • pkg/storage/v1/wire/zz_generated.mapping.go: Generated file
  • pkg/storage/v1/wire/zz_generated.provider.go: Generated file
  • pkg/storage/v1/wire/zz_generated.recorder_test.go: Generated file
  • pkg/storage/v1/wire/zz_generated.service.go: Generated file

Review effort: Balanced

…k-batch

Signed-off-by: Robert Cronin <robert.owen.cronin@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 02:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Ownership prefetching runs before context-token and visibility filtering, unnecessarily fetching full message bodies for discarded tasks and potentially triggering many remote batches even with limit=0.

1 open issue
9 files not reviewed
  • internal/storageclient/storagefault/wrappers_gen.go: Generated file
  • pkg/storage/v1/wire/storagepb/gateway.pb.go: Generated file
  • pkg/storage/v1/wire/storagepb/gateway_grpc.pb.go: Generated file
  • pkg/storage/v1/wire/wiretest/zz_generated.overlay.go: Generated file
  • pkg/storage/v1/wire/zz_generated.codecs_test.go: Generated file
  • pkg/storage/v1/wire/zz_generated.mapping.go: Generated file
  • pkg/storage/v1/wire/zz_generated.provider.go: Generated file
  • pkg/storage/v1/wire/zz_generated.recorder_test.go: Generated file
  • pkg/storage/v1/wire/zz_generated.service.go: Generated file

Review effort: Balanced

Comment thread internal/api/handlers.go Resolved
… return

Signed-off-by: Robert Cronin <robert.owen.cronin@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 03:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the batched gateway ownership lookup change.

No open issues 🎉

1 resolved since last review
9 files not reviewed
  • internal/storageclient/storagefault/wrappers_gen.go: Generated file
  • pkg/storage/v1/wire/storagepb/gateway.pb.go: Generated file
  • pkg/storage/v1/wire/storagepb/gateway_grpc.pb.go: Generated file
  • pkg/storage/v1/wire/wiretest/zz_generated.overlay.go: Generated file
  • pkg/storage/v1/wire/zz_generated.codecs_test.go: Generated file
  • pkg/storage/v1/wire/zz_generated.mapping.go: Generated file
  • pkg/storage/v1/wire/zz_generated.provider.go: Generated file
  • pkg/storage/v1/wire/zz_generated.recorder_test.go: Generated file
  • pkg/storage/v1/wire/zz_generated.service.go: Generated file

Review effort: Balanced

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.

2 participants