-
Notifications
You must be signed in to change notification settings - Fork 0
fix(obsidian): make wiki sync direct and observable #2037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,21 +1,37 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||||||||||||||
| # Trigger obsidian-git's commitAndSync via CDP. | ||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||
| # The Electron renderer's setTimeout doesn't fire under headless xvfb | ||||||||||||||||||||||||||||||||||||||||||||||
| # (futex_wait_queue blocks the event loop pump), but CDP messages use | ||||||||||||||||||||||||||||||||||||||||||||||
| # IPC and bypass the stuck loop. We trigger the backup and keep the | ||||||||||||||||||||||||||||||||||||||||||||||
| # websocket open with ping-interval for 15s to pump the event loop | ||||||||||||||||||||||||||||||||||||||||||||||
| # while git operations complete through the obsidian-git plugin. | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| CDP="http://localhost:9222" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| WS_URL=$(@curl@/bin/curl -sf "$CDP/json" | @jq@/bin/jq -r '.[0].webSocketDebuggerUrl // empty') | ||||||||||||||||||||||||||||||||||||||||||||||
| [ -z "$WS_URL" ] && exit 0 | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # Send trigger, then keep stdin open for 15s so websocat stays alive. | ||||||||||||||||||||||||||||||||||||||||||||||
| # The --ping-interval sends websocket pings that pump the Electron | ||||||||||||||||||||||||||||||||||||||||||||||
| # event loop, allowing the obsidian-git promise queue to execute. | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| echo '{"id":1,"method":"Runtime.evaluate","params":{"expression":"app.plugins.plugins['"'"'obsidian-git'"'"']?.automaticsManager?.doAutoCommitAndSync()"}}' | ||||||||||||||||||||||||||||||||||||||||||||||
| sleep 15 | ||||||||||||||||||||||||||||||||||||||||||||||
| } | @websocat@/bin/websocat --ping-interval 1 "$WS_URL" >/dev/null 2>&1 || true | ||||||||||||||||||||||||||||||||||||||||||||||
| # Commit, rebase, and push the memory wiki without depending on Obsidian's | ||||||||||||||||||||||||||||||||||||||||||||||
| # headless renderer or the obsidian-git community plugin. | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| VAULT="@vaultDir@" | ||||||||||||||||||||||||||||||||||||||||||||||
| GIT="@git@/bin/git" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if ! "$GIT" -C "$VAULT" rev-parse --is-inside-work-tree >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||||||||||
| echo "wiki-git-sync: vault is not a Git checkout: $VAULT" >&2 | ||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| BRANCH=$("$GIT" -C "$VAULT" symbolic-ref --short HEAD) | ||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With Prompt for Agent
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: With BRANCH=$("$GIT" -C "$VAULT" symbolic-ref --short HEAD 2>/dev/null) || {
echo "wiki-git-sync: HEAD is detached or unborn in: $VAULT" >&2
exit 1
}This preserves clear diagnostics for operators debugging unattended failures. Prompt for AI agentsThis preserves clear diagnostics for operators debugging unattended failures. @@ -1,21 +1,37 @@ + exit 1 +fi + +BRANCH=$("$GIT" -C "$VAULT" symbolic-ref --short HEAD) +if [ "$BRANCH" != "main" ]; then + echo "wiki-git-sync: expected main branch, found $BRANCH" >&2 ```
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| if [ "$BRANCH" != "main" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||
| echo "wiki-git-sync: expected main branch, found $BRANCH" >&2 | ||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+15
to
+19
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the repository is in a detached HEAD state,
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| exec 9>"$VAULT/.git/wiki-sync.lock" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The lock file path assumes Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| if ! @utilLinux@/bin/flock -n 9; then | ||||||||||||||||||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a hardcoded path of
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| "$GIT" -C "$VAULT" add -A | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if ! "$GIT" -C "$VAULT" diff --cached --quiet; then | ||||||||||||||||||||||||||||||||||||||||||||||
| "$GIT" -C "$VAULT" -c commit.gpgsign=false commit -m "vault backup: $(@coreutils@/bin/date -u '+%Y-%m-%d %H:%M:%S UTC')" | ||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disabling GPG signing removes commit provenance guarantees. While pragmatic for unattended commits, this weakens the security model. Consider documenting this tradeoff in comments and implementing compensating controls such as: restrictive repository access permissions, signed tags for releases, or downstream CI verification of commit integrity. Prompt for Agent |
||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| "$GIT" -C "$VAULT" fetch origin main | ||||||||||||||||||||||||||||||||||||||||||||||
| "$GIT" -C "$VAULT" rebase origin/main | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+32
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this script runs unattended as a systemd timer, any merge conflict during
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rebase conflict permanently wedges the sync. With Since this rewrite is specifically about unattended durability, please self-heal here. Options:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A rebase conflict will leave the repository in Prompt for Agent
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Rebase failure leaves vault stuck in mid-rebase state. If Aborting the rebase on failure keeps the vault recoverable and makes the next run retry cleanly. 🔒 Proposed fix: abort rebase on failure "$GIT" -C "$VAULT" fetch origin main
-"$GIT" -C "$VAULT" rebase origin/main
+"$GIT" -C "$VAULT" rebase origin/main || {
+ "$GIT" -C "$VAULT" rebase --abort
+ echo "wiki-git-sync: rebase failed, conflicts aborted" >&2
+ exit 1
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: A rebase conflict will exit non-zero (due to Since this script's purpose is unattended durability, consider aborting the rebase on failure so the repo is always left in a clean state: if ! "$GIT" -C "$VAULT" rebase origin/main; then
echo "wiki-git-sync: rebase conflict, aborting to restore clean state" >&2
"$GIT" -C "$VAULT" rebase --abort || true
exit 1
fiOptionally, detect and clean up a leftover rebase state at script start as well. Prompt for AI agentsOptionally, detect and clean up a leftover rebase state at script start as well. @@ -1,21 +1,37 @@ +fi + +"$GIT" -C "$VAULT" fetch origin main +"$GIT" -C "$VAULT" rebase origin/main + +if [ "$("$GIT" -C "$VAULT" rev-parse HEAD)" != "$("$GIT" -C "$VAULT" rev-parse origin/main)" ]; then ```
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if [ "$("$GIT" -C "$VAULT" rev-parse HEAD)" != "$("$GIT" -C "$VAULT" rev-parse origin/main)" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||
| "$GIT" -C "$VAULT" push origin HEAD:main | ||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching from
unsafe-localtobridgemode is a strong architectural improvement. However, ensure there's a migration path if any consumers still expectunsafeLocalconfiguration keys. Consider documenting bridge mode prerequisites (what produces the artifacts/events) to prevent silent indexing gaps during rollout.Prompt for Agent