diff --git a/docs/investigations/agent-operations/README.md b/docs/investigations/agent-operations/README.md new file mode 100644 index 0000000..826b060 --- /dev/null +++ b/docs/investigations/agent-operations/README.md @@ -0,0 +1,240 @@ +# Arc agent operations investigation + +Investigation: `arc-0d80.05y7th`, September 2026. This examines Claude Code, pi, +and Codex. It does not establish a production incident or authorize a new +orchestration framework. Detailed task contracts and scope boundaries remain +required in every runtime. + +## Recommendations + +| Workstream | Decision | Reason and follow-up | +| --- | --- | --- | +| Progress recording | Implement CLI access to existing comments; migrate all three adapters | Append-only comments preserve concurrent notes and specification edits. `arc-0d80.034wng`, then `arc-0d80.03c64b`. | +| Multi-field update consistency | Implement atomic storage update | Injected failure leaves half an update committed today. `arc-0d80.03smij`. | +| Exclusive acquisition | Retain assignment semantics; defer acquisition and leases | Two claims succeeding demonstrates current semantics, not duplicate implementation. Global dispatch/recovery requirements are unspecified. | +| Task-source preparation | Implement narrow runtime-neutral capture/validation with thin adapters | Three consumers justify sharing schema and exact serialization. `arc-0d80.01xfdz`, then `arc-0d80.02veqj`. | +| Concurrent specification editing | Defer conditional revision writes | Comments remove progress writes from this path. Multi-editor requirements remain unestablished. | +| Comment retry idempotency | Defer operation-key storage; prohibit blind automatic POST retries initially | Existing API has no idempotency key. Identical text is not proof of duplicate intent. | + +Session resolution and registration are separate work in `arc-0d80.00tifl` and +`arc-0d80.01f3ua`. The concurrency fixtures use valid explicitly registered +sessions; identity fallback does not explain their results. + +## Baselines and reproduction + +- Arc: `93f5823cfe6c2dc54552b518a27fb2d72a283060`, including the root-session fix. + The installed global CLI was `0.16.0-rc9`; the fixtures used a locally built + binary from the inspected checkout. +- Agent marketplace: `f806cb7bdb47984b2d706d634240c8e29b02f4ae`. Inspected Codex + plugin `0.13.0` and Claude plugin `0.19.0`; relevant installed files matched + the inspected source. +- pi-nexus: `62c7a3550ddc3cb6e65ded609d78012821bf3cf9`, pi-arc `0.11.0`. + Relevant installed extension, skills and agent templates matched source. +- Independent source review traced complete consumers, metadata, retry paths, + and per-runtime differences. No implementation workers ran in the competing + claim experiment. + +The adjacent scripts are investigative fixtures, not future-behavior regression +tests: they deliberately assert the baseline failures. Run from an Arc checkout +containing the baseline binary; the second command accepts an agent-marketplace +checkout with the recorded commit available: + +```sh +task build:quick +python3 docs/investigations/agent-operations/reproduce.py ./bin/arc +python3 docs/investigations/agent-operations/handoff-fixtures.py /path/to/agent-marketplace +``` + +`reproduce.py` needs Python's standard library, local sockets, and the Arc binary. +It creates and removes a temporary server/database, records synchronized writes, +injects failures only into that disposable database, and stops the server in +cleanup. `handoff-fixtures.py` needs Bash, jq and Git; it extracts exact recorded +Codex source lines using `git show` and synthetic API-shaped JSON. It neither +runs a model nor dispatches a worker. Results are retained in +`baseline-results.json` and `handoff-results.json`. + +## A. Progress and specification preservation + +### Reproduced behavior + +| Fixture | Result | +| --- | --- | +| A reads D; B saves D+spec-B; A saves D+note-A | Final D+note-A; A's equality readback passes while spec-B is absent. | +| A's successful description response is discarded; C edits; A retries old body | C's intervening edit is overwritten. | +| Two note appenders synchronize their reads of D | Final D+note-B; note-A is lost. | +| Two comment POSTs and a specification edit run concurrently | Both distinct comments and D+spec-B survive. | +| Successful comment response discarded, identical POST repeated | Two comments with the same text are created. | + +These are observed disposable-fixture outcomes. They do not show that a real +user's task was lost. A successful readback detects some write failures; it +cannot detect an overwritten edit absent from the writer's stale body. + +The current API already exposes issue comments in +`internal/api/comments.go`, `internal/api/server.go`, and OpenAPI. Storage inserts +comments separately from the issue description. The missing part is ergonomic +CLI add/list input and an all-runtime caller migration. `arc show --json` already +contains comments; ordinary `arc show` prints them. + +### Actual consumers differ + +Paths below are relative to each runtime's Arc plugin/package root at the +recorded revision. + +| Runtime | Progress writer | Progress reader | +| --- | --- | --- | +| Codex | `skills/finish/SKILL.md:14-31` merges a note into a copy, replaces description, and compares | Build sequential/parallel, review, and team paths project `.description` into source files and omit comments. | +| Claude Code | `skills/finish/SKILL.md:39,68` uses short CONTEXT/PROGRESS description replacements | Builder/reviewer templates paste ordinary `arc show`, which includes comments. | +| pi | `skills/arc-finish/SKILL.md:29,58` uses the same short description replacements | Builder/reviewer templates paste ordinary `arc show`, which includes comments. | + +The Claude/pi PROGRESS recipe directly targets existing in-progress tasks and +therefore replaces their full specification under current update semantics. +This is a source-demonstrated destructive recipe, not an observed production +loss. The CONTEXT example may target a newly created issue with an empty body; +that does not make the existing-task PROGRESS example safe. + +Moving notes to comments without updating consumers is insufficient. Codex needs +separate complete comment sources. Claude/pi already retrieve comments through +ordinary show, but need reliable retention and clear separation of approved +contracts from progress. Their evaluator templates also paste ordinary show +while requiring independent spec-based tests: automatically including builder +reports conflicts with that intended separation. Preserve full approved task +and design for evaluators; supply progress separately to authorized consumers. +Do not delete older notes embedded in descriptions or silently truncate decisions. + +### Smallest alternatives and costs + +1. Keep description appends: no rollout cost, but retains the demonstrated + lost-update behavior and destructive Claude/pi examples. Not recommended. +2. CLI over existing comments: small core change, no schema migration required. + Add stdin/file input, actor attribution, returned IDs and JSON output; change + all finish/resume/build/review/debug callers and evaluator input plumbing. + Publish a minimum CLI version with adapter rollout. Selected. +3. Add operation keys: enables safe lost-response retries but needs persistent + uniqueness scoped to issue/key, replay versus changed-payload conflict rules, + client key retention, and API/schema tests. Deferred. The first version must + disclose ambiguous outcomes and avoid automatic duplicate POSTs; comparing + text alone is not a safe substitute. +4. Conditional description writes: a real revision token plus expected-revision + predicate could reject stale specification edits. It needs API/client support + and deliberate conflict resolution. A local equality check or timestamp read + followed by an unconditional write is not equivalent. Deferred pending need. + +Required tests: CLI input/actor/JSON fidelity; concurrent comments and spec edit +all retained; documented lost-response behavior; all runtime consumers retain +complete specifications and relevant decisions; evaluator inputs remain +independent; no automatic rewriting of embedded history. + +## B. Assignment, exclusivity, and atomicity + +Both synchronized `arc update --take --session-id ` commands +returned exit 0. The issue ended in_progress under one owner. The winner varies +with scheduling; the recorded run ended with registered-session-A. This is +assignment, not compare-and-set acquisition. It does not prove either worker +implemented anything. + +Current orchestration coordinates within a deployment, without a global Arc +ownership exclusion: + +- Codex build uses ready/selection followed by a separate take; team labels and + task maps are procedural coordination. +- Claude team dispatch uses native team tasks and runtime ownership within one + team. Other Claude sessions, pi, Codex and CLI clients can still assign the + same Arc issue. +- pi parallel build uses optional pi-subagents with fresh contexts and worktree + patches; arc_agent is its sequential fallback. Neither is a database lock. + +The maintainer was asked whether Arc must arbitrate independent dispatchers. +No additional requirement was supplied during this investigation. The source +does not justify assuming a universal single dispatcher, but it also does not +establish a need for leases. Retain `--take` as assignment. If acquisition becomes +required, prefer a distinct atomic conditional operation with current-owner +conflicts and deliberate reassignment kept separate. Specify same-owner retries, +in-progress/closed/deferred state, blockers, cancellation and abandoned ownership +before implementation. Leases/heartbeats need separate recovery requirements. + +There is a concrete consistency defect independent of that decision: +`internal/storage/sqlite/issues.go:341-401` updates fields individually. A trigger +that rejects the second status/session write, regardless of map order, produces +HTTP 500 while the first field remains changed. The recorded run retained +status=in_progress and no owner; another run retained an owner and status=open. + +Select one transactional UpdateIssue follow-up. Preserve successful assignment +semantics and coordinate events/FTS with commit/rollback. The store has a single +connection, so a transaction must not call helpers that acquire the global +connection and deadlock. Test deterministic second-write failure, committed +events/search consistency, successful explicit status overrides, validation, +project isolation and repeated deliberate assignment. Do not describe session +registration plus issue update as one atomic transaction. + +## C. Complete, deterministic task sources + +The current Arc details fixture returns parent-child dependencies but omits +populated parent_id; it also omits labels for an unlabeled issue. All three +adapters' parent_id lookups therefore miss a real parent design. + +Exact Codex shell fixtures additionally reproduce: + +- Command substitution removes trailing LF bytes from descriptions; trailing + CRLF leaves a stray CR. Full source text is not retained exactly. +- Its label validator rejects omitted labels even though that is valid API JSON. +- The conditional parent selector returns the whole object when parent_id is + populated. Claude/pi have a simpler selector and do not share this extra bug. +- Projecting only description drops comments present in the response. + +Claude/pi currently paste ordinary show and ask for relevant design excerpts; +they do not retain the Codex task-indexed immutable source manifest. Their +builder scope constraints still require complete Files, Scope Boundary, Design +Contracts, steps and acceptance requirements. An excerpt or summary is not a +replacement for the user's full-source requirement. Claude team dispatch starts +from compact arc team context and needs explicit per-task hydration. + +Pi's existing materializer generates specialist agent definitions and model +metadata. It does not capture issue/parent sources. Its migration script imports +Claude skills with Pi adaptations and intentionally omits persistent Claude team +primitives. These distinctions must survive the rollout. + +### Ownership alternatives + +A shared portable plugin helper could avoid an Arc release and use existing +detail endpoints. It must be distributed and versioned in three integrations, +survive Pi source regeneration, and be packaged explicitly: pi-arc does not ship +its repository scripts directory. Three independent shell implementations would +retain the maintenance problem. + +A narrow Arc CLI capture/export plus retained-source validation is selected: +one schema-aware implementation serves three real consumers, at the cost of a +stable command/manifest contract and minimum CLI rollout. Keep runtime adapters +small. Do not move role/model choice, tool syntax, dispatch, workspace lifecycle, +scope judgment or integration into core. No new API is needed unless atomic +cross-resource snapshots later become a requirement. + +The core contract should retain raw task/parent JSON, exact full description +files, separate comments, resolved identities and dependency parent, normalized +absent labels, observed updated_at/capture timestamps, and hashes. Validate +returned IDs and types, use an explicit isolated destination, reject cross-task +reuse, and publish the manifest only after all required sources validate. + +Adapter metadata retains the selected route, workspace/cwd, VCS, immutable code +base, plugin path, and verification commands. A retry validates retained source +identity/paths/hashes without refetching mutable Arc state. Add feedback +separately. Explicit source refresh creates a new capture. Digests establish +what was captured; existing separate API reads do not prove task, comments, +labels and parent existed at one atomic database revision. + +Tests must exercise API-shaped omitted fields and dependencies, LF/CRLF/Unicode +and shell-sensitive bytes, wrong identities/types, missing parents, fetch/write +failures, destination collisions and tampering. Two tasks with distinct parents, +routes and workspaces must survive reverse-order retries after server mutation +with zero refetches. Thin-adapter tests cover Codex build/review/team, Claude +Agent/team, pi preferred subagent and arc_agent fallback. Pi regeneration/package +checks and existing runtime reference validators complement executable source +fidelity tests; static token matches alone cannot prove the contract. + +## Implementation boundaries + +The five linked issues contain the selected implementation contracts and +dependencies. This investigation changes no claim semantics, progress-writing +semantics, dispatch framework or task specification. Exclusive acquisition, +leases, conditional specification writes, operation-key storage and atomic +server snapshots remain deferred. The separate session-registration fix is +validated across actual Claude Code, pi and Codex runtime identities. diff --git a/docs/investigations/agent-operations/baseline-results.json b/docs/investigations/agent-operations/baseline-results.json new file mode 100644 index 0000000..9565df4 --- /dev/null +++ b/docs/investigations/agent-operations/baseline-results.json @@ -0,0 +1,54 @@ +{ + "stale_note_overwrites_spec": { + "readback_check_passes": true, + "description": "D+note-A" + }, + "lost_update_response_retry": { + "description": "D+note-A", + "intervening_spec_edit_lost": true + }, + "two_note_appenders": { + "description": "D+note-B", + "note_A_lost": true + }, + "comments_preserve_spec_and_notes": { + "description": "D+spec-B", + "comments": [ + "note-A", + "note-B" + ] + }, + "lost_response_retry": { + "identical_comment_count": 2 + }, + "handoff_detail_shape": { + "parent_id_present": false, + "labels_present": false, + "parent_in_dependencies": true + }, + "competing_claims": { + "responses": [ + { + "session": "registered-session-A", + "exit_code": 0, + "stdout": "Updated: probe.07ueea" + }, + { + "session": "registered-session-B", + "exit_code": 0, + "stdout": "Updated: probe.07ueea" + } + ], + "owner": "registered-session-A", + "status": "in_progress", + "implementation_workers_executed": false + }, + "interrupted_multifield_update": { + "http_status": 500, + "response": { + "error": "update ai_session_id: constraint failed: fixture: second field write rejected (1811)" + }, + "owner": null, + "status": "in_progress" + } +} diff --git a/docs/investigations/agent-operations/handoff-fixtures.py b/docs/investigations/agent-operations/handoff-fixtures.py new file mode 100644 index 0000000..eb87935 --- /dev/null +++ b/docs/investigations/agent-operations/handoff-fixtures.py @@ -0,0 +1,18 @@ +import json, os, subprocess, sys +from pathlib import Path +root = Path(sys.argv[1]).resolve() +revision = 'f806cb7bdb47984b2d706d634240c8e29b02f4ae' +source = 'codex-marketplace/plugins/arc/skills/build/SKILL.md' +lines = subprocess.check_output(['git', '-C', str(root), 'show', revision + ':' + source], text=True).splitlines() +results = [] +def run(name, fixture, source_line, output_var): + snippet = lines[source_line - 1] + '\nprintf \'%s\' "$' + output_var + '"\n' + r = subprocess.run(['bash', '-c', snippet], env={**os.environ, 'TASK_JSON': json.dumps(fixture)}, capture_output=True) + results.append({'name': name, 'source_line': source_line, 'fixture': fixture, 'exit': r.returncode, 'output_hex': r.stdout.hex(), 'output_repr': repr(r.stdout), 'stderr': r.stderr.decode()}) +run('trailing LF preservation', {'description': 'full task\n\n'}, 147, 'TASK_DESCRIPTION') +run('trailing CRLF preservation', {'description': 'full task\r\n\r\n'}, 147, 'TASK_DESCRIPTION') +run('comments projected away', {'description': 'full task', 'comments': [{'id': 1, 'text': 'PROGRESS: retained decision'}]}, 147, 'TASK_DESCRIPTION') +run('unlabeled API issue omitted labels', {'description': 'full task'}, 146, 'BUILD_LABELS') +run('parent dependency only API issue', {'id': 'fixture-parent.1', 'description': 'full task', 'dependencies': [{'issue_id': 'fixture-parent.1', 'depends_on_id': 'fixture-parent', 'type': 'parent-child'}]}, 144, 'TASK_PARENT') +run('populated parent_id selects full object', {'id': 'child', 'parent_id': 'parent'}, 144, 'TASK_PARENT') +print(json.dumps(results, indent=2)) diff --git a/docs/investigations/agent-operations/handoff-results.json b/docs/investigations/agent-operations/handoff-results.json new file mode 100644 index 0000000..fb5cc61 --- /dev/null +++ b/docs/investigations/agent-operations/handoff-results.json @@ -0,0 +1,83 @@ +[ + { + "name": "trailing LF preservation", + "source_line": 147, + "fixture": { + "description": "full task\n\n" + }, + "exit": 0, + "output_hex": "66756c6c207461736b", + "output_repr": "b'full task'", + "stderr": "" + }, + { + "name": "trailing CRLF preservation", + "source_line": 147, + "fixture": { + "description": "full task\r\n\r\n" + }, + "exit": 0, + "output_hex": "66756c6c207461736b0d0a0d", + "output_repr": "b'full task\\r\\n\\r'", + "stderr": "" + }, + { + "name": "comments projected away", + "source_line": 147, + "fixture": { + "description": "full task", + "comments": [ + { + "id": 1, + "text": "PROGRESS: retained decision" + } + ] + }, + "exit": 0, + "output_hex": "66756c6c207461736b", + "output_repr": "b'full task'", + "stderr": "" + }, + { + "name": "unlabeled API issue omitted labels", + "source_line": 146, + "fixture": { + "description": "full task" + }, + "exit": 1, + "output_hex": "", + "output_repr": "b''", + "stderr": "jq: error (at :0): invalid labels\n" + }, + { + "name": "parent dependency only API issue", + "source_line": 144, + "fixture": { + "id": "fixture-parent.1", + "description": "full task", + "dependencies": [ + { + "issue_id": "fixture-parent.1", + "depends_on_id": "fixture-parent", + "type": "parent-child" + } + ] + }, + "exit": 0, + "output_hex": "", + "output_repr": "b''", + "stderr": "" + }, + { + "name": "populated parent_id selects full object", + "source_line": 144, + "fixture": { + "id": "child", + "parent_id": "parent" + }, + "exit": 0, + "output_hex": "7b0a2020226964223a20226368696c64222c0a202022706172656e745f6964223a2022706172656e74220a7d", + "output_repr": "b'{\\n \"id\": \"child\",\\n \"parent_id\": \"parent\"\\n}'", + "stderr": "" + } +] diff --git a/docs/investigations/agent-operations/reproduce.py b/docs/investigations/agent-operations/reproduce.py new file mode 100644 index 0000000..9acac99 --- /dev/null +++ b/docs/investigations/agent-operations/reproduce.py @@ -0,0 +1,194 @@ +#!/usr/bin/env python3 +"""Reproduce Arc agent-operation semantics using only a disposable database.""" +import concurrent.futures +import json +import pathlib +import signal +import socket +import sqlite3 +import subprocess +import sys +import tempfile +import threading +import time +import urllib.error +import urllib.request + + +def investigate(binary, fixture, url): + def request(method, path, data=None, actor="fixture"): + payload = None if data is None else json.dumps(data).encode() + req = urllib.request.Request(url + path, data=payload, method=method, + headers={"Content-Type": "application/json", "X-Actor": actor}) + try: + with urllib.request.urlopen(req, timeout=10) as response: + return response.status, json.load(response) + except urllib.error.HTTPError as error: + with error: + return error.code, json.load(error) + + def ok(method, path, data=None, actor="fixture"): + status, result = request(method, path, data, actor) + assert 200 <= status < 300, (status, result) + return result + + project = ok("POST", "/api/v1/projects", {"name": "Operation investigation", "prefix": "probe"}) + base = "/api/v1/projects/" + project["id"] + ok("POST", base + "/workspaces", {"path": fixture}) + + def issue(title): + return ok("POST", base + "/issues", {"title": title, "description": "D", "issue_type": "task"}) + + def path(item): + return base + "/issues/" + item["id"] + + results = {} + item = issue("Stale note versus specification edit") + stale = ok("GET", path(item))["description"] + ok("PUT", path(item), {"description": stale + "+spec-B"}, "writer-B") + intended = stale + "+note-A" + ok("PUT", path(item), {"description": intended}, "writer-A") + final = ok("GET", path(item))["description"] + assert final == intended and "spec-B" not in final + results["stale_note_overwrites_spec"] = {"readback_check_passes": final == intended, "description": final} + + # The original response could have been lost; repeating the same successful + # update later is safe only if no intervening writer changed the description. + ok("PUT", path(item), {"description": intended + "+spec-C"}, "writer-C") + ok("PUT", path(item), {"description": intended}, "writer-A-retry") + final = ok("GET", path(item))["description"] + assert final == intended and "spec-C" not in final + results["lost_update_response_retry"] = {"description": final, "intervening_spec_edit_lost": True} + + item = issue("Two stale note appenders") + reads = threading.Barrier(2) + a_saved = threading.Event() + + def append_note(writer): + old = ok("GET", path(item))["description"] + reads.wait(timeout=10) + if writer == "B": + assert a_saved.wait(timeout=10) + ok("PUT", path(item), {"description": old + "+note-" + writer}, writer) + if writer == "A": + a_saved.set() + + with concurrent.futures.ThreadPoolExecutor(max_workers=2) as pool: + list(pool.map(append_note, ("A", "B"))) + final = ok("GET", path(item))["description"] + assert final == "D+note-B" + results["two_note_appenders"] = {"description": final, "note_A_lost": True} + + item = issue("Comments plus concurrent specification edit") + start = threading.Barrier(3) + + def comment_or_edit(writer): + start.wait(timeout=10) + if writer == "spec": + return ok("PUT", path(item), {"description": "D+spec-B"}, writer) + return ok("POST", path(item) + "/comments", {"text": "note-" + writer}, writer) + + with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool: + list(pool.map(comment_or_edit, ("A", "B", "spec"))) + details = ok("GET", path(item) + "?details=true") + assert details["description"] == "D+spec-B" + assert sorted(c["text"] for c in details["comments"]) == ["note-A", "note-B"] + results["comments_preserve_spec_and_notes"] = { + "description": details["description"], "comments": sorted(c["text"] for c in details["comments"])} + + # Discard the first successful response, then retry the identical append. + ok("POST", path(item) + "/comments", {"text": "retry-note"}) + ok("POST", path(item) + "/comments", {"text": "retry-note"}) + comments = ok("GET", path(item) + "/comments") + duplicates = sum(c["text"] == "retry-note" for c in comments) + assert duplicates == 2 + results["lost_response_retry"] = {"identical_comment_count": duplicates} + + parent = ok("POST", base + "/issues", {"title": "Parent design", "issue_type": "epic"}) + child = ok("POST", base + "/issues", {"title": "Unlabeled child", "parent_id": parent["id"]}) + details = ok("GET", path(child) + "?details=true") + assert not details.get("parent_id") and "labels" not in details + assert any(d["type"] == "parent-child" and d["depends_on_id"] == parent["id"] + for d in details["dependencies"]) + results["handoff_detail_shape"] = {"parent_id_present": "parent_id" in details, + "labels_present": "labels" in details, + "parent_in_dependencies": True} + + sessions = ["registered-session-A", "registered-session-B"] + for session in sessions: + ok("POST", base + "/ai/sessions", {"id": session, "cwd": fixture}) + item = issue("Competing explicit claims") + start = threading.Barrier(2) + + def claim(session): + observed = ok("GET", path(item)) + assert observed["status"] == "open" and not observed.get("ai_session_id") + start.wait(timeout=10) + command = [binary, "--config", fixture + "/config.toml", "--server", url, + "update", item["id"], "--take", "--session-id", session] + result = subprocess.run(command, cwd=fixture, text=True, capture_output=True, check=False) + assert result.returncode == 0, result.stderr + return {"session": session, "exit_code": result.returncode, "stdout": result.stdout.strip()} + + with concurrent.futures.ThreadPoolExecutor(max_workers=2) as pool: + responses = list(pool.map(claim, sessions)) + final = ok("GET", path(item)) + assert final["ai_session_id"] in sessions and final["status"] == "in_progress" + results["competing_claims"] = { + "responses": responses, "owner": final["ai_session_id"], "status": final["status"], + "implementation_workers_executed": False} + + item = issue("Injected interruption after first field write") + # Count only updates to this disposable issue and reject its second field write, + # regardless of Go's map iteration order. No production DB is opened here. + with sqlite3.connect(fixture + "/data.db") as db: + db.executescript(""" + CREATE TABLE fixture_writes (n INTEGER); + CREATE TRIGGER fixture_abort_second BEFORE UPDATE OF status, ai_session_id ON issues + WHEN OLD.id = '%s' AND (SELECT COUNT(*) FROM fixture_writes) > 0 + BEGIN SELECT RAISE(ABORT, 'fixture: second field write rejected'); END; + CREATE TRIGGER fixture_record_first AFTER UPDATE OF status, ai_session_id ON issues + WHEN OLD.id = '%s' + BEGIN INSERT INTO fixture_writes VALUES (1); END; + """ % (item["id"], item["id"])) + status, response = request("PUT", path(item), {"status": "in_progress", "ai_session_id": sessions[0]}) + assert status == 500, (status, response) + final = ok("GET", path(item)) + assert (final.get("ai_session_id") == sessions[0]) != (final["status"] == "in_progress") + results["interrupted_multifield_update"] = { + "http_status": status, "response": response, + "owner": final.get("ai_session_id"), "status": final["status"]} + return results + + +def main(): + binary = str(pathlib.Path(sys.argv[1]).resolve()) + with tempfile.TemporaryDirectory(prefix="arc-operations-") as fixture: + with socket.socket() as sock: + sock.bind(("127.0.0.1", 0)) + port = sock.getsockname()[1] + url = "http://127.0.0.1:" + str(port) + with open(fixture + "/server.log", "w+") as log: + server = subprocess.Popen([binary, "--config", fixture + "/config.toml", "server", "start", + "--foreground", "--port", str(port), "--db", fixture + "/data.db"], + cwd=fixture, stdout=log, stderr=log) + try: + for attempt in range(100): + try: + with urllib.request.urlopen(url + "/health", timeout=1): + break + except OSError: + if server.poll() is not None: + log.seek(0) + raise RuntimeError(log.read()) + time.sleep(.05) + else: + raise RuntimeError("temporary server startup timed out") + print(json.dumps(investigate(binary, fixture, url), indent=2)) + finally: + server.send_signal(signal.SIGTERM) + server.wait(timeout=15) + + +if __name__ == "__main__": + main()