Skip to content

feat(tags): make the per-Artifact and per-query tag limits configurable - #2816

Open
Lumea-art wants to merge 8 commits into
oceanbase:masterfrom
Lumea-art:feat/tag-limits
Open

Lumea-art wants to merge 8 commits into
oceanbase:masterfrom
Lumea-art:feat/tag-limits

Conversation

@Lumea-art

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

Closes #2720.

Rationale for this change

The 32-labels-per-Artifact and 16-labels-per-query bounds were hard-coded in domain validation, OpenAPI arrays and
several duplicate paths. Raising either required editing source, and changing only one copy would leave another supported
path rejecting the same input. This change makes both limits deployment-wide settings while keeping the defaults and
putting a bounded ceiling in the contract.

What changes are included in this PR?

  • RuntimeConfig.tag_max_per_artifact (POWERCONTEXT_SERVER_RUNTIME_TAG_MAX_PER_ARTIFACT, default 32, range 1–256) and
    RuntimeConfig.tag_max_query_labels (POWERCONTEXT_SERVER_RUNTIME_TAG_MAX_QUERY_LABELS, default 16, range 1–64),
    exposed through the embedded runtime configuration and the Server's runtime settings.
  • Effective enforcement on Artifact tag replacement, tag queries, Artifact-list and Memory tag filters, plugin Artifact
    writes (host and Worker), Dream/Catalog approval and merge tag selection.
  • OpenAPI tag arrays use the contract ceilings (256 for Artifact sets, 64 for query labels) so configured values pass
    static validation; runtime admission reports the effective limit.
  • Read, export and import paths stay ceiling-bound: lowering a limit never truncates or hides existing tag sets, and an
    existing larger set stays readable and can be replaced with a compliant set or cleared.
  • EN/ZH documentation, .env.example and the configuration reference describe the settings, ranges and precedence;
    Desktop contract identity and its qualification record are refreshed.

Are there any user-facing changes?

Two new runtime settings with unchanged defaults. Without overrides behavior is identical; configured larger values now
succeed up to the effective limit, and values above it fail with an actionable validation error naming the limit.

How was this change tested?

  • tests/test_tag_limits.py (7 tests): default 32/16 boundaries, configured 40/20 boundaries, Artifact-list filters,
    Memory search filters, lowering a limit with existing oversized tag sets (read, replace and clear), and rejection of
    configuration above the ceilings.
  • pytest tests/test_tag_limits.py tests/e2e/test_real_artifact_tags.py tests/builtin/artifacts/atomic_memory tests/builtin/persistence/test_records.py tests/test_api_contract.py tests/test_js_operations.py → 284 passed,
    7 skipped; tests/builtin/dream tests/builtin/plugins → 20 passed, 2 skipped.
  • generate_api.py --check, generate_js_operations.py --check, upgrade_release_gate.py, ruff and ty pass;
    tests/test_desktop_contract.py → 4 passed.
  • Real SQLite Server from the wheel with TAG_MAX_PER_ARTIFACT=64 and TAG_MAX_QUERY_LABELS=20 and enforced Bearer
    authentication: 64 labels accepted, 65 rejected with 422; a 20-label query succeeded and a 21-label query was
    rejected with 400; desktop/VALIDATION.md records the probe, including that the native probe was not rebuilt here.
  • OceanBase was not exercised; the change adds no storage or query-shape change.

AI usage statement

Built with an AI coding assistant (DeepSeek Harness). Changes were reviewed and executed locally against a real
SQLite Server built from the wheel; the OceanBase limit is reported as not exercised.

Add RuntimeConfig.tag_max_per_artifact (default 32, ceiling 256) and
tag_max_query_labels (default 16, ceiling 64). Enforce the effective policy on
HTTP tag writes, tag queries and Artifact or Memory tag filters, on plugin
Artifact writes, on Dream/catalog approval and on merge tag selection; widen the
OpenAPI arrays to the contract ceilings and keep read, export and import paths
ceiling-bound so existing tag sets stay readable after a limit is lowered.

Docs, the environment template and tests cover the defaults, configured values,
filters, lowering, replacement/clearing and the configuration ceiling.
Record sqlite-tag-limits-17fcab7-v1 for the wheel built from the implementation
commit. The Bearer probe covers all thirteen Desktop operations plus the
64/65 Artifact-label and 20/21 query-label boundaries.
Comment thread tests/test_tag_limits.py Outdated
settings=ServerSettings(
database=SQLiteConfig(url=f"sqlite+aiosqlite:///{tmp_path / 'tags.db'}"),
inference=InferenceConfig(generation_model="test"),
runtime=RuntimeConfig(**runtime),

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.

[P1] _app() 的 dict 字面量让 ty check 报 83 条 invalid-argument-type,CI preflight 红 ⇒ 全部 suite 跳过

第 42 行的 runtime = {"artifact_processing_families": ()} 让类型检查器把该 dict 推断成 dict[str, int | tuple[()]],第 47 行 RuntimeConfig(**runtime) 的每个字段都是具体类型,联合值不可赋。

证据(实测):CI preflight(run 45326786769 / job 138218203821)在 Makefile:49: workflow-actions-check 处以 exit 1 结束,日志中 83 条 error[invalid-argument-type] 全部指向 tests/test_tag_limits.py:47:35,无第二处错误位置。

影响:quality 失败后 needs.quality.outputs.suites 为空,master.yml 的 suite job 一律 skipped(本次 39 个,含 tests (*)、*-host、desktop-validation)。本 PR 新增的这张 184 行用例表与「可配置标签上限」的实际行为在 CI 里没有任何执行记录;Upgrade release gate 的红是同一原因的级联,不是第二个缺陷。

建议:改成逐字段构造,避免 ** 展开掩盖字段类型,例如

return create_server_app(
    settings=ServerSettings(
        database=SQLiteConfig(url=f"sqlite+aiosqlite:///{tmp_path / 'tags.db'}"),
        inference=InferenceConfig(generation_model="test"),
        runtime=RuntimeConfig(
            artifact_processing_families=(),
            tag_max_per_artifact=artifact if artifact is not None else MAX_TARGET_TAGS,
            tag_max_query_labels=query if query is not None else MAX_QUERY_TAG_LABELS,
        ),
        mcp=McpConfig(enabled=False),
    )
)

若仍要保留 dict 写法,至少要显式标注成能让 ty 通过的类型(dict[str, Any] 一类),并用 uv run ty check tests/test_tag_limits.py 确认该文件零错误,再确认 CI preflight 转绿后各 suite 真正执行到这张用例表。

@Lumea-art Lumea-art Nov 24, 2026 •

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.

Fixed in 9ac84bf. _app() now builds RuntimeConfig with explicit fields:

runtime=RuntimeConfig(
    artifact_processing_families=(),
    tag_max_per_artifact=MAX_TARGET_TAGS if artifact is None else artifact,
    tag_max_query_labels=MAX_QUERY_TAG_LABELS if query is None else query,
)

uv run ty check over every changed Python file (including tests/test_tag_limits.py) passes with no diagnostics, ruff is clean, and the 7 tag-limit tests still pass. The preflight failure was ty-only; no product code changed in this commit.

@AlexStocks AlexStocks Nov 25, 2026 •

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.

[P1 closed] The ty failure on this line is gone at 5c61512. _app() now passes artifact_processing_families=(), tag_max_per_artifact and tag_max_query_labels as explicit keyword arguments instead of building a dict literal, so the dict[str, int | tuple[()]] inference that produced the 83 invalid-argument-type errors no longer exists. Evidence: CI preflight on head 5c61512 concluded success (01:57:24Z-02:00:23Z), which is the job that ran the workflow-actions-check / ty step; the other 67 checks are green apart from two unrelated failures (see below).

The two remaining red checks are not caused by this branch: gateway-validation / check died in capacity_process::capability_contract_and_positive_integer_capacity_are_required with bind: Os { code: 98, kind: AddrInUse } at main.rs:361 in port-takeover mode (the same flake the branch already retriggered once in 5c61512), and harness-validation / Acceptance (sqlite) ended with No ACP summary file found and a 0.000 mean over 6:12, which is the harbor harness signature, not a tag or bundle failure.

Separately, the new tag_limit plumbing has one uncovered path; I posted it as its own thread (4690059709) instead of extending this one, since the root cause differs.

@AlexStocks AlexStocks added the 1.6.1 v1.6.1 release tracking label Nov 24, 2026
Construct RuntimeConfig with explicit fields instead of a `**`-expanded dict so
the type checker validates every setting; the previous dict literal produced 83
invalid-argument-type diagnostics and failed the CI preflight.
@Lumea-art

Lumea-art commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed in 9ac84bf. _app() now builds RuntimeConfig with explicit fields:

runtime=RuntimeConfig(
    artifact_processing_families=(),
    tag_max_per_artifact=MAX_TARGET_TAGS if artifact is None else artifact,
    tag_max_query_labels=MAX_QUERY_TAG_LABELS if query is None else query,
)

uv run ty check over every changed Python file (including tests/test_tag_limits.py) passes with no diagnostics, ruff is clean, and the 7 tag-limit tests still pass. The preflight failure was ty-only; no product code changed in this commit.

Thread the deployment's Artifact tag limit into PortableBundleService so archive
validation rejects tag sets the target cannot store, while single-label parsing
stays at the contract ceiling. Store the limit on RelationalContexts so the
runtime export and restore path receives the configured value instead of the
default.
@Lumea-art

Copy link
Copy Markdown
Contributor Author

Two fixes are pushed on top of the implementation:

  • 9ac84bf — the ty finding: _app() builds RuntimeConfig with explicit fields instead of a **-expanded dict. ty check over every changed Python file now passes; this was the only preflight diagnostic.
  • ac3d5e5 — the first rerun then exposed a real e2e regression in tests/e2e/test_portable_archive.py: bundle validation was ceiling-bound, so archives whose combined tag sets exceed the target's effective limit validated as compatible. PortableBundleService now receives the deployment's Artifact tag limit (stored on RelationalContexts and passed from the runtime) and validates restored tag sets against it; single-label parsing stays at the contract ceiling.

Verification on the pushed head: pytest tests/e2e/test_portable_archive.py → 121 passed, 65 skipped; pytest tests/test_tag_limits.py tests/builtin tests/test_api_contract.py tests/test_js_operations.py tests/test_desktop_contract.py → 3886 passed, 146 skipped; ty and ruff pass on all changed files. CI is rerunning.

Regenerate the Dify contract for the widened tag arrays and add the TagFilter
description to the generated Rust wire model, which is the only wire model the
new schema documentation touches.
Run the pinned OpenAPI generator with the new TagFilter description. The
generator emits the description on the constructor as well as the model, which
the hand-edited line could not reproduce.
@Lumea-art

Copy link
Copy Markdown
Contributor Author

The rerun exposed two more generated-artifact issues, both fixed:

  • dify-tools — the Dify contract needed regeneration after the tag arrays widened; ac3d5e5 includes the regenerated contract.json.
  • desktop-validation — wire.rs drifted because the new TagFilter description is emitted by the pinned OpenAPI generator on both the model and its constructor. I installed the pinned JDK/rustfmt locally, ran pnpm --dir desktop generate, and committed the exact generated output in 5d12903; pnpm --dir desktop generate --check now passes locally.

On the previous head, every other job passed, including all e2e shards, dify-tools, and desktop-validation on Linux and macOS. The remaining red was gateway-validation / check, which failed with AddrInUse in a port-takeover test (capacity_process.rs), unrelated to this change, so I retriggered the run.

artifact_content_decoder: Callable[[Mapping[str, Any]], object] | None = None,
candidate_decoder: Callable[[Mapping[str, Any]], object] | None = None,
source_decoder: Callable[[Mapping[str, Any]], object] | None = None,
tag_limit: int = MAX_TARGET_TAGS,

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.

[P2] tag_limit defaults silently, and the restore --dry-run path never passes it

PortableBundleService.__init__ now takes tag_limit: int = MAX_TARGET_TAGS and RelationalContexts passes runtime.tag_max_per_artifact, so export/restore validate tag sets against the effective limit instead of the 256 ceiling. The other production construction site, src/powercontext/cli/archive.py::_validate_with_database, still builds PortableBundleService(...) without tag_limit. That function is what pc archive restore --dry-run runs (restore_bundle -> _emit_validation_result -> _validate_only -> _validate_with_database), so the dry-run always validates with the 32 default.

Impact, at a supported configuration: with runtime.tag_max_per_artifact=64 (allowed up to MAX_TARGET_TAGS_CEILING), a bundle whose Artifact carries 33-64 tags fails the dry-run with BundleFormatError("artifact tag set has invalid labels"), while the real restore --yes on the same machine accepts it, because that path goes through open_builtin_runtime -> RelationalContexts. The inverse also holds: with a limit below 32 the dry-run accepts a bundle that the real restore then rejects. A precheck whose verdict contradicts the operation it prechecks is worse than no precheck, since operators use it to decide whether to run the write.

Suggestion: thread settings.runtime.tag_max_per_artifact through _validate_only into _validate_with_database, and add one case that pins the dry-run verdict at a non-default limit. The increment currently adds no test at all for the effective-limit change, so neither path is pinned.

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

1.6.1 v1.6.1 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(tags): make per-Artifact and per-query tag limits configurable

2 participants