Skip to content

fix(register): move _registeredApis.add after successful _initPluginState (Must-Fix #1)#702

Closed
jlin53882 wants to merge 2 commits intoCortexReach:masterfrom
jlin53882:fix/issue-448-v3
Closed

fix(register): move _registeredApis.add after successful _initPluginState (Must-Fix #1)#702
jlin53882 wants to merge 2 commits intoCortexReach:masterfrom
jlin53882:fix/issue-448-v3

Conversation

@jlin53882
Copy link
Copy Markdown
Contributor

Summary

Fixes a P1 registration lifecycle regression in register() where _registeredApis.add(api) was called before _initPluginState(). If _initPluginState threw, the api was already in the WeakSet, permanently blocking any retry from the same api instance.

Fix

Wrap _initPluginState in a try-catch; add api to WeakSet only after successful init. If init fails, the api stays out of the WeakSet, allowing subsequent register() calls with the same api to retry.

let singleton: typeof _singletonState;
try {
  if (!_singletonState) { _singletonState = _initPluginState(api); }
  singleton = _singletonState;
} catch (err) {
  api.logger.error(`memory-lancedb-pro: _initPluginState failed — ${String(err)}`);
  throw err;
}
_registeredApis.add(api);   // ← now only called after successful init

Relationship to PR #522

This PR supersedes the fix/issue-448-v2 branch. PR #522 addressed the isOwnedByAgent derived ownership fix but had an outstanding Must-Fix #1 (registration lifecycle regression). This PR fixes that regression.

File Change
index.ts _registeredApis.add() moved to after successful _initPluginState() with try-catch

Testing

  • TypeScript compilation: passed (index.ts clean; pre-existing error in src/reflection-store.ts unrelated to this change)
  • Existing test suite behavior preserved (singleton is still shared across api instances)

jlin53882 and others added 2 commits April 25, 2026 01:17
…tate

Resolves reviewer Must-Fix #1 from PR CortexReach#522:

- _registeredApis.add(api) was called BEFORE _initPluginState.
  If _initPluginState threw, the api was already in the WeakSet,
  permanently blocking any retry from the same api instance.

- Fix: wrap _initPluginState in try-catch; add api to WeakSet only
  after successful init. If init fails, api stays out of WeakSet,
  allowing subsequent register() calls with the same api to retry.

Fixes CortexReach#448
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

// itemKind 敹???string type嚗???航炊?脣 derived ?嚗ull/undefined/number 蝑?韏?legacy fallback嚗? if (typeof itemKind === "string" && itemKind === "derived") {
if (!owner) return false;
return owner === agentId;
}

P1 Badge Restore executable if for derived ownership branch

The if (typeof itemKind === "string" && itemKind === "derived") token sequence is now inside a // comment, so the following if (!owner) return false;/return owner === agentId; block is no longer guarded and leaves a stray closing brace. In this commit state, src/reflection-store.ts fails to parse (TS1128: Declaration or statement expected), which blocks TypeScript-based builds and any runtime path that loads this module.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jlin53882 jlin53882 closed this Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/lesson命令是自己添加吗 没成功

1 participant