Skip to content

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

Merged
hidb4ai merged 2 commits into
oceanbase:masterfrom
Lumea-art:feat/tag-limits
Nov 30, 2026
Merged

hidb4ai merged 2 commits into
oceanbase:masterfrom
Lumea-art:feat/tag-limits

Conversation

@Lumea-art

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

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.

Plugin note: Artifact tag filters in plugin hosts now default to 16 labels (the documented query-label limit) and accept up to the deployment's configured value; previously they accepted at most 32.

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

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

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

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 728eddd. _validate_only now passes settings.runtime.tag_max_per_artifact into _validate_with_database, which forwards it as tag_limit to PortableBundleService; the dry-run therefore validates against the effective write limit. Export validates historical sets at the contract ceiling, while validate/restore use the effective limit, so lowering the limit cannot block exporting existing data. The default remains only for direct service construction.

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 的传递已生效,但 dry-run 这条路径仍无回归保护

在 head 25c27eb16f 上核对(git -C D:/test/github/review/_bare/powercontext.git show refs/pr/2816:<path>):

  • 传参链完整:src/powercontext/cli/archive.py:157 的 _validate_only 四个分支(:166 / :172 / :179 / :184)都传 settings.runtime.tag_max_per_artifact;_validate_with_database 在 :190 接收该值、:209 转成 PortableBundleService(tag_limit=...)。
  • 出口侧与回复一致:bundle.py:633 的 export() 用 MAX_TARGET_TAGS_CEILING,validate()(:658)与恢复目标校验(:902)用 self._tag_limit。
  • 实测(exact head、SQLite,探针 D:/test/github/review/oceanbase-powercontext-pr-2816/probes/probe_dryrun_tag_limit.py):同一份含 33 个标签的 bundle,tag_limit=32 → BundleFormatError: artifact tag set has invalid labels;tag_limit=64 与 tag_limit=33 → compatible=True。这个参数就是判定的分歧点,不是装饰。

缺口:tests/ 与 e2e/ 里 tag_max_per_artifact 只出现在 tests/test_tag_limits.py:44 与 :181(HTTP 侧),tag_limit 关键字在测试里 0 命中;tests/e2e/test_portable_archive.py:599 与 tests/e2e/test_plugin_archive.py:114-117 的 archive restore --dry-run 全部在默认设置下运行(默认 32 与有效 32 相同)。因此把上面四处传参删回默认值,现有用例的判定不变、仍然全绿——本轮这条修复没有任何用例能拦住回退。

建议补一例:建一个 Artifact 带 33 个标签的 bundle(export 走 ceiling,能成功导出),在 tag_max_per_artifact=64 的设置下跑 archive restore --dry-run 期望通过,在默认设置下期望 BundleFormatError。一例同时钉住「CLI 侧传参」与「export 侧 ceiling」两个方向;否则这条修复只能靠人工阅读维持。

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.

Added the regression test in 4b4db27: test_archive_cli_dry_run_uses_the_configured_tag_write_limit exports a 33-label Artifact (export still uses the ceiling), then runs archive restore --dry-run: with tag_max_per_artifact=64 it is compatible (exit 0), and with 32 it exits 2 with artifact tag set has invalid labels. Reverting the four call-site arguments would now fail this test.

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 闭合] 在 head 8eaf6250 复核,dry-run 这条路径现在有回归保护。

  • 传参链:cli/archive.py 的 _validate_only 四个分支都传 settings.runtime.tag_max_per_artifact,_validate_with_database 以 tag_limit 透传 PortableBundleService;export() 走 MAX_TARGET_TAGS_CEILING,validate()/restore 目标校验走 self._tag_limit。
  • 新用例 tests/test_archive_cli_dry_run_uses_the_configured_tag_write_limit 已存在并通过(pytest tests/test_archive_cli.py -k dry_run_uses_the_configured → 1 passed);tests/test_tag_limits.py + tests/test_archive_cli.py 合跑 40 passed(Python 3.14 / SQLite / 本机镜像 exact head)。
  • 顺带核到与本次改动相关的门禁:scripts/upgrade_release_gate.py exit 0(persistence_sha256 与托管输入一致,digest 已随 persistence/records.py、persistence/tags.py、limits.py 更新);generate_api.py --check、generate_js_operations.py --check 均 exit 0;contractSha256 复算 2aaad075… 与 desktop/.../operations.json、compatibility.json 的记录一致。

本线程无残留问题,可按作者判断处置。

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

Reviewed 5c61512. The effective query-tag limit is bypassed by the Atomic Memory endpoints; reproduced through the public HTTP API, with details inline. The previously reported archive dry-run limit mismatch is also still present; I have not duplicated that thread.

@classmethod
def validate_tags(cls, value: tuple[str, ...]) -> tuple[str, ...]:
normalize_tags(value, maximum=16, allow_empty=False)
normalize_tags(value, maximum=MAX_QUERY_TAG_LABELS_CEILING, allow_empty=False)

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.

[P2] Apply the effective query limit to Atomic Memory routes

Raising TagFilter validation to the 64-label ceiling removes its former 16-label bound, but server/atomic_memory.py builds this filter without checking the deployment limit, and the runtime does not enforce tag_max_query_labels. Reproduced with RuntimeConfig(tag_max_query_labels=2): POST /v1/atomic-memory/list with {"scope_id": scope, "tags": ["one", "two", "three"]} returns 200; /v1/atomic-memory/search with the same tags and "query": "fact" also returns 200. In the same application, /v1/memory/search with those labels in tag_filter.tags returns 422 as configured. Enforce the effective policy at the owning runtime boundary so these supported routes and direct callers honor it as well, while retaining the larger contract ceiling.

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 728eddd. AtomicMemoryApplication now receives tag_query_limit and ScopedAtomicMemory._require_tag_query_limit enforces it in manifest, list_query, list and search, so the HTTP Atomic Memory list/search routes and direct runtime callers share the effective limit. tests/test_tag_limits.py::test_atomic_memory_routes_apply_the_query_limit reproduces the public-HTTP bypass and now gets the query-limit 422.

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.

The Atomic Memory routes apply the limit now, and test_atomic_memory_routes_apply_the_query_limit fails if _require_tag_query_limit is disabled.

The same TagFilter/TagQuery change reaches two embedded paths that don't check the limit. ScopedRecordApplication.query_artifacts(..., tag_filter=...) and query_tags forward straight to the record service (runtime/application.py:876, :907). On SQLite with default settings, both accept 17 labels, which 942e61f9a rejects. With tag_max_query_labels=2, both accept 3.

Plugin reads have a related gap that predates this PR. The tag-filtered list in plugins/writer.py:236 calls normalize_tags without maximum, so it uses the fixed 32-label bound regardless of tag_max_query_labels.

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.

Confirmed at 25c27eb through open_builtin_runtime on SQLite: with tag_max_query_labels=2, both records.for_scope(scope).query_tags(TagQuery(tags=("one", "two", "three"))) and query_artifacts(..., tag_filter=TagFilter(tags=("one", "two", "three"))) succeed. The Atomic Memory-specific fix does not cover these supported embedded query paths.

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 4b4db27. RelationalTagService.query and RelationalRecordService.query_artifacts now call the shared require_tag_query_limit with the runtime's tag_max_query_labels, and both services receive it from RelationalContexts. test_embedded_runtime_queries_apply_the_query_limit drives open_builtin_runtime with tag_max_query_labels=2 and asserts both query_tags and query_artifacts reject three labels.

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.

Verified fixed at a735614 through open_builtin_runtime on SQLite: with tag_max_query_labels=2, both query_tags and query_artifacts now reject three labels with InvalidBaseAccessRequestError. The previous embedded-query bypass reproduction no longer succeeds.

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

Reviewed 5c61512. Two additional correctness issues reproduced with real SQLite storage: lowering the admission limit prevents exporting existing data, and embedded Runtime tag replacement bypasses the configured write limit. Details inline. The existing dry-run and Atomic Memory query-limit threads are not duplicated here.

_parse_bundle(archive_path)
with _validate_dependencies(archive_path, candidate_decoder=self._candidate_decoder):
with _validate_dependencies(
archive_path, candidate_decoder=self._candidate_decoder, maximum=self._tag_limit

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] Keep exports independent of the current write-admission limit

Passing the effective limit here prevents backing up valid existing data after the limit is lowered. Reproduced on SQLite: persist 40 labels with tag_max_per_artifact=40 and export successfully; close and reopen the same database with the limit set to 10. All 40 labels remain readable, but portability.export(...) now raises BundleFormatError("artifact tag set has invalid labels"). This violates #2720's requirement that lowering admission limits must not make exports unreadable/unavailable. Validate exported historical tag sets against the contract ceiling; keep the effective write limit on admission/restore as appropriate.

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 728eddd. export now validates dependencies with MAX_TARGET_TAGS_CEILING, while validate/restore keep the effective self._tag_limit. Lowering the write limit therefore still permits exporting existing tag sets, and restoring an archive the target cannot store is rejected explicitly. The existing archive tests pass (121 passed, 65 skipped).

execution_context=None,
) -> ArtifactTagSet:
desired = normalize_tags(tags)
desired = normalize_tags(tags, maximum=MAX_TARGET_TAGS_CEILING)

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] Enforce the configured write limit for embedded Runtime callers

This change raises storage validation to 256, but the new effective-limit guard exists only in the HTTP adapter. The supported runtime.records.for_scope(scope_id).replace_tags(...) path reaches this method without enforcing RuntimeConfig.tag_max_per_artifact. Reproduced through open_builtin_runtime with real SQLite and tag_max_per_artifact=2: replacing an Atomic Memory tag set with ("one", "two", "three") succeeds and persists all three labels. The unchanged default of 32 is likewise no longer enforced on this path. Enforce the effective limit at the owning runtime/service write boundary while retaining ceiling-bound reads of historical sets.

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 728eddd. RelationalTagService now takes tag_limit, and the embedded Runtime constructs it with tag_max_per_artifact; replace_in_transaction enforces the effective limit on the desired set while reading the previous set at the contract ceiling, so historical oversized sets stay readable and replaceable. Merge tag selection already receives the same configured limit. The regression is covered by the embedded-runtime path in the tag-limit tests.

@hidb4ai

hidb4ai commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Follow-up review: the head is still 5c615121df9b, unchanged since my previous review. The four current P2 threads remain unresolved: archive dry-run uses the default limit, Atomic Memory queries bypass the configured limit, lowering the limit prevents export of existing tag sets, and embedded Runtime tag replacement bypasses the write limit. Please address these before requesting another review; the existing threads contain the reproduction details.

GitHub now also reports merge conflicts. The Gateway check and SQLite harness acceptance remain failing. My changes-requested review remains in place.

@Lumea-art

Copy link
Copy Markdown
Contributor Author

All four open P2 threads are addressed in 728eddd, rebased onto 942e61f and requalified in 25c27eb:

  • Atomic Memory query limit — AtomicMemoryApplication.tag_query_limit and enforcement in manifest, list_query, list and search; HTTP list/search now share the effective limit.
  • Archive export independence — export validates historical tag sets at the contract ceiling; validate/restore use the effective limit; the CLI dry-run passes settings.runtime.tag_max_per_artifact.
  • Embedded Runtime write limit — RelationalTagService receives tag_limit from the runtime and enforces it on the desired set, while the previous set is read at the ceiling so existing larger sets remain replaceable.
  • TagFilter description/ty/preflight and generated artifacts — full pnpm --dir desktop generate and Dify regeneration on the new base; ty passes on every changed file.

Regression coverage: tests/test_tag_limits.py (8 tests, including Atomic Memory list/search), tests/e2e/test_portable_archive.py, Atomic Memory, Dream, plugin suites → 402 passed, 70 skipped. The Bearer probe for wheel 728eddd covers all thirteen Desktop operations, the Artifact 64/65 and query 20/21 boundaries, and the Atomic Memory query-limit rejection; desktop/VALIDATION.md records sqlite-tag-limits-728eddd-v1.

The branch is 728eddd (implementation) + 25c27eb (qualification). The force-push requires a fresh review; the Gateway and harness failures in the previous run are the known environment flakes, so I did not change either.

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

Checked 25c27eb16 on SQLite through the embedded Runtime, the Server app under TestClient, and the archive CLI, comparing with 942e61f9a where behavior changed.

The four fixes from the last round work. Embedded replace_tags rejects a set above tag_max_per_artifact. Export succeeds after the limit is lowered from 40 to 10. archive restore --dry-run --env-file validates against the limit in that file. The Atomic Memory routes apply the query limit. The P1 is inline, and one more query-limit gap is in NeverENG's thread.

Tests. Of the four fixes, only the Atomic Memory one is protected by a test: disabling _require_tag_query_limit fails test_atomic_memory_routes_apply_the_query_limit. I reverted the other three: persistence/tags.py:178 back to the ceiling, the export call at bundle.py:633 back to self._tag_limit, and cli/archive.py:209 back to the default. The tag and archive suites still pass: 268 passed, 69 skipped across tests/test_tag_limits.py, tests/test_archive_cli.py, tests/builtin/portability/test_bundle.py, tests/e2e/test_portable_archive.py and six more files. No other test sets either limit. A probe on the same tree reproduced all three bugs. The embedded-write reply says "The regression is covered by the embedded-runtime path in the tag-limit tests", but tests/test_tag_limits.py only goes through TestClient, where _require_tag_admission rejects the request before the runtime sees it. Each of these fixes needs a test that fails without it; the dry-run case at a non-default limit is what AlexStocks asked for in the dry-run thread.

Docs.

  • docs/zh/docs/operate/configuration.md:57-58 still says a merge result keeps at most 32 tags. The English paragraph describes the configurable limit.
  • #2720 asks the docs to say whether changing these settings needs a restart. Neither locale does.

Not blocking.

  • Two over-limit errors outside HTTP don't name the limit. Embedded replace_tags raises tags has an invalid number of labels. The restore dry-run reports archive validation failed: artifact tag set has invalid labels, which reads like a malformed label rather than a set larger than the target's tag_max_per_artifact.
  • #2720 also asks for query and write costs at a documented larger configuration. The PR doesn't report any.


class CatalogChangeProposal(TagDreamTarget, TagChangeProposal):
before_tags: tuple[str, ...] = Field(max_length=32)
before_tags: tuple[str, ...] = Field(max_length=MAX_TARGET_TAGS_CEILING)

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.

[P1] Raise the candidate contract along with these bounds

These models now accept up to 256 labels, but the contract's CatalogChangeProposal still caps before_tags and after_tags at 32 (openapi/powercontext.yaml:14729-14736, generated http/_generated/models.py:4674-4675). candidate_response validates each proposal into that model, so any candidate with more than 32 labels on either side fails response validation.

Reproduced on SQLite with the Dream e2e harness (tests/e2e/dream_support.py) and the Server app under TestClient:

  • tag_max_per_artifact=40, a target holding 40 tags, and a plan proposing one tag. Everything is within the configured limit.
    • /v1/candidates/get and /v1/candidates/list return 422 invalid_request ("The request violates the API contract.", loc: ["before_tags"]).
    • /v1/candidates/approve returns the same 422, yet the target's tags are now ["verified"].
    • /v1/candidates/reject also returns 422 and commits: a repeat returns 409 candidate_terminal.
  • Default limits and a plan proposing 33 tags. At 942e61f9a the run fails, because TagChangeProposal rejects 33 labels. Here the run succeeds with a pending candidate holding 33 after_tags.
    • get and list fail on after_tags.
    • Approve returns 422 "The request is invalid." with details: null, so the response doesn't carry the 32-tag message from _approve_once.
    • Reject clears the candidate, but also answers 422.

_candidate_responses maps the whole page, so /v1/candidates/list fails for every page that contains such a candidate.

The second case also changes behavior at default settings. The generator's output type is DreamPlan (composition.py:1549), and its after_tags schema now has maxItems: 256 instead of 32. propose() doesn't check the effective limit either, so a plan the deployment can't apply becomes a pending candidate.

Suggested direction:

  • Raise both contract bounds to the 256 ceiling and regenerate, so stored candidates stay readable after any limit change.
  • Check the effective limit when the candidate is proposed.
  • Keep the approval check for candidates created before a limit was lowered, and give it details the client can act on.

#2720 asks to explicitly define and test that approval case. HTTP tests for get, list, approve and reject would cover it.

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.

Independently reproduced at 25c27eb with real SQLite persistence and the controlled Dream generator: a valid target with 40 tags produces a pending candidate, GET returns 422 on before_tags, and APPROVE also returns 422 while the stored tags have already changed to ["verified"]. This confirms a committed write behind an error response, not just a static schema mismatch. Please align the candidate response contract with the supported tag ceiling before merging.

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 4b4db27. CatalogChangeProposal.before_tags/after_tags and CatalogTagResult.tags now allow the contract ceiling (256) in openapi/powercontext.yaml, and the generated models were refreshed. The new test_candidate_proposal_accepts_labels_above_the_default_limit validates a 40-label proposal, so a candidate over the old 32-label bound no longer fails response validation after approval commits.

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 4b4db27. The candidate response contract is now widened to 256 labels and regenerated; the 40-label model regression test covers the exact shape that returned 422 at 25c27eb. Validation over HTTP and the Dream harness needs the new wheel; I also requalified the Desktop contract at this head.

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.

Verified fixed at a735614. Replayed the same SQLite-backed Dream scenario with 40 existing labels: candidate get and approve now both return 200, and readback confirms the approved tag set. The former error-after-commit reproduction no longer fails.

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

Re-reviewed 25c27eb. The export-after-limit-reduction and embedded write-limit fixes pass independent SQLite/restart probes. However, the candidate response contract still returns 422 after committing approval, and the two embedded record-query paths still bypass the configured limit; independent reproductions are added to the existing threads. Please fix those before merging. Real-provider SQLite capture/generation, embedding and tag-filtered FTS/vector/hybrid recall passed. OceanBase acceptance did not reach the business flow: startup rejected the disposable database with DreamSchemaNotReadyError (candidate constraints). This is a validation limit, not a newly attributed PR defect.

@Lumea-art

Copy link
Copy Markdown
Contributor Author

Rebased onto 389c440 and addressed the two correctness findings plus the dry-run regression gap in 4b4db27 / 8eaf625:

  • Candidate contract (P1) — CatalogChangeProposal.before_tags/after_tags and CatalogTagResult.tags now use the 256-label contract ceiling; models regenerated. A 40-label proposal regression test covers the shape that returned 422 after approval.
  • Embedded query limit (P2) — RelationalTagService.query and RelationalRecordService.query_artifacts enforce the runtime's tag_max_query_labels; a new open_builtin_runtime test with limit 2 rejects three labels on both paths.
  • Dry-run regression (P2) — a CLI test exports a 33-label archive, accepts it at configured 64, and rejects it at 32, so the four call-site arguments are now protected.
  • Regenerated API/Desktop/JS/integration/Dify artifacts and the managed persistence digest; requalified as sqlite-tag-limits-4b4db27-v1 for wheel 0b74d467... (contract digest 2aaad075...).

Validation: 246 passed/81 skipped across tag, archive CLI, portable archive, catalog-change, API/JS contract suites; ty, ruff, ruff format, upgrade gate, API/JS generation checks and the Desktop contract test pass. The branch is 4b4db27 + 8eaf625, PR is mergeable; the force-push requires fresh review.

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

Rechecked 8eaf625 on SQLite through a real powercontext server run, the embedded Runtime and the archive CLI. The candidate P1 is fixed: with the per-Artifact limit at 64, 40-label candidates list, get, approve and read back over HTTP, and no approval commits behind an error. The two embedded query paths and the dry-run test are fixed too. One gap remains at the default settings: the Server now creates and revises tag candidates it can't approve.

What I checked

  • I compared the author's changes rather than the rebase. I applied the 25c27eb diff to 389c440 and diffed the result against 8eaf625. The new changes are the maxItems: 256 bound that before_tags, after_tags and CatalogTagResult.tags share, the query check in RelationalTagService.query and RelationalRecordService.query_artifacts, two tests, and the regenerated artifacts.
  • I seeded Dream candidates with the controlled generator from tests/e2e/dream_support.py. I read and acted on them over HTTP through a real Server process.
    • At TAG_MAX_PER_ARTIFACT=64, I tried a target holding 40 tags with a 1-label plan, and an empty target with a 40-label plan. In both cases list, get, approve, a repeated approve and get all return 200, and the target reads back with 1 and 40 tags. Reject returns 200 and leaves the 40 tags, and a repeated reject returns 409 candidate_terminal. At 25c27eb with a limit of 40, the first case still answers 422 on before_tags after committing.
    • I lowered the limit. A candidate with 40 after_tags created at 64 stays readable after a restart at 32: get and list return 200. Approve returns 422 and the target is unchanged. A 1-label candidate for a target that already holds 40 tags approves at 32.
  • Query limit.
    • Embedded query_tags and query_artifacts(tag_filter=…) accept 16 labels and reject 17 at the default, reject 3 at a limit of 2, and accept 64 at a limit of 64.
    • Over HTTP, artifact-tags/query, GET …/artifacts/atomic-memory?tag=… and memory/entries/list reject 17 labels at the default, with the "16-label query limit" message. At 64 they accept 64 labels, and the contract rejects 65.
  • Dry-run. archive restore --dry-run on a 33-label archive exits 0 at 64, at 33, and with --env-file set to 64. It exits 2 at 32 and at the default.
  • Test suites. The tag, archive, catalog-change, Dream and portability suites pass: 374 passed, 173 skipped. test_api_contract.py, test_js_operations.py and test_desktop_contract.py pass: 69 passed. Also passing: generate_api.py --check, generate_js_operations.py --check, the Dify generate_contract.py --check and upgrade_release_gate.py. Main CI on 8eaf625 is green, with the OceanBase and SeekDB jobs skipped.
  • Reverts. I reverted the source change behind each new test. Each new test then fails: the generated bounds back at 32, either query check, and the CLI call sites.

Remaining findings

  1. [P2] Tag candidates above the effective limit are still created, and revise now accepts them too.

    • Widening CatalogChangeProposal also widens a request. ReviseCandidateRequest.proposal uses CatalogChangeProposal (openapi/powercontext.yaml:12913-12922, :14716-14736). Neither the revise route (server/app.py:6110-6121) nor revise() (catalog_changes/service.py:234-277) checks the deployment limit.
      • At default settings, revising a tag candidate to 33 labels returns 200 and stores version 2. Master 389c440 and 25c27eb reject the same request with a 422 contract error. On master, a revise to 2 labels succeeds.
      • At a limit of 64, a revise to 65 labels also returns 200.
    • propose() (catalog_changes/service.py:162-189) still doesn't check the limit either. At default settings, a Dream plan with 33 after_tags becomes a pending candidate, while on master the same run fails. The JSON schema of DreamPlan, the generator's output type, now allows 256 after_tags (32 on master), whatever limit the deployment sets.
    • Approve rejects every one of these candidates. They also break clients built from the master contract, which still caps after_tags at 32. At default settings, PowerContextClient.get_candidate from 389c440 raises InvalidResponseError ("violated the API schema") on the revised 33-label candidate.
    • RFC 1715 bounds a revision's after_tags at 0–32. With a configurable limit, the consistent rule is 0 to the effective limit.
    • The direction I'd take:
      • Check after_tags against the effective limit in propose() and revise(), and in the revise route, the way _require_tag_admission guards tag writes.
      • A Dream run whose plan exceeds the limit then fails as it does on master.
      • Keep the approval check for candidates created before a limit was lowered.
  2. [P2] The new test doesn't cover the response that committed behind an error.

    • test_candidate_proposal_accepts_labels_above_the_default_limit (tests/test_tag_limits.py:205) only validates the model. I set the generated CatalogTagResult.tags back to max_length=32 and left CatalogChangeProposal at 256. The tag, archive, catalog-change and Dream suites and test_api_contract.py still pass: 413 passed.
    • On a real Server at a limit of 64, that mutant answers approve of a 40-label candidate with 422 on result.tags, while the target now holds all 40 tags. This is the original defect.
    • No test sets the per-Artifact limit above 32 and goes through candidate get, list, approve and reject over HTTP. #2720 also asks for the lowered-limit approval case to be tested.
    • The round-one fixes for export after lowering the limit (portability/bundle.py:633) and the embedded write limit (persistence/tags.py:181) are also still untested. Reverting either one leaves the same suites green, although both behave correctly at this head.
    • One HTTP test at a limit of 40 or 64 should approve and read back a candidate with more than 32 labels, approve one after the limit is lowered, and assert the response and the stored tags. That would cover the P1 path.
  3. [P3] An over-limit approval returns no details.

    • _approve_once raises InvalidCandidateError("after_tags", "the candidate exceeds the deployment's 32-tag Artifact limit") (catalog_changes/service.py:305-309). _CANDIDATE_ERROR_REASONS (server/app.py:7742) has no entry for it, so the client gets 422 "The request is invalid." with details: null.
    • With that check removed, the same request fails in replace_in_transaction and carries {"field": "tags", "reason": "has an invalid number of labels"}. The explicit check makes the response less specific.
    • A mapped reason for after_tags, together with the limit, would let the Dashboard and clients explain why the candidate can't be approved. docs/*/docs/workflows/review-dream-revisions.md doesn't describe this outcome yet.
  4. [P3] Docs. These are unchanged since 25c27eb.

    • docs/zh/docs/operate/configuration.md:57-58 still says a merge result keeps at most 32 tags. The English paragraph at docs/en/docs/operate/configuration.md:67-70 describes the configurable limit.
    • Neither locale says whether changing the two settings requires a restart, which #2720 asks for.
    • Neither locale says that a limit above 32 needs clients built from this contract. A client from master rejects tag sets and candidates larger than 32 labels.

Notes (not blocking)

  • Two errors still don't name the limit. An embedded over-limit replace_tags raises "tags has an invalid number of labels", and the restore dry-run reports "artifact tag set has invalid labels".
  • The cost figures #2720 asks for are still missing.
  • hidb4ai's two findings and AlexStocks' dry-run test request are addressed, as checked above. I didn't run OceanBase.
  • As it stands, #2745 changes the same contract digest, Desktop compatibility profile, limits.py and release/upgrade-support.json. Whichever merges second needs to regenerate those files and add a new Desktop profile.

@Lumea-art

Copy link
Copy Markdown
Contributor Author

Addressed the remaining P2 findings and the documentation details in 7160b93, requalified in c71da4b:

  1. Over-limit candidates (P2) — CatalogChangeService.propose and revise now reject after_tags above the effective limit before writing anything; the approval check remains for candidates created before a limit was lowered. At default settings a 33-label Dream plan or revision now fails instead of storing an unapprovable candidate, and at 64 a 65-label revision fails.
  2. Regression coverage (P2) — added HTTP coverage for a 40-label candidate at limit 64 (get/list/approve/readback), the lowered-limit approval case (candidate stays readable, approve returns 422, target unchanged), proposal/revise limits, the embedded write limit, and export after lowering the limit.
  3. Approval details (P3) — over-limit approval now returns 422 with details.field="after_tags", details.reason="tag_limit_exceeded" and the effective details.limit; the embedded write error also names the configured limit. review-dream-revisions.md documents the outcome in both locales.
  4. Docs (P3) — the zh configuration paragraph now describes the effective merge-result limit instead of a fixed 32; both locales state that the settings take effect on restart and that reading or writing more than 32 labels requires a client built from this contract.

Validation: tag, archive CLI, catalog-change, portable-archive and Dream suites → 259 passed, 81 skipped; ty on changed files, ruff, format, API/JS generation checks, Dify check, upgrade gate and Desktop contract pass. Requalified as sqlite-tag-limits-7160b93-v1 for wheel 5be09b2a…; the Bearer probe covers the 13 Desktop operations and the 64/65 and 20/21 boundaries.

Two non-blocking notes remain as stated: the restore dry-run message is still the generic artifact tag set has invalid labels, and #2720's cost figures are not included here.

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

Rechecked c71da4b on SQLite through real powercontext server run processes and the embedded Runtime. Both P2 findings are fixed. At default settings a 33-label revision is now rejected and a 33-label Dream plan leaves no candidate. The new tests fail when each fix is reverted. Over-limit approval now returns details. What's left is small: two sentences in the new docs paragraph, some Chinese line breaks, and the notes below. I have no blocking concerns, so I'm approving.

What I checked

  • Proposal and revision limits. I seeded Dream candidates with the controlled generator from tests/e2e/dream_support.py and acted on them over HTTP.
    • Default limit: revising a 1-label candidate to 32 labels returns 200 and stores version 2. Revising it to 33 returns 422 with {"field": "after_tags", "reason": "tag_limit_exceeded", "limit": 32}, and the candidate stays at version 2 with 32 labels.
    • Default limit: a Dream plan with 33 after_tags ends as a failed run with error invalid_generation_output, after 1 attempt and 1 model call. It leaves no candidate rows. On 389c440 a real model's 33-label output would fail output validation, which _map_error turns into the same error code. The Dream generator runs with max_requests=1, so neither branch retries.
    • Limit 64: revise to 64 returns 200 and revise to 65 returns 422 with limit: 64. At a limit of 100, revise to 101 reports limit: 100, so the parsed limit isn't limited to two digits.
    • Limit 64, 40-label candidate: list, get, approve, repeated approve and get all return 200, with result.tags holding 40. The target reads back with 40 tags. PUT of 64 tags returns 200, and 65 returns 422 naming the 64-label limit.
    • Lowered limit: a 40-label candidate created at 64 and served at 32 returns 200 for get and list. Approve returns 422 with limit: 32, the target stays empty and the candidate stays pending. Reject then returns 200, and a repeated reject returns 409 candidate_terminal.
  • No other way in. Every proposal goes through propose(). In the Server its only caller is Dream's _propose, and no route creates a tag candidate directly. Embedded callers of catalog_changes.for_scope(...).propose() hit the same check. Portable archives reject tag candidates ("tag Candidates are not supported by portable archives"), so restore can't bring one in.
  • Clients built from 389c440.
    • The new 422 parses: approve_candidate raises ServerResponseError with details={'field': 'after_tags', 'reason': 'tag_limit_exceeded', 'limit': 32}.
    • On 40-label data, get_candidate, get_artifact_tags and list_candidates (for the pending candidate) raise InvalidResponseError. This is the case the new configuration paragraph describes.
    • A client built from c71da4b reads all of them.
  • Reverts. I reverted each fix alone and ran the tag, archive, portability, catalog-change, Dream and test_api_contract.py suites.
    • Removing the propose() check or the revise() check fails test_candidate_proposal_and_revision_respect_the_effective_limit.
    • Removing the tag_limit_exceeded mapping or the limit key fails test_lowering_the_limit_keeps_candidates_readable_but_not_approvable.
    • Removing the embedded write check in replace_in_transaction, or restoring the 8eaf625 version of it, fails test_embedded_runtime_rejects_tag_writes_above_the_configured_limit.
    • Pointing the export validation back at the configured limit fails test_export_survives_a_lowered_write_limit.
    • Setting the generated CatalogTagResult.tags back to max_length=32, with the proposal left at 256, fails test_candidate_larger_than_the_default_limit_approves_over_http. This is the mutant that survived on 8eaf625.
    • Removing the approval check fails the lowered-limit test.
  • Test suites. At c71da4b the tag, archive CLI, portability, portable/plugin archive, artifact-tag, catalog-change and Dream suites pass, together with test_api_contract.py, test_js_operations.py and test_desktop_contract.py: 426 passed, 169 skipped. Also passing: generate_api.py --check, generate_js_operations.py --check, the Dify generate_contract.py --check and upgrade_release_gate.py. CI on c71da4b is green: 72 checks pass and 22 are skipped, including the OceanBase and SeekDB jobs.
  • Desktop profile. c71da4b differs from 7160b93 only in desktop/VALIDATION.md and compatibility.json, so serverCommit 7160b93 matches the head's Server code. The contract digest is unchanged since 8eaf625.

Remaining findings

  1. [P3] The new paragraph in review-dream-revisions.md doesn't describe a Dream proposal correctly, and it splits a sentence pair.
    • It says an over-limit proposal is rejected with a 422 invalid_request response. Over HTTP a tag proposal only comes from a Dream run, which has no response to return: the run fails with invalid_generation_output and creates no candidate. An embedded catalog_changes caller gets InvalidCandidateError. Only revise and approve return the 422. The zh paragraph says the same.
    • In docs/en/docs/workflows/review-dream-revisions.md:88-93 the paragraph sits between "Approval checks both the Tag ETag and content baseline atomically." and " The result contains the complete tags and new ETag…". They render as one paragraph, so "The result" now follows "leaves the target unchanged" and reads as the rejected approval's result. Moving the new text after the result sentence fixes it.
  2. [P3] The new zh lines break between two Chinese characters, which the website renders as a space.
    • docs/zh/docs/operate/configuration.md: 58→59 (重启后|生效), 59→60 (去重后|超过), 60→61 (顺序见|[使用…). The old text kept the last one on one line.
    • docs/zh/docs/workflows/review-dream-revisions.md: 90→91 (已创建的|候选).
    • The zh workflow page also gains a second blank line at line 12 and after the new paragraph.

Notes (not blocking)

  • In revise(), the limit check runs before lock_pending. A 33-label revise of a rejected candidate therefore returns 422 tag_limit_exceeded, while a 1-label revise of the same candidate returns 409 candidate_terminal. Both responses are rejections, but the 409 tells the caller more.
  • _candidate_error_details parses limit back out of the message with a regex, so the two places that build the message (_require_after_tag_limit and the inline copy in _approve_once) have to keep "deployment's N-tag" exactly. Calling _require_after_tag_limit(current.proposal) from _approve_once, or carrying the limit on the error, would remove that coupling.
  • DreamPlan's JSON schema, which the model sees through PromptedOutput, still allows 256 after_tags whatever the deployment sets, and the instructions don't mention the limit. A model at default settings is no longer told 32. The run fails cleanly either way, as above.
  • release/upgrade-support.json schema_review.rationale now has two "PR #2816 makes the per-Artifact and per-query tag limits configurable…" sentences. The new one appears to be meant to replace the old one.
  • RFC 1715 (en line 127, zh line 301) still bounds after_tags at 0–32, and RFC 1467 (en line 242, zh line 232) still says at most 32 tags. The behavior now matches "0 to the deployment's effective limit, 32 by default". Updating both, here or in a follow-up, would keep the RFCs in line with the code.
  • The revise limit is covered through CatalogChangeService.revise and not through POST /v1/candidates/revise. The HTTP behavior is correct, as above.
  • As it stands, #2745 still changes openapi/powercontext.yaml, the generated models and schema, compatibility.json, desktop/VALIDATION.md, limits.py, server/app.py, both configuration.md pages and release/upgrade-support.json. Whichever merges second needs to regenerate those files and requalify Desktop.
  • I didn't run OceanBase or the Desktop native probe.

Lumea-art added a commit to Lumea-art/powercontext that referenced this pull request Nov 27, 2026
Correct the Tag review paragraph: a Dream proposal over the limit fails its run
and creates no candidate, while revise and approval return the mapped 422; move
it after the approval-result sentence. Reuse _require_after_tag_limit for the
approval check so the message has one owner, drop the duplicate PR oceanbase#2816
rationale, fix Chinese line breaks, and update RFC 1715/1467 from a fixed 32-tag
bound to the deployment's effective limit.
@Lumea-art

Copy link
Copy Markdown
Contributor Author

All remaining P3 items are fixed on 32091a7 (requalified in a735614):

  1. Review paragraph — now states that an over-limit Dream proposal fails its run with invalid_generation_output and creates no candidate, while revise/approval return the mapped 422 and an embedded catalog_changes.propose gets InvalidCandidateError. It sits after the “The result contains…” sentence, so the result wording no longer attaches to a rejected approval.
  2. Chinese line breaks — configuration.md now breaks after punctuation/ASCII only; the review page’s new paragraph is one line and its extra blank lines are gone.
  3. Notes — _approve_once now calls _require_after_tag_limit(current.proposal) instead of duplicating the message; the duplicate PR feat(tags): make the per-Artifact and per-query tag limits configurable #2816 rationale sentence is removed; RFC 1715 and 1467 now describe 0 to the deployment’s effective limit (32 default, ceiling 256) in both locales.

Still open as acknowledged follow-ups: the revise limit check runs before lock_pending, so a terminal candidate reports tag_limit_exceeded rather than candidate_terminal; DreamPlan’s schema still advertises 256; and #2720’s cost figures are not included.

Validation on the new head: tag/catalog/Dream suites pass, ruff and format pass, upgrade gate passes with the refreshed digest, and the Desktop record sqlite-tag-limits-32091a7-v1 matches wheel 30985637…; the Bearer probe still passes all 13 operations and the 64/65 and 20/21 boundaries. Please re-approve the new head.

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

Re-reviewed a735614. The previously reproduced candidate-response, embedded query/write-limit, export-after-limit-reduction and archive dry-run issues are fixed; confirmations are in the existing threads. I found no new blocking correctness issue in the reviewed changes.

Real-provider SQLite capture/generation, embedding and tag-filtered FTS/vector/hybrid recall passed. Fresh OceanBase acceptance also passed at this commit in both enforced and disabled access modes. Each mode used a separate disposable database, initialized through the full Server migration runner (plan/apply/verify to revision 000), followed by the existing tag HTTP behavior suite and real-provider capture/generation, embedding, and tag-filtered FTS/vector/hybrid recall. HTTP handlers were exercised through in-process ASGI transport with the real database and providers. Both databases were dropped after successful validation.

The earlier OceanBase startup failure came from the pre-existing configured database, before disposable-database creation. The fresh run avoids using that old business schema for the administrative connection. This validates fresh initialization and the tested business flows, not migration of that existing database. Larger-limit query/write costs remain unquantified.

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

  • Resolve merge conflicts with the target branch.

context: Any = None,
change: UserChange | None = None,
caller_scoped: bool = False,
tag_limit: int = MAX_TARGET_TAGS,

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.

[P2] Apply the configured query limit to plugin listings

With tag_max_query_labels=40, plugin calls to writer.list(tags=...) and tx.list(tags=...) still reject 40 distinct labels because _Reads.list calls normalize_tags with its default maximum of 32. Propagate the query limit through both plugin host and Worker specs into the list validator so these filters honor the deployment setting.

@Fengzdadi

Copy link
Copy Markdown
Collaborator

Thanks. I checked 32091a727 and a7356146b:

  • review-dream-revisions.md now says that an over-limit Dream proposal fails its run with invalid_generation_output and creates no candidate, that revise and approval return the 422, and that an embedded catalog_changes.propose call gets InvalidCandidateError. In en, "The result contains…" again follows the approval sentence it describes.
  • The lines this PR adds to the zh pages no longer break between two Chinese characters. One extra blank line is left at line 12 of the zh review-dream-revisions.md. It renders the same, so it can wait for the master merge.
  • _approve_once now calls _require_after_tag_limit, which raises the same error with the same message. The duplicate rationale sentence is gone, and RFC 1467 and 1715 describe the effective limit in both locales.
  • At a7356146b the suites I ran on c71da4b4f pass again with the same counts, 426 passed and 169 skipped, and upgrade_release_gate.py passes too.

hireview001's new P2 on plugin listings holds from the code. PluginArtifactWriter and PluginArtifactTransaction inherit list() from _Reads, which checks the filter with normalize_tags at its default maximum of 32 (writer.py:236, the same call as on master), and nothing under plugins/ reads tag_max_query_labels. With the setting at 40, a plugin filter of 33 labels is rejected. At the default 16, plugin filters still take up to 32 labels. The configuration table says the setting applies to Artifact tag filters. Passing the limit through also lowers the plugin default from 32 labels to 16, so the PR description should call that out for plugin authors.

My approval from c71da4b4f still counts, because the master ruleset doesn't dismiss approvals on new pushes. The three remaining notes are fine as follow-ups. I'll recheck after the plugin listing fix and the master merge. #2745 merged first, and a trial merge of master conflicts in server/app.py, release/upgrade-support.json and four Desktop files. So the master merge has to resolve server/app.py, regenerate the generated files and the upgrade digest, and requalify Desktop again.

@AlexStocks

Copy link
Copy Markdown
Contributor

@Lumea-art plz fix the file confliction and then we can merge it.

@Lumea-art

Copy link
Copy Markdown
Contributor Author

Rebased onto 901247c (which now contains #2745) and fixed the plugin-listing P2 in 2e111d6, requalified in 49e0782.

  • Merge — resolved server/app.py by keeping both limits (source_content_max_chars alongside tag_limits), regenerated API/Desktop/JS/integration/Dify artifacts and refreshed the managed digest (aa1745b9… before the final commit).
  • Plugin listings (P2) — tag_max_query_labels now flows through PluginManager → PluginHostSpec/PluginWorkerSpec → PluginArtifactWriter; _Reads.list rejects filters above the effective limit and normalizes with it. test_plugin_listing_applies_the_configured_query_limit covers 40 labels at limit 40, 41 rejected, and the default rejecting 17 at 16.
  • Plugin default change — plugin filters now default to 16 labels (the documented query limit) instead of the previous 32; I'll call this out in the PR description.

Validation on the rebased head: 146 passed/18 skipped across tag, plugin-writer, archive CLI, catalog-change, Dream, API/JS suites; upgrade gate, generation checks, Desktop contract and the Bearer probe (13 operations, 64/65 and 20/21 boundaries) pass. The branch is 2e111d6 + 49e0782; please re-review the conflict resolution and plugin fix.

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

The plugin query-limit propagation fixes the previous admission gap, but introduces a pagination regression in tagged plugin listings. Reproduced through a running Server and spawned plugin Host; please preserve the caller's page size when validating the tag count.

Validation limit: the fresh OceanBase rerun at this commit stopped during explicit schema initialization with native error 4012 (RPC post error), before the real-provider business flow. Cleanup succeeded on retry and the disposable database was verified absent. The earlier OceanBase acceptance was on a735614 and is not claimed as acceptance of this updated commit.

statement = statement.where(heads.c.artifact_id > cursor)
if tags:
keys = tuple(normalize_tags(tuple(tags), allow_empty=False))
limit = owner.tag_query_limit

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] Keep the query-label bound separate from the page-size limit

This assignment overwrites the caller's pagination limit after SQL has already been built with .limit(limit + 1). The later identities[:limit] and next_cursor calculation therefore use tag_max_query_labels instead of the requested page size. Reproduced at 49e0782 through a running Server and spawned plugin Host: with three matching tagged artifacts and tag_max_query_labels=40, ctx.reads(scope).list(tags=["selected"], limit=1) returns two items and next_cursor=None, so the third matching artifact is unreachable through pagination. The shared implementation also affects writer.list and tx.list, including default settings whenever page size differs from the query-label limit. Use a separate local for the tag bound and cover a nonempty tagged multi-page result.

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.

独立复核上述结论,缺陷由本 PR 引入,且影响面比单个 writer.list 更宽。

  • 归因:master b8603175 的 src/powercontext/builtin/plugins/writer.py(blob eb933c9f)在该查询处只有 .limit(limit + 1),没有 limit = owner.tag_query_limit;本 PR head 49e07823 在 .limit(limit + 1)(:231)之后新增 .limit 重绑定(:236),随后 identities[:limit](:256)与 next_cursor 计算(:259)都用到了被覆盖后的值。
  • 共享实现:该 list 定义在 _Reads(writer.py:213),PluginArtifactTransaction(:317)与 PluginArtifactWriter(:699)都继承它,因此 ctx.reads(...).list、writer.list、tx.list 三处同受影响;host.py:316/:467 把 spec.tag_max_query_labels 注入为 tag_query_limit。
  • 两个方向的后果都可以从代码直接推出,不需要运行:
    • 请求 limit 小于 tag 上限时丢页:默认 tag_max_query_labels=16,若调用方 limit=1,SQL 取 2 行,identities[:16] 返回 2 条而 len(2) > 16 为假 ⇒ next_cursor=None,第 3 条及之后不可达(与上述 limit=1 / tag_max_query_labels=40 的复现同因,但默认配置即成立,不限于显式放大 tag 上限)。
    • 请求 limit 大于 tag 上限时静默缩小页:limit=50、tag 上限 16 时每页只返回 16 条。
  • 修复方向:tag 数量校验与 normalize_tags 的上界用独立局部变量(例如 tag_bound = owner.tag_query_limit),不要覆盖分页用的 limit;回归用「3 个同标签 Artifact + limit=1 + 默认 tag 上限」断言 len(page.items) == 1 且 next_cursor 非空,再补一条 limit > tag 上限 的页大小断言。

说明:本条不涉及我此前在本 PR 的两条线程(tests/test_tag_limits.py 的 ty 失败、bundle.py 的 dry-run tag_limit 透传),那两条在 49e07823 上仍成立(本地 ty check tests/test_tag_limits.py 通过;tests/test_archive_cli.py 30 passed;移除 _validate_only 四处透传后该用例 1 failed)。

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 b7399de. _Reads.list now keeps the caller's limit for SQL, slicing and next_cursor, and uses a separate tag_bound = owner.tag_query_limit only for the label-count check and normalize_tags maximum. test_plugin_listing_keeps_the_requested_page_size creates 20 tagged artifacts and asserts limit=1 returns one item with a non-empty cursor and a second page reaches a different artifact, then asserts limit=20 returns all 20 with no cursor, so both the shrunken-page and lost-page cases are covered.

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.

Verified fixed at 0786032 through the running Server and spawned plugin Host: with three tagged artifacts, query-label limit 40 and page size 1, the response now contains one item and a non-empty next cursor. The nonempty pagination regression test also passes on the current merge result. Host and Worker paths still accept 40 query labels and reject 41.

Add RuntimeConfig.tag_max_per_artifact (default 32, ceiling 256) and
tag_max_query_labels (default 16, ceiling 64). Enforce the effective policy at
the owning boundaries: HTTP tag writes/queries/filters, the Atomic Memory
runtime list/search/manifest filters, embedded Runtime tag and artifact queries,
plugin Artifact listings and writes, Dream/catalog proposal, revision and
approval, merge tag selection and the storage write service. Read, export and
import paths stay ceiling-bound so lowering a limit never hides existing sets.

Widen the candidate response contract to the same 256-label ceiling, reject
over-limit proposals and revisions before they are stored, apply the query limit
to plugin listings without changing the caller's page size (default 16 rather
than 32), and keep export independent of the current write-admission limit with
the CLI dry-run passing the configured value.

Cover the candidate HTTP paths, both embedded query paths, plugin listing bounds
and pagination, the embedded write limit and the dry-run boundary; refresh
generated artifacts, docs and environment template; recompute the managed
persistence digest after the content-limit merge.
Record sqlite-tag-limits-b7399de-v1 for the wheel built from the merged
implementation commit. The Bearer probe covers all thirteen Desktop operations,
the 64/65 Artifact-label and 20/21 query-label boundaries, and the Atomic Memory
list query-limit rejection.
@Lumea-art

Copy link
Copy Markdown
Contributor Author

Rebased onto 476bd2c and fixed the plugin pagination regression in b7399de (requalified in 0786032).

  • Pagination — _Reads.list no longer rebinds limit; the tag bound is a separate local used only for the label-count check and normalize_tags, so SQL, slicing and next_cursor keep the caller's page size. The new test_plugin_listing_keeps_the_requested_page_size covers limit=1 with 20 tagged artifacts (one item + non-empty cursor, second page differs) and limit=20 (all 20, no cursor).
  • Merge — rebased onto 476bd2c, regenerated API/Desktop/JS/integration/Dify artifacts and refreshed the managed digest; no conflicts remain.
  • Validation — 147 passed/18 skipped across tag, plugin writer, archive CLI, catalog, Dream and API/JS suites; upgrade gate, generation checks, Desktop contract and the Bearer probe (13 operations, 64/65 and 20/21 boundaries) pass. Desktop record is sqlite-tag-limits-b7399de-v1 for wheel 7e2d4630….

The OceanBase 4012 failure you hit was during disposable schema initialization, before the business flow; I have not claimed OceanBase acceptance for this head. Please re-review the page-size fix and the merge.

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

Re-reviewed 0786032. The tagged plugin pagination regression is fixed; confirmation is in the original thread. I found no remaining blocking correctness issue in the reviewed changes.

Fresh OceanBase initialization to 000, tag HTTP behavior, and real-provider generation/embedding plus tag-filtered FTS/vector/hybrid recall passed at this head with access enforcement enabled; the disposable database was removed. The current merge result cbaf025 (master 15b2548 plus this head) also passed plugin pagination tests and the SQLite real-provider journey. Database/provider calls were real; these backend journeys used in-process ASGI HTTP transport, while the plugin check used a running TCP Server and spawned Host/Worker processes. This does not certify upgrades of the existing database or high-limit performance.

No new tables, migrations or HTTP routes are introduced. There are new deployment configuration interfaces and expanded existing API bounds, so I am leaving a comment rather than automatic approval under the requested review policy.

@hidb4ai
hidb4ai merged commit a0593e1 into oceanbase:master Nov 30, 2026
94 checks passed
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

6 participants