Skip to content

fix(pi): await model discovery before disabling configured chains - #656

Merged
ualtinok merged 8 commits into
cortexkit:masterfrom
randomvariable:fix/pi-model-discovery-readiness
Oct 11, 2026
Merged

ualtinok merged 8 commits into
cortexkit:masterfrom
randomvariable:fix/pi-model-discovery-readiness

Conversation

@randomvariable

@randomvariable randomvariable commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Refs #658

Defer disabled model-chain reports until background provider discovery settles. Preserve correctness across concurrent lifecycle events and configuration/project changes.

Independent of PR #655. Initial standalone verification: typecheck and 53 focused tests. Review concurrency regressions are being addressed.

RetriggerConfidence Score: 5/5

The PR appears safe to merge; both previous findings are fixed and no new blocking issues remain.

Summary

The PR waits for model discovery before reporting configured chains as disabled.

  • Empty model-chain reports wait for provider discovery to finish.
  • Dreamer chains can recognize models added after startup.

Reviews (9) · Last reviewed commit: "style: format the model-chain generation..." · Reviewed by Greptile

@cortexkit-ci

cortexkit-ci Bot commented Oct 10, 2026

Copy link
Copy Markdown

Harness coverage advisory: these conventional twins were not touched:

  • packages/pi-plugin/src/index.ts → packages/plugin/src/index.ts

Cover every shipped harness or explain why the surface does not exist there. See CONTRIBUTING.md. This is advisory only; no draft state is changed.

@cortexkit-ci

cortexkit-ci Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Design gate skipped: the trivial label is applied.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread packages/pi-plugin/src/index.ts Outdated
Comment thread packages/pi-plugin/src/index.ts Outdated
@magic-alfonso

magic-alfonso Bot commented Oct 10, 2026

Copy link
Copy Markdown

Thanks for this, and for the clear description of the startup race.

Before review, please address the two open bot findings. They describe the same gap from two sides:

  • cubic: the refresh wait only guards the first pass, and the re-check then runs with stale state.
  • greptile: the project is added to modelChainReadinessRechecked before its refresh finishes, so a warning can still be issued before discovery completes.

The re-check should be recorded as done only after the awaited refresh has finished, and it should read the model registry fresh at that point. A test that interleaves a second readiness check while the first refresh is still pending would cover both.

Once the findings are resolved, we'll take it through review.

@randomvariable

Copy link
Copy Markdown
Contributor Author

Addressed both discovery race reports in 7ffeeff. Pending refreshes now defer every report; settled callbacks resolve current session/project state and check configuration generation. Three lifecycle regressions cover repeated events, session switching, and configuration replacement. All 12 focused tests, Pi-package typecheck, and build passed. OpenCode has no Pi ModelRegistry API: it receives historian chains from Rust and dispatches via server HTTP, so this registry-readiness defect has no equivalent in packages/plugin/src/index.ts. Refs #658 for maintainer design approval.

Comment thread packages/pi-plugin/src/index.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread packages/pi-plugin/src/index.ts Outdated
@randomvariable

Copy link
Copy Markdown
Contributor Author

Follow-up: deferred reports now require the waiting project to match the active session, preserving the inactive project notice budget. The updated cross-project regression, all 12 focused tests, typecheck and build pass.

@randomvariable

Copy link
Copy Markdown
Contributor Author

Addressed post-refresh rejection handling in 1c423f8. The callback catches configuration-resolution failures and logs a warning. Regression proves no escaping rejection and a subsequent event still reports the settled catalogue. All 13 focused lifecycle tests and Pi typecheck passed.

@magic-alfonso

magic-alfonso Bot commented Oct 10, 2026

Copy link
Copy Markdown

Thanks for the update; the race findings are resolved. One cubic finding is still open, from the new commit: the post-refresh callback (waitForPiModelRegistryRefresh(...).then(...) → reportPiModelChainsAfterRefresh) runs resolveProjectDepsForDir and the live reader poll without error handling. If that throws, the promise rejects unhandled, and because the project is already marked as waited, the missing-model warning is never reported. Wrapping the re-check in the same try/catch reportPiModelChains uses, logging through warn, would resolve it. A test where the deferred re-check throws would cover it.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

View guided diff | Re-trigger cubic

Comment thread packages/pi-plugin/src/index.ts Outdated
@randomvariable

Copy link
Copy Markdown
Contributor Author

Updated in ec989ba: prefer awaitInitialBackgroundRefresh when the host exposes it, which also waits when boot discovery has not started. Retain awaitBackgroundRefresh for older hosts. Regression covers session_start before discovery starts, verifies no premature warning, then hydrates the catalogue and settles discovery. 57 focused tests, typecheck and build pass. @coderabbitai review @greptileai review

@randomvariable

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai @greptile-apps Please review the latest head ec989ba, including the initial-background-discovery readiness change.

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 11, 2026

Copy link
Copy Markdown

@cubic-dev-ai @greptile-apps Please review the latest head ec989ba, including the initial-background-discovery readiness change.

@randomvariable I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread packages/pi-plugin/src/model-chain-health.ts
@ualtinok ualtinok added the trivial Typo-class change; exempt from the design-approved gate label Oct 11, 2026
@ualtinok
ualtinok merged commit a83cd18 into cortexkit:master Oct 11, 2026
17 checks passed
@magic-alfonso

magic-alfonso Bot commented Oct 11, 2026

Copy link
Copy Markdown

Merged, thank you. It passed the full plugin, Pi and CLI suites on current master, and it ships in the next release. The only change on our side was a 2-line formatter fix (55ede24) so the lint gate passes. Issue 658 stays open until the release.

@randomvariable
randomvariable deleted the fix/pi-model-discovery-readiness branch October 11, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

trivial Typo-class change; exempt from the design-approved gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants