Skip to content

fix(state/redis): round sub-millisecond ExtendLock TTL up to 1 ms - #130

Merged
ThomasK33 merged 3 commits into
mainfrom
fix/redis-extendlock-submillisecond
Oct 29, 2026
Merged

ThomasK33 merged 3 commits into
mainfrom
fix/redis-extendlock-submillisecond

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Why

The operator goal is one small, reviewed PR for every open follow-up issue in coder/chat. This one fixes the Redis state: ExtendLock with a positive TTL under 1 ms sent PEXPIRE 0, Redis deleted the lock, and ExtendLock still returned true. The fix rounds that TTL up to 1 ms, as go-redis already does for SetNX.

Closes #125

What changed

  • ExtendLock sends at least 1 ms to the extend script.
  • A new test extends a held lock by 500 µs, then checks that the key still exists and that a second AcquireLock fails.
  • state/redis/README.md now describes the rounding instead of the bug.

Scope

  • Only the Redis backend. The other backends keep a positive TTL already, per the issue.
  • MarkEvent and AcquireLock need no change. They call go-redis SetNX, which rounds a positive TTL under 1 ms up to 1 ms.

Blast Radius

Only callers that pass a TTL under 1 ms see a change. They now keep the lock for 1 ms instead of losing it.

Verification

  • The new test failed before the fix with "lock key was deleted by ExtendLock" and passes after it.
  • On redis:7.2-alpine (testcontainers, throwaway test), ExtendLock by 500 µs left EXISTS=0 before the fix. After the fix it left EXISTS=1 and PTTL=1ms, and a second token could not take the lock.
  • go vet and go test pass in every module, go test -race passes in state/redis, and gofmt -l prints nothing.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

ExtendLock with a positive TTL under 1 ms deletes the lock and still
returns true. This test fails until the fix lands. Refs #125.
ExtendLock sent ttl.Milliseconds() to PEXPIRE. A positive TTL under
1 ms became 0, Redis deleted the lock, and ExtendLock still returned
true. Round it up to 1 ms, as go-redis does on its SetNX path, and
update the README contract.

MarkEvent and AcquireLock already get this rounding from go-redis
SetNX.
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 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-10-29T20:58:13.284088Z 2874b46 Manual request
🔒 Security Review ✅ Completed 2026-10-29T20:58:30.731043Z 2874b46 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: e6f8c6829c

ℹ️ 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 state/redis/README.md Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: e6f8c6829c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

A round-to-nearest fix passes the 500 µs case but still sends 0 for
1 ns. Write the extend ARGV in the README as two values.
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 2874b46cec

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

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 2874b46cec

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 merged commit fa4cd70 into main Oct 29, 2026
2 checks passed
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.

state/redis: ExtendLock with a TTL under 1 ms deletes the lock and returns true

1 participant