Skip to content

CBG-5327: Wire up REST API to document channel history compaction#8275

Merged
RIT3shSapata merged 16 commits into
mainfrom
CBG-5327
Jun 1, 2026
Merged

CBG-5327: Wire up REST API to document channel history compaction#8275
RIT3shSapata merged 16 commits into
mainfrom
CBG-5327

Conversation

@RIT3shSapata

@RIT3shSapata RIT3shSapata commented May 15, 2026

Copy link
Copy Markdown
Contributor

CBG-5327

Describe your PR here...

  • Added routes and handlers for get and post requests of document channel history compaction
  • Created a get document channel history function
  • Added test coverage for the http requests
  • Updated the Document Channel history compaction to store the compacted channels as set instead of array
  • Updated Open API spec

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

Integration Tests

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.

Pull request overview

This PR wires document channel history compaction into the Admin REST API and adds a REST-accessible way to inspect a document’s channel revocation history.

Changes:

  • Added Admin REST routes and handlers for getting document channel history and compacting channel history.
  • Added GetDocChannelHistory plus updated compaction output to deduplicate compacted channel names.
  • Added REST/API tests and updated OpenAPI path documentation.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
rest/routing.go Registers new Admin channel history GET and compaction POST routes.
rest/doc_api.go Adds request/response handling for channel history APIs.
rest/api_test.go Adds REST coverage and updates compaction expectations for deduplicated channels.
docs/api/paths/admin/keyspace-_history.yaml Updates documented GET channel history response schema.
docs/api/paths/admin/keyspace-_history-compact.yaml Updates compaction response description.
db/crud.go Adds channel history retrieval and deduplicates compacted channel results.
Comments suppressed due to low confidence (2)

docs/api/paths/admin/keyspace-_history.yaml:17

  • This description conflicts with the implemented behavior and the new test for a channel that is revoked and then re-added: such a channel is still returned because it has revocation history. Rephrase this to say active channel memberships without any revocation history are not included, rather than implying all currently assigned channels are excluded.
    names to the sequences at which the document was removed from each channel. Only channels
    that have been revoked at least once are included; channels the document is currently
    assigned to are excluded.

docs/api/paths/admin/keyspace-_history.yaml:34

  • This map response is missing the repository’s OpenAPI convention of naming additionalProperties keys with x-additionalPropertiesName (for example, docs/api/paths/admin/keyspace-_history-compact.yaml:59-61 uses it for doc IDs). Add an appropriate key name such as channel_name to keep generated docs consistent.
            additionalProperties:
              type: array

Comment thread docs/api/paths/admin/keyspace-_channel_history.yaml
Comment thread docs/api/paths/admin/keyspace-_history-compact.yaml Outdated
Comment thread rest/doc_api.go
Comment thread db/crud.go Outdated
Comment thread rest/doc_api.go Outdated
Comment thread rest/routing.go
Comment thread rest/doc_api.go Outdated

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread docs/api/admin.yaml Outdated
'/{keyspace}/_channel_history/{docid}':
$ref: './paths/admin/keyspace-_history.yaml'
'/{keyspace}/_history/compact':
'/{keyspace}/_channel_history/compact':
Comment thread rest/doc_api.go Outdated
Comment on lines +976 to +977
if err != nil && !base.IsDocNotFoundError(err) {
return err
Comment on lines +33 to +39
additionalProperties:
type: array
items:
type: integer
format: int64
minimum: 0
description: Sequences at which the document was removed from this channel.

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Comment thread rest/routing.go Outdated
Comment thread rest/doc_api.go Outdated
Comment on lines +934 to +939
func (h *handler) handleGetDocChannelHistory() error {
h.assertAdminOnly()

if !h.collection.UseXattrs() {
return fmt.Errorf("xattrs not enabled")
}
Comment thread rest/doc_api.go Outdated
Comment thread rest/doc_api.go Outdated
Comment thread db/crud.go
Comment thread docs/api/paths/admin/keyspace-_history.yaml Outdated
Comment thread docs/api/paths/admin/keyspace-_channel_history-compact.yaml
Comment thread rest/api_test.go

@adamcfraser adamcfraser 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.

Posted text cleanup from our discussion - final review pending decisions on discussion items.

Comment thread docs/api/paths/admin/keyspace-_history.yaml Outdated
Comment thread docs/api/paths/admin/keyspace-_history-compact.yaml Outdated
Comment thread docs/api/paths/admin/keyspace-_history-compact.yaml Outdated
Base automatically changed from CBG-5326 to main May 26, 2026 14:01
- added route for get request and the handler
- created a get channel history function and added test coverage
- add route and handler to handle http request
- add test coverage for http request
- use set instead of array to store compacted channels
- add docstrings to all functions
- updated api spec

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.

Comments suppressed due to low confidence (4)

docs/api/paths/admin/keyspace-_channel_history-compact.yaml:56

  • The documented 200 response schema doesn’t match the actual handler output. The code returns an object with a compacted_channels property (array of strings), but this spec currently describes an object with additionalProperties (and an unrelated x-additionalPropertiesName: doc_id). Update the schema to define compacted_channels as a property and remove the additionalProperties mapping.
    docs/api/paths/admin/keyspace-_channel_history-compact.yaml:37
  • The request schema allows seq with minimum: 0, but the handler currently returns 400 when seq==0. Either allow 0 (treat as a valid no-op) or update the OpenAPI schema/description to require seq >= 1 so the contract matches runtime behavior.
    docs/api/paths/admin/keyspace-_channel_history-compact.yaml:59
  • The description has a grammar typo: “A array of all the compacted channels” should be “An array of all the compacted channels”.
    docs/api/paths/admin/keyspace-_channel_history-compact.yaml:67
  • operationId in this file still references the old _history endpoint name (post_keyspace-_history-compact), but the path is now /_channel_history/{docid}/compact. Update the operationId to match the new endpoint naming to avoid collisions/confusion in generated clients.

Comment thread rest/doc_api.go Outdated
Comment thread rest/doc_api.go Outdated
Comment thread rest/doc_api.go
Comment on lines +971 to +978
err := h.readJSONInto(&req)
if err != nil {
return base.HTTPErrorf(http.StatusBadRequest, "invalid JSON: %v", err)
}

if req.Seq == 0 {
return base.HTTPErrorf(http.StatusBadRequest, "missing seq")
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changing the open api spec

Comment thread db/crud.go Outdated
Comment thread db/crud.go Outdated
Comment thread rest/api_test.go Outdated
Comment on lines +35 to +44
schema:
type: object
additionalProperties:
type: array
items:
type: integer
format: int64
minimum: 0
description: Sequences at which the document was removed from this channel.
description: Map of channel names to their revocation sequences.
Comment thread db/crud.go

@adamcfraser adamcfraser 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.

Generally looks good, one naming suggestion and then some comments about response ordering.

Comment thread rest/doc_api.go Outdated
Comment thread db/crud.go
Comment thread db/crud.go Outdated
Comment thread db/crud.go Outdated
- rename a few functions
- refactor the format of the response being sent for get channel history
Comment thread db/crud.go Outdated
})

chanHistoryMap := make(map[string][]uint64)
for _, entry := range chanHistoryEntries {

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.

Once you convert this to a map, we're going to lose the ordering from chanHistoryEntries. The map itself will be unordered, and then JSON serialization of a map is going to order by keys.

So if we want the output to be ordered by sequence, we'd need to change it from a map of channel names to a slice of structs. Let's not make that change in this PR, and revisit the question of sorting by sequence.

@adamcfraser adamcfraser 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.

Generally looks good, I think copilot suggestion to sort channels by name for the compact response is correct.

Comment thread db/crud.go Outdated
@RIT3shSapata RIT3shSapata merged commit dd81b5c into main Jun 1, 2026
51 checks passed
@RIT3shSapata RIT3shSapata deleted the CBG-5327 branch June 1, 2026 16:26
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.

3 participants