Skip to content

feat(locks): add auto-renewing context - #83

Merged
swkeever merged 3 commits into
mainfrom
skeever/locks-with-lock-context
Sep 3, 2026
Merged

swkeever merged 3 commits into
mainfrom
skeever/locks-with-lock-context

Conversation

@swkeever

@swkeever swkeever commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add an idiomatic with_lock() context manager over the reviewed guard and renewal worker
  • synchronously renew an acquisition that no longer has a safe initial window
  • stop renewal before releasing and preserve context-body exceptions
  • export and document LockGuard lease-loss observation

This is the final integration slice replacing #71; scheduling, guard state, and worker mechanics landed independently.

Verification

  • uv run python scripts/check_openapi.py
  • uv run ruff check .
  • uv run ruff format --check .
  • uv run mypy
  • uv run pyright
  • uv run pytest tests/unit -q
  • uv run behave features/contract --dry-run --no-snippets
  • uv run python -m build
  • Hosting SDK contract unit and shell guards

@swkeever

swkeever commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-03T15:33:21.470310Z 0e1279c Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b99abd5967

ℹ️ 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".

Comment thread src/volcano_sdk/locks.py Outdated
Comment on lines +219 to +220
except (KeyError, TypeError, ValueError, VolcanoError) as error:
release_error = error

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve body errors for every release failure

If cleanup raises an exception outside this narrow tuple, it replaces an already-active exception from the context body, contradicting the documented guarantee that the body exception takes precedence. For example, clearing the client's current service credential makes release() raise RuntimeError from _service_token(), which masks the body's original failure; catch general cleanup exceptions here and suppress them whenever body_failed is true.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in the current head. Cleanup now suppresses any ordinary release exception only when a body or renewal failure already has precedence; otherwise release exceptions still propagate. The regression uses an unexpected RuntimeError from release.

@swkeever

swkeever commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

@swkeever

swkeever commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

@swkeever

swkeever commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2e1fa95bfa

ℹ️ 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".

Comment thread src/volcano_sdk/locks.py
body_failed = False
try:
self._prepare_guard(key, guard, ttl=ttl)
renewer.start()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Propagate every background renewal failure

Once this starts the background renewer, an ordinary exception outside _lock_worker.LockRenewer._renew_once()'s narrow whitelist terminates the thread without marking the guard lost. For example, if _service_token() raises RuntimeError during renewal, guard.lost and wait_lost() do not report the failed renewal until the local lease eventually expires, so protected work may continue after automatic renewal has already stopped; record every ordinary renewal exception on the guard so callers can stop promptly and the context can raise it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in the current head. The worker now records and suppresses any ordinary exception across its full run boundary, while preserving the original exception on the guard. Focused tests cover both request and scheduling failures.

Comment thread src/volcano_sdk/locks.py Outdated
with suppress(Exception):
self.release(key, guard.lease)
else:
self.release(key, guard.lease)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Signal the guard after releasing its lease

When the caller retains the yielded guard or another worker is blocked in guard.wait_lost(), a successful context exit releases the server lease here but leaves the guard reporting lost == False until its old local deadline. Such a worker can therefore continue protected work after this context has relinquished ownership; successful cleanup should transition or close the guard and wake its loss waiters.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in the current head. Context cleanup now closes the guard in a finally block after the release attempt, waking waiters and making retained guards report lost without manufacturing a renewal failure.

@swkeever

swkeever commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 0e1279c344

ℹ️ 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".

@swkeever
swkeever marked this pull request as ready for review September 3, 2026 15:33
@swkeever
swkeever merged commit 413c74d into main Sep 3, 2026
2 checks passed
@swkeever
swkeever deleted the skeever/locks-with-lock-context branch September 3, 2026 15:33
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