Skip to content

fix(harness): close index connections when initialization fails - #3912

Merged
jujn merged 1 commit into
agentscope-ai:mainfrom
pengmoubuaixuexi:fix/harness-index-init-cleanup
Nov 3, 2026
Merged

jujn merged 1 commit into
agentscope-ai:mainfrom
pengmoubuaixuexi:fix/harness-index-init-cleanup

Conversation

@pengmoubuaixuexi

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT, based on main 4399f75fcdc699465733b4a4dc71794c741b92c9.

Description

Closes #3911.

WorkspaceIndex.open() can acquire a SQLite connection and then fail while configuring it or initializing the schema. The factory returns null for the optional-index fallback, but previously left the connection open with no returned index for callers to close. A corrupt .index/workspace.db reproduces this with the real SQLite driver.

Take ownership of the acquired connection before initialization and close the partially initialized index on failure. Preserve the existing best-effort null fallback and keep successful connections open until the returned index is closed. There are no public API or dependency changes.

Add three lifecycle regressions covering failure before connection acquisition, real corrupt-database initialization failure, and successful read/write use followed by explicit closure. The SQLite connections are real; the static JDBC interception only makes the factory's connection observable, following the existing JDBC static-mocking approach in this module. Tests also release the captured connection on assertion failure. Document ownership in Javadoc and both filesystem guides.

Validation

Environment: Windows, Temurin 17.0.15, Maven 3.9.12, SQLite JDBC 3.47.1.0. No external providers or services.

  • Before the production fix: two new lifecycle cases plus five existing prefix cases ran; 7 tests, 1 failure, 0 errors. The corrupt-database case observed open() == null but connection.isClosed() == false. The normal-open control passed.
  • After the fix: all three new lifecycle cases plus the existing prefix cases passed: 8 tests, 0 failures/errors/skips.
  • Build the same checkout's reactor dependencies: mvn -B -T1C -pl :agentscope-harness -am -DskipTests clean install (dependency build; tests intentionally skipped in this command).
  • Complete affected-module check: mvn -B -T1C -pl :agentscope-harness clean verify — 1,594 tests, 0 failures, 0 errors, 37 skipped (1,557 passed), BUILD SUCCESS. This includes Spotless, packaging and Javadoc. The full-repository test suite was not run.
  • git diff --check passed.
  • Docs: npm test — 13 passed; npm run validate — passed.
  • npm run broken-links exits nonzero on the existing documentation baseline. Modified and original HEAD documents both report 2,222 links in 328 files; comparing the file/target multisets gives no additions or removals. The two documents were restored after the baseline comparison.

The first dependency install encountered an old Maven compiler cache encoding error after switching to UTF-8; a clean build with process-local JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8 resolved it. No global environment settings or unrelated code were changed.

Checklist

  • Code has been checked with Spotless.
  • Regression and complete affected-module tests pass within the validation scope above.
  • Javadoc describes connection ownership on failure and success.
  • Matching English and Chinese documentation is updated.
  • The complete diff has been inspected and is ready for review.

AI assistance: Codex assisted with source investigation, implementation, regression tests and documentation. The stated checks were executed locally and the full staged diff was inspected.

Copilot AI balanced review requested due to automatic review settings November 1, 2026 05:25
@mintlify

mintlify Bot commented Nov 1, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit f9403d8.

Approve preview

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@ningmao-hlyz

Copy link
Copy Markdown
Contributor

Two things worth having in the body: WorkspaceIndex.close() swallows SQLException, so closing from the catch cannot turn the null fallback into a throw; and the ownership chain is already complete (HarnessAgent.ownedWorkspaceIndex, WorkspaceManager.ownsIndex), which makes the documentation sentence accurate rather than aspirational. SqliteSessionStorage does the same close-on-failure dance, so there is an in-repo precedent worth citing.

@ningmao-hlyz

Copy link
Copy Markdown
Contributor

LGTM

@jujn
jujn merged commit 2b4a1cb into agentscope-ai:main Nov 3, 2026
7 checks passed
chickenlj pushed a commit that referenced this pull request Nov 13, 2026
Backport the verified fix to the 2.0.x implementation and retain its existing public contracts where the upstream kernel differs.

(cherry picked from commit 2b4a1cb)
Backport-review-patch: cc572eb4fc97c9d5de1ed07c30c6e1d5272e8b10
Constraint: No AgentScope Service or SDK migration
Confidence: high
Not-tested: Whole-repository verification pending after lane integration
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.

[Bug]: WorkspaceIndex leaks its SQLite connection when initialization fails

4 participants