Skip to content

Temp/reserve imap connecteon for operation - #99

Closed
dbezverkhnii wants to merge 9 commits into
spark2from
temp/reserve-imap-connecteon-for-operation
Closed

Temp/reserve imap connecteon for operation#99
dbezverkhnii wants to merge 9 commits into
spark2from
temp/reserve-imap-connecteon-for-operation

Conversation

@dbezverkhnii

@dbezverkhnii dbezverkhnii commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Note

High Risk
Changes core IMAP connection pooling, reservation, and stream cancellation semantics used by Spark; Windows consumers need a new prebuilt for any C/C++ digest change or builds fail at download time.

Overview
Adds exclusive IMAP connection leases so callers can reserve a pool connection, pin operations to it (setConnection / setSession), and return it with optional disconnect. Reserved connections are skipped by normal session selection; idle auto-disconnect is configurable (automaticDisconnectDelay) and paused while leased. interruptCurrentCommand() aborts the currently running operation’s blocked IMAP read via OperationQueue::interruptRunningOperation and mailstream_cancel, with matching C/Swift APIs (MCOIMAPAsyncConnection, acquireConnection / releaseConnection). Darwin unit tests cover leasing, pinning, exhaustion, and interrupt behavior.

Separately, Windows MailCore prebuilts move from numbered S3 zips to mailcore2-all-<digest>.zip on GitHub releases (windows-prebuilt), where the digest hashes committed C/C++ inputs plus windows-build-pins.json. Publish-Mailcore2Prebuilt.ps1 builds, verifies, and uploads; Get-Mailcore2.ps1 downloads publicly and validates the stamped digest (-LegacyS3Version keeps the old path). Build-Helpers.ps1 and a bundled dependency archive reduce reliance on internal RD modules, AWS keys, and fixed C:\Library paths. Docs (README, AGENTS.md) describe the new publish flow.

Reviewed by Cursor Bugbot for commit 3ded97b. Bugbot is set up for automated code reviews on this repo. Configure here.

dbezverkhnii and others added 9 commits August 31, 2026 19:26
Idle timer stands down while a connection is reserved and is re-armed by
releaseConnection; releaseConnection is idempotent and owner-checked;
selection no longer stamps the affinity hint on reserved connections;
threading contract documented; test endpoint descriptor lifecycle fixed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Bridges the existing IMAPAsyncConnection::disconnectOperation() to C and
Swift so a lease holder can tear its socket down before commands whose
freshness matters: the next command logs in from scratch and sees the
server's current mailbox view.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The installed header set was self-inconsistent: CIMAPAsyncSession.h,
CIMAPBaseOperation.h and CCore.h include CIMAPAsyncConnection.h, but the
CMake install list did not carry it. Also rights the leaked-lease wording
in the Swift docs: the pool degrades to sharing, it does not shrink.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Swift-only: exposes the underlying pool connection's pointer as an opaque
identity, unique and constant for the owning session's lifetime, so the
client can key per-connection bookkeeping (view-freshness generations)
across separate acquisitions of the same connection.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The mailcore2-all-<N>.zip archives for the Windows build are stored as
release assets of this repository instead of the S3 bucket; upload and
verification instructions now go through gh release.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Build-Helpers.ps1 provides minimal stand-ins for RDBuildCMake/RDBuildMSVC/
RDDependency and is dot-sourced only when those modules are absent, so a plain
clone of the public repository builds with just the Swift toolchain and VS Build
Tools. Dependencies are cloned over https instead of ssh, and one optional
-PrebuiltDependenciesArchive supplies ICU, libxml2, openssl, sasl and zlib,
replacing the S3 downloads and the manual C:\Library layout.

Also installs the ICU and Swift runtime DLLs the artifact needs, fixes the tidy
include/lib paths, and adds MCIMAPAsyncConnection.h to the C++ public headers -
the C++ half of the header-install fix in 00e17d8.

Authored on Windows by the build agent; carried over verbatim except for
comments and the header-list fix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…n COR-180

The archive is now named after the C/C++ sources it was built from
(mailcore2-all-<digest>.zip), so there is no version to bump and no way to
silently consume a stale binary: sources that were never built have no archive,
and the spark-core build stops with a message naming the missing one. Since
there is no Windows CI, that build is where the omission surfaces.

The digest covers src minus src/swift, CMakeLists.txt and the new
windows-build-pins.json (exact dependency revisions and toolchain versions), and
is computed from git's tree entries, which makes it identical across platforms
regardless of core.autocrlf. Build scripts are deliberately outside it: editing
them must not invalidate good binaries.

Publish-Mailcore2Prebuilt.ps1 does the whole job in one call - digest, skip if
already published, toolchain check, build, stamp, package, verify, upload - and
nothing needs to be committed afterwards. Downloads need no credentials now that
the repository is public; the S3 path survives behind -LegacyS3Version for tags
published before this change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3ded97b. Configure here.

New-Item -ItemType Directory -Path $Path -Force | Out-Null
foreach ($dependency in $Dependencies) {
$destination = Join-Path $Path $dependency.Directory
if (Test-Path -LiteralPath (Join-Path $destination ".git")) { continue }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale deps ignore pin updates

High Severity

Initialize-Dependencies treats any existing .git directory as ready and never re-checks HEAD against the pinned GitRevision. Publish-Mailcore2Prebuilt.ps1 reuses .build\prebuilt\build-dependencies across runs, so a later publish after a pin change still builds ctemplate, libetpan, and tidy from the old checkout while naming the archive after the new digest.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3ded97b. Configure here.

$swiftRoot = Join-Path $env:LOCALAPPDATA "Programs\Swift"
$swiftBin = Get-ChildItem -LiteralPath (Join-Path $swiftRoot "Toolchains") -Filter clang-cl.exe -Recurse -File |
Select-Object -First 1 -ExpandProperty DirectoryName
if (-not $swiftBin) { throw "Swift clang-cl.exe not found under $swiftRoot" }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wrong Swift compiler can be used

Medium Severity

Initialize-Toolchain puts the first clang-cl.exe it finds under the Swift toolchains directory on PATH, and does not select the version from windows-build-pins.json. Publish-Mailcore2Prebuilt.ps1 only checks that the pinned Swift platform folder exists, so a machine with multiple Swift installs can compile the prebuilt with a different clang than the digest claims.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3ded97b. Configure here.

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.

1 participant