Skip to content

fix(acquire): keep the lease's role for the same database - #51

Merged
simoncrypta merged 1 commit into
mainfrom
fix/keep-lease-role
Oct 8, 2026
Merged

simoncrypta merged 1 commit into
mainfrom
fix/keep-lease-role

Conversation

@simoncrypta

Copy link
Copy Markdown
Collaborator

Beads: cedar-pg-n8i

Problem

acquire derived the role name on every call (src/core/lifecycle.ts). After #44 changed role naming for long worktree names, any existing dev database whose name exceeds 58 characters now maps to a new role. ensureDatabase then hands the database to that role, while the tables inside stay owned by the old one, so the app gets permission denied on its own dev data. The rewritten lease also drops the old role, which is left orphaned. The CHANGELOG claim "existing leases keep their stored role" only held until the next acquire.

Fix

I picked lease reuse over REASSIGN OWNED, as the bead asked. It's a two-line change in the canonical layer and needs no per-database connection.

Tests

  • New tests/lifecycle-acquire.test.ts (mocked host and provider) covers three cases:
    • an existing lease with the old cut role for the same 63-char database: acquire keeps that role for ensureDatabase, fresh and the lease;
    • a lease for a different database: the derived role is used;
    • no lease: the derived role is used.
  • The first case fails without the fix and passes with it.
  • Live check, run once by hand, not in CI: an owned throwaway autopg postmaster on a temp port and data dir (never the shared host), with a stub AUTOPG_BIN reporting that port, drove the built acquire.
    • Seeded lease with the old role: the role is kept and the seeded row reads back.
    • Lease removed: the derived role gets 42501 permission denied for table t. That is the pre-fix failure.
  • smoke:pg does not cover this upgrade path.

Checks

  • vp check: pass
  • vp test: 22 files, 138 tests pass
  • vp run smoke:pg: pass

🤖 Generated with Claude Code

acquire derived the role name on every call. After #44 changed role naming
for long worktree names, an existing long-named dev database mapped to a new
role: ensureDatabase handed the database to it while its tables stayed owned
by the old role (permission denied), and the rewritten lease lost the old one.

acquire now reuses the role stored in an existing lease when that lease is
for the same database (fresh drops by it too); new databases keep the new
naming. CHANGELOG corrected to describe the real behaviour.

Refs: cedar-pg-n8i

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 28cc23ed-c85b-47ab-90fc-5de059126613
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cedarjs/pg@51

commit: 3840edd

@simoncrypta
simoncrypta merged commit 0c3943c into main Oct 8, 2026
4 checks passed
@simoncrypta
simoncrypta deleted the fix/keep-lease-role branch October 8, 2026 17:00
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