Skip to content

Conversation

@tanujnay112
Copy link
Contributor

@tanujnay112 tanujnay112 commented Dec 10, 2025

Description of changes

Summarize the changes made by this PR.

  • Improvements & Bug fixes
    • Make chroma::source_collection_id a protected collection metadata field by checking for this on the CreateCollection and UpdateCollection paths.
  • New functionality
    • ...

Test plan

Added a test in test_task_api.py

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Migration plan

Are there any migrations, or any forwards/backwards compatibility changes needed in order to make sure this change deploys reliably?

Observability plan

What is the plan to instrument and monitor this change?

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs section?

@github-actions
Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@tanujnay112 tanujnay112 marked this pull request as ready for review December 10, 2025 21:39
@propel-code-bot
Copy link
Contributor

propel-code-bot bot commented Dec 10, 2025

Protect system-managed collection metadata from user updates

Adds server-side guards around collection metadata to stop clients from setting or changing the chroma:source_attached_function_id system key. The gRPC create path now rejects requests containing reserved keys, the catalog update path validates that existing system metadata values remain unchanged, and dedicated integration tests verify both the create-time and modify-time protections.

Key Changes

• Defined coordinator.SystemCollectionMetadataKeys with reserved metadata keys and added validation helper validateSystemMetadataKeysUnchanged in go/pkg/sysdb/coordinator/table_catalog.go.
• Updated Catalog.UpdateCollection to check that system-reserved metadata values match the persisted values before replacing metadata rows.
• Added gRPC-layer validation in go/pkg/sysdb/grpc/collection_service.go to reject CreateCollection requests supplying reserved metadata keys.
• Extended integration coverage in chromadb/test/distributed/test_task_api.py to ensure users cannot create or modify collections with chroma:source_attached_function_id and added a new ErrSystemMetadataKeyNotAllowed error in go/pkg/common/errors.go.

Affected Areas

• go/pkg/sysdb/coordinator/table_catalog.go
• go/pkg/sysdb/grpc/collection_service.go
• go/pkg/common/errors.go
• chromadb/test/distributed/test_task_api.py

This summary was automatically generated by @propel-code-bot

@blacksmith-sh

This comment has been minimized.

@blacksmith-sh

This comment has been minimized.

Comment on lines +453 to +493
def test_cannot_modify_system_metadata_key(basic_http_client: System) -> None:
"""Test that users cannot modify the system-reserved metadata key on output collections"""
client = ClientCreator.from_system(basic_http_client)
client.reset()

# Create input collection and attach a function
input_collection = client.create_collection(name="input_collection")
input_collection.add(ids=["id1"], documents=["test"])

attached_fn, created = input_collection.attach_function(
name="my_function",
function=RECORD_COUNTER_FUNCTION,
output_collection="output_collection",
params=None,
)
assert attached_fn is not None
assert created is True

# Get the output collection
output_collection = client.get_collection(name="output_collection")

# Verify the output collection has the system metadata key
assert output_collection.metadata is not None
assert "chroma:source_attached_function_id" in output_collection.metadata

# Attempt to modify the system-reserved metadata key should fail
with pytest.raises(
ChromaError, match="cannot set or modify system-reserved metadata key"
):
output_collection.modify(
metadata={"chroma:source_attached_function_id": "fake-value"}
)

# Verify the metadata was not changed
output_collection = client.get_collection(name="output_collection")
assert output_collection.metadata["chroma:source_attached_function_id"] == str(
attached_fn.id
)

# Clean up
input_collection.detach_function(attached_fn.name, delete_output_collection=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Important

[Logic] This is a great test for preventing direct modification of a system key. To make it more robust, it would be beneficial to also verify that system keys are preserved when modifying other metadata fields.

The current implementation in table_catalog.go might allow for the deletion of system keys if they are omitted from the metadata object in a modify call. Adding a test case for this would help catch that potential regression.

You could add a check like this after the existing pytest.raises block:

    # Also attempt to modify non-system metadata, which should succeed
    # and preserve the system key.
    output_collection.modify(
        metadata={"user_key": "user_value"}
    )

    # Verify the system metadata key was preserved and user key was added
    output_collection = client.get_collection(name="output_collection")
    assert output_collection.metadata is not None
    assert "user_key" in output_collection.metadata
    assert output_collection.metadata["user_key"] == "user_value"
    assert "chroma:source_attached_function_id" in output_collection.metadata
    assert output_collection.metadata["chroma:source_attached_function_id"] == str(
        attached_fn.id
    )
Context for Agents
This is a great test for preventing direct modification of a system key. To make it more robust, it would be beneficial to also verify that system keys are preserved when modifying *other* metadata fields.

The current implementation in `table_catalog.go` might allow for the deletion of system keys if they are omitted from the `metadata` object in a `modify` call. Adding a test case for this would help catch that potential regression.

You could add a check like this after the existing `pytest.raises` block:

```python
    # Also attempt to modify non-system metadata, which should succeed
    # and preserve the system key.
    output_collection.modify(
        metadata={"user_key": "user_value"}
    )

    # Verify the system metadata key was preserved and user key was added
    output_collection = client.get_collection(name="output_collection")
    assert output_collection.metadata is not None
    assert "user_key" in output_collection.metadata
    assert output_collection.metadata["user_key"] == "user_value"
    assert "chroma:source_attached_function_id" in output_collection.metadata
    assert output_collection.metadata["chroma:source_attached_function_id"] == str(
        attached_fn.id
    )
```

File: chromadb/test/distributed/test_task_api.py
Line: 493

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