Artifact 45b2037106e999bb9973a58e3921e3934b9014feb5cca8a56f540119034055f1:
- File
src/pic.h
— part of check-in
[7e7550292a]
at
2026-11-18 12:30:18
on branch tracer-bullet
— Add the first durable agent loop in C
pic keeps its journal in its own libfossil-hosted SQLite database: an idempotent admission per request key, then one short transaction per state change, never held across provider or tool I/O. A replay-safe write tool reruns after a crash; a replay-unsafe exec records an unknown outcome and never reruns. exec runs under a supervisor that starts the command only after the started commit and kills its group if pic dies or is interrupted. A second pic on the same database is refused.
test/pic/crash.sh crashes at every commit and effect boundary and checks the journal against an external ledger, plus deadline, output redirection, background child, crash and interrupt orphaning, and second-writer cases. Vendored SQLite and libfossil match ctx byte for byte. (user: dmestas, size: 2228) [annotate] [blame] [check-ins using] [more...]
/* pic: durable coding-agent harness. Internal interfaces for the tracer bullet. */ #ifndef PIC_H #define PIC_H #include <stddef.h> #include <stdint.h> #include "sqlite3.h" #define PIC_SCHEMA_VERSION "1" #define PIC_ERR_CAP 512 #define PIC_OUTPUT_CAP 65536 /* tool output kept in the journal, bytes */ typedef struct pic_store { sqlite3 *db; int lock_fd; char err[PIC_ERR_CAP]; } pic_store; /* Store: owns the connection, the single-writer lock, schema, and invariants. */ int pic_open(pic_store *s, const char *db_path); void pic_close(pic_store *s); int pic_exec(pic_store *s, const char *sql); int pic_begin(pic_store *s); int pic_commit(pic_store *s); void pic_rollback(pic_store *s); int pic_check(pic_store *s); /* hand-enforced integrity: foreign_keys is OFF */ /* Scripted provider: turn N of a submission is line N+1 of the script. */ typedef enum { PIC_REPLY_TEXT, PIC_REPLY_TOOL } pic_reply_kind; typedef struct { pic_reply_kind kind; char *tool; /* "write" or "exec" when kind is PIC_REPLY_TOOL */ char *args; /* tool arguments, or the answer text */ } pic_reply; int pic_provider_reply(const char *script, int64_t turn, pic_reply *out, char *err, size_t errcap); void pic_reply_free(pic_reply *r); /* Tools run outside any transaction and return a malloc'd result string. * started() durably records that the effect has begun; tools call it exactly * once, before any external effect. If it fails the tool returns NULL and * nothing ran. NULL after a successful started() means the outcome is lost. */ typedef struct { int exec_seconds; int (*started)(void *ctx); void *ctx; } pic_tool_hooks; int pic_tool_replay_safe(const char *tool); char *pic_tool_run(const char *workspace, const char *tool, const char *args, const pic_tool_hooks *hooks); /* Loop. */ int pic_submit(pic_store *s, const char *request_key, const char *content, int *duplicate); int pic_recover(pic_store *s); int pic_run(pic_store *s, const char *workspace, const char *script, int exec_seconds); int pic_dump(pic_store *s); /* Crash-injection hooks exist only in development builds. */ #ifdef PIC_FAULTS void pic_fault(const char *point); #else #define pic_fault(point) ((void)0) #endif #endif