Skip to content

fix(pm-stack backup): pmp_links source resolution + both offsite legs (#7096) - #7363

Merged
dezren39 merged 2 commits into
mainfrom
queue/12738-7096-pmp-links-backup-source
Nov 8, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/12738-7096-pmp-links-backup-source

Conversation

@dezren39

@dezren39 dezren39 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Fixes #7096 — bounded follow-up to the unresolved review findings on merged PR #5315. Needed for issue #1744 criterion 3 (pmp_links recoverable from the archive).

What changed (nixos/home/pm-dashboard-backup.sh)

  • Last assignment wins. DATABASE_URL is taken from the last matching env-file line (optionally export -prefixed, spaces around =), because a later assignment is what the service actually loads.
  • Edge-only value trimming. One trailing CR, edge whitespace and a single matching quote pair are stripped; interior characters (spaces, quotes) survive. The previous tr -d deleted every quote and space anywhere in the value and mangled paths with spaces.
  • file: URLs decoded. Percent escapes are decoded and file:/// / file://localhost/ authorities collapsed before the existence check, so file:/a%20b/projector.db finds the real file.
  • No silent local fallback for remote DSNs. A non-file DATABASE_URL (postgres://, libsql://, ...) fails the run with a pmp_links error naming only the scheme — never the DSN, which may embed credentials. Archiving a stale local DB instead would make the backup evidence claim a source it never read.
  • PM_PROJECTOR_DIR resolution. With no configured source, <PM_PROJECTOR_DIR>/projector.db is used before the ~/.local/state/pm-projector fallback; a relative value resolves under PM_PROJECTOR_DIR. Bare local paths in DATABASE_URL are now honoured instead of being ignored.

Tests (nixos/home/pm-dashboard-backup-pmp-links.test.sh)

  • with-db passes only when the stub log records copyto to both R2 and Drive for the same archive (previously any single upload passed).
  • New scenarios: env-last (stale first assignment must not win), env-quoted (quoted, CR-terminated, percent-encoded path containing a space), env-remote (explicit failure, nothing uploaded, cursor unchanged, DSN not leaked), env-relative + projector-dir (relative/default resolution under PM_PROJECTOR_DIR before the state fallback).
  • PM_PROJECTOR_* are cleared per scenario so ambient values cannot pick the source.

Verification

  • bash nixos/home/pm-dashboard-backup-pmp-links.test.sh — all passed (21 checks)
  • bash nixos/home/pm-dashboard-backup-manifest.test.sh — all passed
  • also green locally: copy, date, prune, record, base pm-dashboard-backup.test.sh

No export re-implementation, no data/service migration; scope is only source resolution and the offsite-leg assertion.

Queue task 12738 (lane 7b47536b, worker repo-worker-code).


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…t both offsite legs

The pmp_links export added by #5315 still had unresolved review gaps
(code#7096):

- DATABASE_URL is read from the LAST matching env-file assignment (a
  later line is what the service loads), with CR, edge whitespace and one
  matching quote pair trimmed. The old tr deleted every quote/space in
  the value, mangling paths with spaces.
- file: URL paths are percent-decoded and file:/// and file://localhost/
  authorities stripped before the existence check.
- An unsupported non-file DATABASE_URL (postgres://, libsql://, ...)
  now fails the run instead of silently archiving a stale local DB; the
  failure names only the scheme, never the DSN (it may embed credentials).
- With no configured source, <PM_PROJECTOR_DIR>/projector.db is used
  before the ~/.local/state/pm-projector fallback; a relative value
  resolves under PM_PROJECTOR_DIR.
- The with-db scenario now passes only when the stub log records copyto
  to BOTH R2 and Drive for the same archive, plus new scenarios for
  last-assignment, quoted/CR/percent-encoded values, remote-DSN
  rejection, and relative/PM_PROJECTOR_DIR resolution.

Refs #7096, #1744
@dezren39
dezren39 requested a review from a team as a code owner November 8, 2026 06:45
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 54 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b440d9c3-6b4d-4953-8eb8-033217f38d50
Commits

Reviewing files that changed from the base of the PR and between ae08110 and afda12d.

Files selected for processing: 2

  • nixos/home/pm-dashboard-backup-pmp-links.test.sh
  • nixos/home/pm-dashboard-backup.sh
  • Autofix · 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T08:51:09.345548Z afda12d New commits
ℹ️ 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: 4f1908fc6b

ℹ️ 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 nixos/home/pm-dashboard-backup.sh Outdated
Comment on lines +468 to +469
if [ -n "$PMP_DIR" ] && [ -f "$PMP_DIR/projector.db" ]; then
PMP_DB="$PMP_DIR/projector.db"

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 Resolve the projector default under its data directory

When DATABASE_URL is absent and PM_PROJECTOR_DIR points to the projector's working directory, this selects the wrong default database. The projector defaults to file:data/projector.db (pm-stack/projector/src/store.ts:13-15), not file:projector.db; the deployed working directory is set in nixos/services/pm-stack/default.nix:115. If an older projector.db exists at the directory root, this new branch exports its stale links and reports a successful backup instead of preserving the active database's links. Resolve the default to data/projector.db and update the new projector-dir fixture accordingly.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in afda12d: the no-DATABASE_URL default under PM_PROJECTOR_DIR now resolves data/projector.db (the projector default file:data/projector.db in pm-stack/projector/src/store.ts, relative to its working directory). A root-level projector.db is never picked. The projector-dir fixture now puts the active DB at data/projector.db and adds a stale root projector.db, asserting neither it nor the state-dir DB is exported.

//localhost/*) PMP_DB="/${PMP_DB#//localhost/}" ;;
///*) PMP_DB="/${PMP_DB#///}" ;;
esac
PMP_DB="$(pmp_url_decode "$PMP_DB")"

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 URI escaping when opening the decoded database path

For a configured URL such as file:/path/projector%3Fprod.db, decoding produces the correct filesystem path for the existence check, but the subsequent SQLite calls interpolate it into file:$PMP_DB?mode=ro again. The decoded ? becomes query syntax, so SQLite opens /path/projector instead of /path/projector?prod.db; encoded # and percent escapes have similar problems. Consequently, these newly supported URLs can fail the entire backup or export a different database. Re-escape the resolved path before constructing the SQLite URI, or pass the decoded filename with SQLite's documented -readonly option (sqlite3 --help: “open the database read-only”).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in afda12d: the export no longer interpolates the decoded path into a file:...?mode=ro URI. All three SQLite calls now use sqlite3 -readonly with the decoded path as a plain filename, so a literal ? or # in the name stays a filename character. New env-encoded-q test case: DATABASE_URL=file:...projector%3Fprod.db exports the real projector?prod.db file; the full pmp-links suite passes.

…DB read-only by path

Codex review on PR #7363, two P2 findings: (1) the projector default is file:data/projector.db relative to its working directory (pm-stack/projector/src/store.ts), so the PM_PROJECTOR_DIR fallback now resolves data/projector.db and never a stale root projector.db; the projector-dir fixture now covers the stale-root case. (2) A percent-decoded path containing ? or # broke when re-interpolated into a file:...?mode=ro SQLite URI; the export now opens the decoded path with sqlite3 -readonly instead. New env-encoded-q case covers a literal ? filename. Targeted suites pass: pm-dashboard-backup-pmp-links.test.sh, pm-dashboard-backup-manifest.test.sh.
@dezren39
dezren39 merged commit 35390d3 into main Nov 8, 2026
3 of 5 checks passed
@dezren39
dezren39 deleted the queue/12738-7096-pmp-links-backup-source branch November 8, 2026 08:50
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.

fix(pm-stack backup): pmp_links backup source resolution and offsite assertions (#5315 follow-up)

1 participant