add shared context lock

This commit is contained in:
Oskar Kapala 2026-05-05 17:25:50 +02:00
parent 4834f0ad9d
commit 041047601a
3 changed files with 62 additions and 2 deletions

View file

@ -6,6 +6,29 @@ This repository documents the current known state of the homelab.
The documentation is based only on stated facts. Missing details are recorded as unknowns and need clarification. The documentation is based only on stated facts. Missing details are recorded as unknowns and need clarification.
## Shared context sync lock
`sync-context.sh` uses a git-tracked `.context.lock` file to serialize updates to `codex_context.yaml`.
If `codex_context.yaml` has changes, the script:
1. pulls with rebase
2. aborts if `.context.lock` already exists and prints its contents
3. creates `.context.lock` with `hostname`, `username`, and UTC `timestamp`
4. commits and pushes the lock with message `lock shared context`
5. validates `codex_context.yaml`, commits it, and pushes
6. removes `.context.lock`, commits `unlock shared context`, and pushes
If any step fails after lock creation, the script prints `Lock may need manual cleanup` and leaves the lock in place.
Manual cleanup:
1. inspect `.context.lock`
2. confirm the owning host/user is no longer updating context
3. remove the file
4. commit `unlock shared context`
5. push
## Current configuration ## Current configuration
- Main server hardware: Raspberry Pi 5 - Main server hardware: Raspberry Pi 5

View file

@ -2,9 +2,9 @@ SESSION_STATE:
meta: meta:
goal: "Maintain compressed lossless session memory in ./codex_context.yaml" goal: "Maintain compressed lossless session memory in ./codex_context.yaml"
environment: environment:
cwd: "/home/oskar/projects/homelab-codex-ws" cwd: "/home/oskar/homelab-codex-ws"
shell: "zsh" shell: "zsh"
date: "2026-05-03" date: "2026-05-05"
tz: "Europe/Warsaw" tz: "Europe/Warsaw"
systems: systems:
S1: S1:
@ -100,6 +100,9 @@ SESSION_STATE:
D40: "Created ./start-aider.sh and ./update-context.md on 2026-05-03. start-aider.sh runs from repo root, defaults OLLAMA_API_BASE to http://100.100.231.104:11434, uses model ollama/deepseek-coder:latest, and attaches ./codex_context.yaml via aider --read after confirming read-only support from local aider help. update-context.md documents shared context rules for Codex and Aider; scripts set executable." D40: "Created ./start-aider.sh and ./update-context.md on 2026-05-03. start-aider.sh runs from repo root, defaults OLLAMA_API_BASE to http://100.100.231.104:11434, uses model ollama/deepseek-coder:latest, and attaches ./codex_context.yaml via aider --read after confirming read-only support from local aider help. update-context.md documents shared context rules for Codex and Aider; scripts set executable."
D41: "Startup 2026-05-03: read existing ./codex_context.yaml before task work, verified parity with user-provided SESSION_STATE, retained state, overwrote file." D41: "Startup 2026-05-03: read existing ./codex_context.yaml before task work, verified parity with user-provided SESSION_STATE, retained state, overwrote file."
D42: "Aider is installed as a local coding assistant, but current local Ollama models are not reliable enough for context-file editing." D42: "Aider is installed as a local coding assistant, but current local Ollama models are not reliable enough for context-file editing."
D43: "Startup 2026-05-05: read existing ./codex_context.yaml before task work, verified parity with user-provided SESSION_STATE, observed clean re-cloned repo on branch master, refreshed meta.environment for current workspace."
D44: "Updated ./sync-context.sh on 2026-05-05 to use git-tracked ./.context.lock around codex_context.yaml sync: abort and print lock contents if present; on context changes create lock with hostname/username/UTC timestamp, commit/push lock, validate YAML, commit/push context, then remove lock and commit/push unlock; failures after lock creation print 'Lock may need manual cleanup' and leave lock in place; no auto-merge conflict resolution."
D45: "Updated ./README.md on 2026-05-05 with shared context lock flow and manual .context.lock cleanup procedure."
todos: todos:
T1: "For all future meaningful changes/decisions, update and overwrite ./codex_context.yaml." T1: "For all future meaningful changes/decisions, update and overwrite ./codex_context.yaml."
T2: "DONE: Commit current changes." T2: "DONE: Commit current changes."
@ -125,6 +128,7 @@ SESSION_STATE:
T22: "DONE: Retry Aider setup on remaining hosts using corrected SSH targets pi@piha and ubuntu-4gb-hel1-1; both verified at aider 0.86.2." T22: "DONE: Retry Aider setup on remaining hosts using corrected SSH targets pi@piha and ubuntu-4gb-hel1-1; both verified at aider 0.86.2."
T23: "DONE: Add shared Codex/Aider context bootstrap scripts and update-context protocol doc." T23: "DONE: Add shared Codex/Aider context bootstrap scripts and update-context protocol doc."
T24: "Use Codex for codex_context.yaml updates; use Aider only for simple code edits until a better local model/edit format is validated." T24: "Use Codex for codex_context.yaml updates; use Aider only for simple code edits until a better local model/edit format is validated."
T25: "DONE: Add safe git-tracked shared context lock to sync-context.sh and document manual cleanup."
issues: issues:
I1: "Tailscale DNS health warning: configured DNS servers unreachable." I1: "Tailscale DNS health warning: configured DNS servers unreachable."
I2: "Preferred gateway path unavailable: 100.108.208.3:8080 connection failed." I2: "Preferred gateway path unavailable: 100.108.208.3:8080 connection failed."

View file

@ -3,6 +3,7 @@
set -euo pipefail set -euo pipefail
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)" REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
LOCK_FILE=".context.lock"
if [[ -z "$REPO_ROOT" ]]; then if [[ -z "$REPO_ROOT" ]]; then
echo "Not inside a git repository" >&2 echo "Not inside a git repository" >&2
@ -31,7 +32,39 @@ if git diff --quiet -- codex_context.yaml && git diff --cached --quiet -- codex_
exit 0 exit 0
fi fi
if [[ -e "$LOCK_FILE" ]]; then
echo "Shared context is locked:" >&2
cat "$LOCK_FILE" >&2
exit 1
fi
lock_created=0
cleanup_note() {
if [[ "$lock_created" -eq 1 ]]; then
echo "Lock may need manual cleanup" >&2
fi
}
trap cleanup_note ERR
printf "hostname: %s\nusername: %s\ntimestamp: %s\n" \
"$(hostname)" \
"$(id -un)" \
"$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
> "$LOCK_FILE"
lock_created=1
git add "$LOCK_FILE"
git commit -m "lock shared context"
git push
python3 -c "import yaml; yaml.safe_load(open('codex_context.yaml'))" python3 -c "import yaml; yaml.safe_load(open('codex_context.yaml'))"
git add codex_context.yaml git add codex_context.yaml
git commit -m "update shared context" git commit -m "update shared context"
git push git push
rm -f "$LOCK_FILE"
git add "$LOCK_FILE"
git commit -m "unlock shared context"
git push
trap - ERR