fix(agentworker): reconcile task clone ownership after commits

This commit is contained in:
sam committed 2026-08-25 03:28:40 +10:00
1 parent 77b1eaa2df
commit 694a977ffe
4 files changed
+41 -7

No files matched your search

+4
View File
@@ -127,3 +127,7 @@
{"id":"int-bc45db099eb63b2e22f27449984fd770","kind":"field_change","created_at":"2026-08-24T15:42:47.277649102Z","actor":"Sam Catlow","issue_id":"archie-core-0dic","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Closed"}}
{"id":"int-6ef69a7ebb781fb99529e52ef038cdaf","kind":"field_change","created_at":"2026-08-24T15:43:19.639842603Z","actor":"Sam Catlow","issue_id":"archie-core-absb","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"send_file tool plus upload-by-reader delivery; commit 9a45fbb"}}
{"id":"int-fd47d92bec50df8b1766cccc3d17ca82","kind":"field_change","created_at":"2026-08-24T17:00:21.332713238Z","actor":"Sam Catlow","issue_id":"archie-core-b7f1","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Implemented UUIDv7 identities, replayable archived chat tool activity, and post-start update report delivery; full quality gate passes."}}
{"id":"int-69455e46e4de1e58cef4cdc6a124ca5f","kind":"field_change","created_at":"2026-08-24T17:19:41.905294834Z","actor":"Sam Catlow","issue_id":"archie-core-4tye","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Implemented, regression-tested, full task check passed, and adversarial review finding resolved."}}
{"id":"int-084477087493b06c289d87dfc319c6d3","kind":"field_change","created_at":"2026-08-24T17:19:41.96078947Z","actor":"Sam Catlow","issue_id":"archie-core-y1hv","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Implemented, regression-tested, full task check passed, and adversarial review finding resolved."}}
{"id":"int-9de2b83189f32eec56dd588dd4b1c439","kind":"field_change","created_at":"2026-08-24T17:28:38.936618176Z","actor":"Sam Catlow","issue_id":"archie-core-15iq","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Implemented with regression coverage, full task check passing, and adversarial review clean."}}
{"id":"int-45a964f90a687ff51f5d7678683f2706","kind":"field_change","created_at":"2026-08-24T17:28:38.999458853Z","actor":"Sam Catlow","issue_id":"archie-core-473l","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Implemented with regression coverage, full task check passing, and adversarial review clean."}}
+2 -2
View File
@@ -1,5 +1,5 @@
{"_type":"issue","id":"archie-core-473l","title":"Reconcile task clone ownership after container commits","description":"Agent containers write Git objects as root into bind-mounted task clones, while ownership is currently repaired only before push. A stopped or failed workflow before push leaves unreadable objects and makes the next host-side worktree prepare fail instantly. Reconcile ownership after every CommitAll result as well as before push.","status":"in_progress","priority":0,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-24T17:24:57Z","created_by":"Sam Catlow","updated_at":"2026-08-24T17:25:30Z","started_at":"2026-08-24T17:25:30Z","lease_expires_at":"2026-08-24T17:30:30Z","heartbeat_at":"2026-08-24T17:25:30Z","dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-15iq","title":"Make UUIDv7 session references distinguishable","description":"UUIDv7 session IDs created close together share their first eight characters, making displayed chat session references unusable and allowing /topic to select the wrong first prefix match. Surface a sufficiently distinguishing shorthand and resolve topic references unambiguously.","status":"in_progress","priority":0,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-24T17:20:49Z","created_by":"Sam Catlow","updated_at":"2026-08-24T17:20:53Z","started_at":"2026-08-24T17:20:53Z","lease_expires_at":"2026-08-24T17:25:53Z","heartbeat_at":"2026-08-24T17:20:53Z","dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-473l","title":"Reconcile task clone ownership after container commits","description":"Agent containers write Git objects as root into bind-mounted task clones, while ownership is currently repaired only before push. A stopped or failed workflow before push leaves unreadable objects and makes the next host-side worktree prepare fail instantly. Reconcile ownership after every CommitAll result as well as before push.","status":"closed","priority":0,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-24T17:24:57Z","created_by":"Sam Catlow","updated_at":"2026-08-24T17:28:39Z","started_at":"2026-08-24T17:25:30Z","closed_at":"2026-08-24T17:28:39Z","close_reason":"Implemented with regression coverage, full task check passing, and adversarial review clean.","dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-15iq","title":"Make UUIDv7 session references distinguishable","description":"UUIDv7 session IDs created close together share their first eight characters, making displayed chat session references unusable and allowing /topic to select the wrong first prefix match. Surface a sufficiently distinguishing shorthand and resolve topic references unambiguously.","status":"closed","priority":0,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-24T17:20:49Z","created_by":"Sam Catlow","updated_at":"2026-08-24T17:28:39Z","started_at":"2026-08-24T17:20:53Z","closed_at":"2026-08-24T17:28:39Z","close_reason":"Implemented with regression coverage, full task check passing, and adversarial review clean.","dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-4tye","title":"Install updates without requiring a source checkout","description":"Make the automatic updater fetch approved release source into an invocation-scoped temporary clone, build and install the binary from that source, and never require or mutate an operator or agent checkout.","status":"closed","priority":0,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-24T17:11:05Z","created_by":"Sam Catlow","updated_at":"2026-08-24T17:19:42Z","started_at":"2026-08-24T17:11:11Z","closed_at":"2026-08-24T17:19:42Z","close_reason":"Implemented, regression-tested, full task check passed, and adversarial review finding resolved.","dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-1787489595430-1-8f81afa3","title":"Security: an unauthenticated endpoint must not be able to run an agent","description":"P0 within this epic because the feature's own pitch is the threat model: a public intake surface whose output is an agent with tool access and a repo. Get this wrong and a webhook URL is remote code execution with extra steps.\n\nNon-negotiables to design:\n\n- Per-source authentication. A source registers with a secret (HMAC, as internal/channels/webhook already does per route) before its events can trigger anything. Capture-only for unknown senders is acceptable; triggering is not.\n- Human approval before a binding goes live. An operator authoring a binding is a deliberate act; an event arriving is not. Nothing should self-arm.\n- Rate and volume limits per source, so capture cannot be used to exhaust disk or drown the inspector.\n- Payload content is untrusted input flowing into an agent prompt. Treat prompt injection as expected, not exceptional -- the sender controls that text, and the agent has tools. Bound what a playbook-triggered workflow may do.\n- Captured payloads may contain secrets from the sending system. Decide retention, redaction and who can view them; internal/memory/scrubber may already have applicable prior art.\n\nArchie's own principle applies: environmental enforcement over prompt rules. 'The agent should ignore instructions in the payload' is not a control.","status":"closed","priority":0,"issue_type":"feature","created_at":"2026-08-23T12:22:08Z","updated_at":"2026-08-24T06:58:51Z","closed_at":"2026-08-24T06:58:51Z","external_ref":"https://github.com/samcharles93/archie-core/issues/564","source_system":"github:https://github.com/samcharles93/archie-core/issues/564:564","metadata":null,"dependencies":[{"issue_id":"archie-core-1787489595430-1-8f81afa3","depends_on_id":"archie-core-t2db.5","type":"supersedes","created_at":"2026-08-24T06:58:51Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-mzok","title":"Make ClaimTurn insert-race regression deterministic under CI","description":"GitHub deploy run 32587841233 failed after the gateway compile fix because TestClaimTurnConcurrentInsertRaceNeverReturnsAnError launched 200 concurrent SQLite claims and exhausted its immediate retry loop with SQLITE_BUSY. The test's stated target is the two-connection same-turn insert race, not unrelated global write-lock saturation.","acceptance_criteria":"The regression still races two independent stores over the same turn ID; unrelated cross-trial SQLite contention cannot exhaust retries; repeated focused runs, task check, and diff-scoped lint pass; fresh adversarial review has zero surviving findings.","status":"closed","priority":0,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-08-22T17:34:07Z","created_by":"Sam Catlow","updated_at":"2026-08-24T06:59:21Z","started_at":"2026-08-22T17:34:11Z","closed_at":"2026-08-24T06:59:21Z","close_reason":"Already fixed on main: session_store_sqlite_claimturn_race_test.go now runs the 100 trials serially (two stores racing one turn ID per trial) with bounded SQLITE_BUSY retries, instead of 200 concurrent claims. Verified: -count=3 passes.","external_ref":"https://github.com/samcharles93/archie-core/issues/587","metadata":null,"dependency_count":0,"dependent_count":0,"comment_count":0}
+16 -5
View File
@@ -2,6 +2,7 @@ package agentworker
import (
"context"
"errors"
"fmt"
"io/fs"
"log/slog"
@@ -52,18 +53,28 @@ func (h *hybridTrees) Prepare(ctx context.Context, owner, repo, base string, iss
}
func (h *hybridTrees) CommitAll(ctx context.Context, dir, message string) (bool, error) {
return h.local.CommitAll(ctx, dir, message)
changed, commitErr := h.local.CommitAll(ctx, dir, message)
if ownershipErr := h.reconcileOwnership(dir); ownershipErr != nil {
ownershipErr = fmt.Errorf("reconcile worktree ownership after commit: %w", ownershipErr)
return changed, errors.Join(commitErr, ownershipErr)
}
return changed, commitErr
}
func (h *hybridTrees) Push(ctx context.Context, dir, branch string) error {
if h.worktreeUID >= 0 && h.worktreeGID >= 0 {
if err := chownTree(dir, h.worktreeUID, h.worktreeGID); err != nil {
return fmt.Errorf("reconcile worktree ownership before push: %w", err)
}
if err := h.reconcileOwnership(dir); err != nil {
return fmt.Errorf("reconcile worktree ownership before push: %w", err)
}
return h.push.Push(ctx)
}
func (h *hybridTrees) reconcileOwnership(dir string) error {
if h.worktreeUID < 0 || h.worktreeGID < 0 {
return nil
}
return chownTree(dir, h.worktreeUID, h.worktreeGID)
}
func (h *hybridTrees) Diff(ctx context.Context, dir, base string) (string, error) {
return h.local.Diff(ctx, dir, base)
}
@@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
"testing"
"time"
@@ -148,6 +149,24 @@ func TestHybridTreesPushSkipsReconciliationWhenNotConfigured(t *testing.T) {
}
}
func TestHybridTreesCommitReconcilesOwnershipEvenWhenCommitFails(t *testing.T) {
missing := filepath.Join(t.TempDir(), "does-not-exist")
trees := &hybridTrees{
local: &worktree.Manager{},
localDir: missing,
worktreeUID: os.Getuid(),
worktreeGID: os.Getgid(),
}
_, err := trees.CommitAll(t.Context(), missing, "test commit")
if err == nil {
t.Fatal("CommitAll error = nil, want commit and ownership reconciliation failure")
}
if !strings.Contains(err.Error(), "reconcile worktree ownership after commit") {
t.Fatalf("CommitAll error = %q, want ownership reconciliation context", err)
}
}
// TestHybridTreesPushSurfacesOwnershipReconciliationFailure: a configured
// but broken reconciliation (the dir push is asked to fix vanished) must
// fail loudly rather than forward to a push that will only fail later with