Skip to content

fix(runtime): make concurrent OceanBase replica startup idempotent - #1957

Open
Tsukikage7 wants to merge 13 commits into
oceanbase:masterfrom
Tsukikage7:fix/concurrent-runtime-startup
Open

Tsukikage7 wants to merge 13 commits into
oceanbase:masterfrom
Tsukikage7:fix/concurrent-runtime-startup

Conversation

@Tsukikage7

@Tsukikage7 Tsukikage7 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

Related to #1609. Supplies the runtime cold-start dependency for the API/background Helm deployment in #1854; does not close either item.

Rationale for this change

Concurrent API/background replicas can race between schema existence checks and DDL, or lose a static authorization preset's first unique-key insert. On OceanBase CE 4.4.2.1, native VECTOR creation can additionally return error 1235 even with IF NOT EXISTS while another replica owns the column reservation and its logical index metadata is still settling.

What changes are included in this PR?

  • Use native idempotent table and ordinary-index DDL for OceanBase/seekdb. Keep specialized vector-index ownership with the native vector initializers so regular schema creation cannot discard VECTOR/HNSW semantics.
  • Make Experience, Atomic Memory and both Topic Memory full-text projections use native IF NOT EXISTS, retaining MATCH capability probes and current-schema validation.
  • Validate the exact native vector name, embedding column and requested parameters using SHOW CREATE TABLE. For the specific OceanBase duplicate-column 1235 race, wait for matching logical metadata within the tenant's existing query timeout, without replaying CREATE. Reject ordinary or incompatible indexes and unrelated errors.
  • Replay only rolled-back MySQL 1062 conflicts for static authorization presets, with the same binding and idempotency key and at most three attempts; propagate other or persistent failures.
  • Add concurrent startup, native-vector ownership, metadata validation and authorization regressions against the current Atomic Memory schema (pc_atomic_memory_current).

The branch includes current master through 329b4be, including upstream cancellation cleanup. The PR's net change is 11 source/test files; no Helm manifests, credentials or acceptance artifacts are included.

Are there any user-facing changes?

Concurrent replicas can initialize a fresh external OceanBase database reliably, while unusable native indexes still prevent startup. No public API or persisted-format change is introduced, and existing SQLite recorder retries are unchanged. Real concurrent cold-start acceptance covered OceanBase CE 4.4.2.1. The final head also passed the CI clean-migration suite on OceanBase CE 4.3.5.6; this is a separate migration/authorization/vector regression scope. Seekdb and other versions have not received concurrent cold-start acceptance for this patch.

How was this change tested?

On final head c8a0730:

  • uv run --locked python -m pytest tests/builtin/persistence/test_native_schema_creation.py tests/builtin/persistence/test_vector_initialization.py tests/builtin/persistence/test_topic_memory_oceanbase.py tests/test_access_bootstrap.py tests/builtin/persistence/test_sqlite_profile.py tests/builtin/runtime/test_model_usage_recorder.py -q: 87 passed, 1 skipped (no live database configured in this local run).
  • make check: passed, including uv run --locked prek run -a, both type-check scopes and 49 integration-manifest tests.
  • make docs-test: passed; 916 public pages and their internal links verified.
  • uv run --locked python -m pytest -q: 5060 passed, 430 skipped, 4 deselected, 1 failed in 20m43s. The sole failure is the existing tests/builtin/test_native_code.py::test_credentials_and_symlinks_are_not_read fixture attempting to git add .env under the host global Git ignore rule. The exact test passed separately with GIT_CONFIG_GLOBAL=/dev/null; user Git configuration and test source were unchanged.
  • Fork E2E workflow: completed, success on this exact head, all 5 jobs passed (Recall effort/OceanBase, Atomic Memory clean migration/OceanBase, validate, Acceptance/SQLite, Acceptance/OceanBase). Logs confirm 3 real OceanBase contract tests, 302 recall/statistics/prepared-context regressions, 40 clean migration cases without skips, 18 OceanBase Atomic Memory/HTTP regressions, and both deterministic acceptance scenarios.
  • Upstream workflows for this head are action_required, awaiting maintainer authorization; the fork run does not replace upstream required checks.

Separate real-backend acceptance was completed before the latest master merge, using the final six production-file patch on base 2058325. These production files are identical on this PR head:

  • OceanBase CE 4.4.2.1: 7 passed, no skips, covering concurrent/repeated DDL, unusable FTS rejection, preserved rows, authorization bootstrap, all three native vector indexes and real Topic Memory hybrid/detail search.
  • An isolated amd64 Kubernetes Helm source fixture loaded that exact patched runtime into two API and two background replicas: fresh-database cold start with zero restarts; authenticated HTTP/MCP and unauthenticated 401; persistence after replacing API pods; and observed leader lease transfer after deleting the identified background leader. Current Atomic Memory schema columns were verified.
  • Acceptance resources and temporary credentials were removed afterward.

Limit: the Kubernetes run used a temporary source fixture, not a newly published application image. Published-image pull/entrypoint and the unmodified chart against that image remain unverified. The real-backend and Kubernetes acceptance has not been rerun after the latest master merge; the cleaned environment was not recreated.

AI usage statement

OpenAI Codex assisted with implementation and validation. The exact model identifier was not recorded in the local task evidence.

@AlexStocks AlexStocks added the 1.4.0 v1.4.0 release tracking label Oct 14, 2026
@hidb4ai hidb4ai removed the 1.4.0 v1.4.0 release tracking label Oct 15, 2026
@AlexStocks AlexStocks added the 1.4.1 v1.4.1 release tracking label Oct 17, 2026
@hidb4ai hidb4ai added 1.5.0 v1.5.0 release tracking and removed 1.4.1 v1.4.1 release tracking labels Oct 23, 2026
@hidb4ai

hidb4ai commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Ready for review?

@Tsukikage7
Tsukikage7 marked this pull request as ready for review October 30, 2026 14:37

Copy link
Copy Markdown
Contributor Author

@hidb4ai Yes, this is ready for code review. I've marked it ready.

Main and E2E pass on the current head, c8a0730. This supersedes the description's earlier note about upstream workflows awaiting authorization. GitHub still reports merge conflicts, and Desktop validation fails in the Windows CLI diagnostic probe (CompatibilityUnverified), so it isn't merge-ready yet.

The source and real OceanBase validation details are documented in the description. Published-image and unmodified Helm chart acceptance remain unverified, separate from the completed source-fixture acceptance.

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

Found one startup compatibility regression for already provisioned databases; details inline.

for table in metadata.sorted_tables:
if table not in selected:
continue
await connection.execute(CreateTable(table, if_not_exists=True))

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] Preserve startup with a provisioned schema and DML-only account

IF NOT EXISTS still checks CREATE privileges on OceanBase for an existing table. On real OceanBase CE 4.3.5.5, I initialized the Access schema and static administrator, granted the runtime user only SELECT/INSERT/UPDATE/DELETE, and called open_builtin_access_control with the same preset. Base 329b4be7 starts and authorizes server.admin; c8a0730 fails here with 1142 (CREATE command denied on pc_access_audit). Restarting this already provisioned deployment now requires expanding its runtime database privileges. Please preserve a no-DDL path for existing objects while retaining race-safe creation for missing tables and indexes.

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.

本轮在 head 4748ad6b 上核了这条 P2 的修复状态,结论分两半。

已闭合的两处(FULLTEXT 索引)

4748ad6b 给两个站点补了存在性查询,只有索引缺失时才发 CREATE ... IF NOT EXISTS:

  • oceanbase/atomic_memory_index.py:104-111(information_schema.statistics + _INDEX_EXISTS);
  • oceanbase/experience_index.py:72-76(新增 _OCEANBASE_FTS_INDEX_EXISTS_SQL);topic_memory_index.py::_ensure_index 本来就有同样的守卫。

test_native_schema_creation.py::test_fulltext_initialization_preserves_provisioned_and_missing_indexes 用 1142 断言 provisioned 时不发 CREATE;exact head 副本 tests/builtin/persistence/ + tests/test_access_bootstrap.py 为 803 passed / 5 failed,5 个失败在 base 0c1dfc28 同集合复现(Windows 文件锁 + test_mysql_vector_admission 的 allow_missing_database 桩签名),非本 PR 引入。

仍未覆盖的部分(表路径)

启动期还会发 DDL 的站点至少有:

  • create_tables() → _create_mysql_tables()(persistence/schema.py:70):用 inspect().has_table(),MySQL 方言实现是 DESCRIBE,只吞 1146/1049/1051(本仓 pin 的 SQLAlchemy 2.0.51),其余错误上抛;表存在则不进入 CreateTable(if_not_exists=True);
  • ensure_artifact_head_searchable_text() 与 require_current_schema() 的 ALTER:均以 information_schema 查询为前提。

你报告的失败对象是 pc_access_audit,那是一张表,落在 _create_mysql_tables() 这条线上,而该线本 head 未改。从 head 源码看,只有 has_table() 对该表返回 False 时才会发 CREATE TABLE IF NOT EXISTS;DML 账户持有 SELECT 时 DESCRIBE 应当成功,所以我这边(无真实 OceanBase)无法复现该分支,也无法确认 c8a07306 的 1142 是来自表路径还是当时的索引路径(c8a07306 确实删过 atomic 的存在性检查,4748ad6b 又加回来了)。

请在 4748ad6b 上重跑一次 DML-only 复现,并给出失败语句原文与对象名,以判定:

  • 报错对象是 pc_atomic_memory_current / pc_artifact_heads 的索引 ⇒ 本 head 已闭合,可以解除;
  • 报错对象仍是 pc_access_audit 等表 ⇒ 说明该租户下 has_table() 返回 False,需要对表路径同样改成"先查 information_schema、再决定是否 CREATE",这条 P2 不能算解除。

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.

Replayed the original scenario on c430184918b9e6a03457715d8a0191eb893e1777 against real OceanBase CE 4.3.5.5: provision the Access schema and static administrator with the administrative account, grant a separate runtime account only SELECT/INSERT/UPDATE/DELETE, then call open_builtin_access_control with the same preset. Both consecutive startups now succeed and authorize server.admin. The original c8a0730 failure was indeed CREATE TABLE IF NOT EXISTS pc_access_audit: that version executed table DDL unconditionally. The current has_table() guard removes that path. This reported Access startup regression is fixed.

…61030

# Conflicts:
#	src/powercontext/builtin/persistence/oceanbase/atomic_memory_index.py
#	src/powercontext/builtin/persistence/oceanbase/experience_index.py
#	src/powercontext/builtin/persistence/oceanbase/topic_memory_index.py
#	src/powercontext/builtin/persistence/schema.py

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

@hidb4ai hidb4ai removed the 1.5.0 v1.5.0 release tracking label Nov 2, 2026
@AlexStocks AlexStocks added the 1.5.1 v1.5.1 release tracking label Nov 3, 2026

@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 prior DML-only Access startup regression is fixed on this head. Native vector reinitialization with unquoted SHOW CREATE output and the live FULLTEXT inventory assertion still need fixes; details inline.

Comment on lines +61 to +62
quoted_name = re.escape(preparer.quote_identifier(name))
quoted_column = re.escape(preparer.quote_identifier(column.name))

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] Recognize unquoted native index definitions

With sql_quote_show_create=OFF, OceanBase returns VECTOR KEY ix_pc_atomic_memory_current_embedding (embedding) ..., so these mandatory quoted patterns never match the existing index. Reinitialization then issues CREATE again and fails with 1235, aborting Atomic Memory initialization. On real OceanBase CE 4.3.5.5, the complete OceanBaseAtomicMemoryIndex(profile).initialize(connection) succeeds at merge base 5032075, fails at c4301849 against the same provisioned database with this session setting, and succeeds again after only restoring sql_quote_show_create=ON. Please support both valid SHOW CREATE forms, or normalize the setting while preserving the caller's session state, so compatible existing indexes remain reusable.

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 on 8cabe99af6c59f27b2189479bee87b784c87423a against native OceanBase CE 4.4.2.1: the live regression confirms unquoted SHOW CREATE output and successful Atomic Memory reinitialization with sql_quote_show_create=OFF. Concurrent and repeated native-vector initialization also passed. This finding is fixed.

)
)
).all()
assert set(rows) == {

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] Scope the FULLTEXT inventory assertion to the tested projections

This query inventories every FULLTEXT index in the database, but _isolated_database() now provisions BUILTIN_TABLES, including pc_artifact_search_text and its ix_pc_artifact_search_fts index. On real OceanBase CE 4.3.5.5 at c4301849, all concurrent initializers and the repeated initialization completed, then this assertion failed because the result also contained ('pc_artifact_search_text', 'ix_pc_artifact_search_fts', 'FULLTEXT'). The new live acceptance test therefore fails on the current valid builtin schema. Restrict the query/assertion to the four projections being tested, while still requiring all four expected native indexes, so unrelated registered indexes do not break concurrent-startup acceptance.

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 on 8cabe99af6c59f27b2189479bee87b784c87423a against native OceanBase CE 4.4.2.1: concurrent and repeated FULLTEXT initialization now passes with the full builtin schema, including the unrelated Artifact search index. The assertion still requires all four expected projection indexes. This finding is fixed.

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

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

The existing unquoted VECTOR index recognition and FULLTEXT inventory findings still apply to this head. Please address those existing threads before merging; the earlier DML-only account issue has been fixed.

@hidb4ai hidb4ai removed the 1.5.1 v1.5.1 release tracking label Nov 9, 2026
@AlexStocks AlexStocks added the 1.5.2 v1.5.2 release tracking label Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Update on 8cabe99a: the branch is synchronized with current master, and both outstanding findings are addressed.

  • An existing native VECTOR index is recognized with quoted or unquoted SHOW CREATE TABLE output. The live test now disables sql_quote_show_create on the session, repeats Atomic Memory initialization against the existing index, and restores the original setting.
  • The FULLTEXT inventory assertion is scoped to the four projections under test, so unrelated registered indexes no longer fail the check.

The live startup suite passed 6/6, no skips, against native OceanBase CE 4.4.2.1 (Linux arm64), including concurrent startup, repeated startup, and the unquoted VECTOR regression. The same runtime image also passed the staged Helm and Pod failover acceptance reported in #1609. Main CI is still running; its preflight and documentation checks have passed.

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

Both previously reported findings are fixed on 8cabe99a and passed native OceanBase replay. I am holding approval because Main CI failed in test_model_ingress_authentication_with_real_core_and_provider[enforcing-responses] with httpx.RemoteProtocolError, and dependent upgrade/backend validation was skipped. I have not established that CI failure as a regression introduced by this PR. Please rerun the failed test matrix and dependent validation successfully before merging.

@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 b4b85c7a. The previously reported startup regressions remain fixed, including unquoted native VECTOR definitions and FULLTEXT inventory scope. Native OceanBase replay and repeated Access startup with a DML-only account passed; current PR CI and the selected upgrade checks are green. No blocking findings, new database tables, or public interfaces.

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

@hidb4ai hidb4ai removed the 1.5.2 v1.5.2 release tracking label Nov 15, 2026
@AlexStocks AlexStocks added the 1.6.0 v1.6.0 release tracking label Nov 17, 2026
Preserve native idempotent index creation and bounded authorization retries with the built-in authorization layout and OceanBase vector encoding. Align the evidence-schema test fixture with provisioned tables and refresh the 1.5.2 schema review.

Validated make check, make contract-test, focused startup regressions, seven native OceanBase tests, and two DML-only Access startups.
Retain the idempotent startup changes alongside batched Atomic Memory reads and publication, and refresh the schema review against the merged persistence inputs.

Validated make check, focused persistence regressions, seven native OceanBase startup/search tests, and three native related-pagination tests.

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

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

Rechecked 59f39f813. The startup findings remain fixed and the merge conflicts are resolved. No new code defect, database table, or public interface was found. Current CI still needs successful completion:

  • Linux installation exceeds its 300-second deadline during the initial client installation; dependency resolution and preparation alone took about 290 seconds.
  • SQLite acceptance fails all three trials with AgentSetupTimeoutError after 360 seconds while installing agent dependencies, before task execution.

Those setup paths are unchanged from base 44aded6; these logs do not establish a regression introduced by this PR. Gateway and OpenClaw test steps passed, but their jobs were cancelled during cache-upload cleanup. Please rerun the failed and cancelled checks successfully before merging. Approval of this head is on hold pending that validation.

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

@AlexStocks AlexStocks added 1.6.1 v1.6.1 release tracking and removed 1.6.0 v1.6.0 release tracking labels Nov 24, 2026

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

Confirmed the reported merge conflict for unchanged head 59f39f813 against current master e65423c6: git merge-tree conflicts in release/upgrade-support.json and the OceanBase Atomic Memory, Experience, and Topic Memory index initializers.

The initialization conflicts overlap master's shared ensure_fulltext_index and its bounded 1205 lock-conflict recovery. Please preserve that recovery and the no-DDL path for existing objects while integrating this PR's idempotent DDL and native VECTOR handling, then revalidate concurrent/repeated startup on the merged result.

The previous CI validation request remains unresolved; there has been no newer run. Approval remains on hold pending conflict resolution and successful validation.

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

Rechecked unchanged head 59f39f813 against current master fe9338075. The same four merge conflicts and the previous CI validation request remain unresolved, so approval remains on hold.

Additional validation on real OceanBase CE 4.3.5.4: the concurrent FULLTEXT startup case initially exceeded its 120-second deadline, then passed on an isolated rerun. A paired Experience-initializer check reproduced duplicate-index failures on the base and completed on this head; the timeout therefore does not establish a new PR regression. The real Core/database/model chain also retained generated memory and FTS/vector/hybrid retrieval across app/runtime recreation; this was in-process HTTP coverage, not a separate-process or deployment acceptance test.

Please resolve the conflicts while preserving master's lock-conflict recovery and existing-object no-DDL guards, then validate concurrent startup and CI on the resulting merged commit. Current-head results do not validate that future merge resolution.

@AlexStocks AlexStocks added 1.6.2 v1.6.2 release tracking and removed 1.6.1 v1.6.1 release tracking labels Nov 30, 2026

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.2 v1.6.2 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants