The data model
What is inside durable.sqlite, which records are Pi’s and which are Pipal’s, and the IDs that tie them together.
You reopen a chat and find the title you gave it, the prompt you sent, and the answer the assistant was writing. They arrive together on screen. On the host, the title is chat metadata, your prompt is a transcript entry, and the partial answer comes from live run state. Follow those records and you can tell where to look for a chat setting, a saved message, or work still in progress.
In this chapter
- Locate a chat’s transcript, settings, and work records inside Pi Durable’s store.
- Trace Pipal’s own documents, entries, signals, and tasks to their writers.
- Distinguish IDs for conversations, messages, submissions, and uploaded files.
- Read the snapshot and transcript types from the browser’s side.
A Pipal chat is a Pi conversation with a Pipal document
- durable.sqlite
Pi Durable supplies the SQLite storage. The boxes show logical records and where they attach.
- Conversation
The conversation identifies this chat’s transcript. A top-level chat is ownerless. A specialist conversation belongs to a task.
- Entries
Immutable transcript records. An attachment entry holds prepared model content and the display information for an input file.
- pipal.web-artifact
Stores a title, the HTML source, and an optional link to an earlier artifact.
- pipal.file-artifact
Stores the plain basename as the title, the file bytes as base64, and an optional link to an earlier file artifact.
- pipal.web-artifact
- pi.agent
The model, thinking level, instructions, turn limit, and extension names Pipal applies through Pi’s
configure(). - pi.live
The run in progress, its partial generation and tool slots. It can also record why a run ended without an answer.
- pi.usage
Token and cost totals. Pipal reads these for session statistics.
- pipal.chat
The chat’s title, archive flag, profile, workspace location, project binding, and deadline.
- pipal.routines
A chat with scheduled prompts keeps their definitions, last runs, and next alarm here.
- Entries
- Work records
A submission records accepted input and its outcome. Tasks carry out work for a conversation and can save a checkpoint, the state they need to continue.
- Submission
A request ID can recover a submission within its conversation. The receipt names the submission.
- Publish record
The task-scoped
pipal.published-artifactdocument remembers the HTML or file entry this publish call already wrote.
- Submission
- Session documents
These records are keyed to the whole Pi store. A Pi session here means the open durable store.
- Chat creation
A keyed creation remembers its inputs, resolved location and original YOLO default while a project opens. Once the chat exists, the receipt also points to its conversation ID.
- Worker slots
pipal.worker-slotstracks the supervisor tasks occupying development worker slots across chats.
- Chat creation
- Conversation
- Submission → Entries · Names the input once placed and the answer when settled as done
- Publish record → Entries · Names the artifact entry
- Chat creation → Conversation · Names the created conversation
- pipal.routines → Submission · A dispatched routine records its submission
pipal.chat
The chat’s title, archive flag, profile, workspace location, project binding, and deadline.
When you start a chat, Pipal asks Pi Durable to create a conversation and apply the agent settings. In the same commit, create() fills in pipal.chat with the title, profile, and workspace locationThe place a chat uses for project tools, either the Pipal host, an account reached over SSH, or a Docker project.. That document also lets Pipal recognize the conversation as one of its chats. A conversation ID without a pipal.chat document gets a 404 on a chat lookup. index.ts
After you send a message, Pi can append an entry for your input and create a task to answer it. Rename the chat and Pipal changes the title in the document instead of adding a message. This is why you look in a different place for the name on the sidebar and for the words you typed. The profile ID lives in pipal.chat, while the agent settings that Pi uses to make requests live in pi.agent. index.ts README.md
Three Pi documents show the agent’s settings, progress, and spend. pi.agent holds the choices for running the agent. pi.live gives Pipal the active run, partial reply, and tool activity and can retain the reason a run ended without an answer. pi.usage keeps token and cost totals for session statistics even when there’s no run left to watch. README.md session-info.ts
Pi keeps a provider-facing session ID in pi.provider and the submission queue in pi.inbox. The provider ID is a UUIDv7 per conversation and survives reopen. Pi assigns a fresh one for a child or fork. README.md
Pi creates pi.generation tasks for model responses and pi.tool tasks for their calls. A generation owns its tool tasks and hands off to the next generation when another model response is needed. README.md
Deep diveThe Pi records Pipal reads
| Record | Writer and reader |
|---|---|
pi.agent |
Pipal applies profiles, model changes, and thinking levels through Pi’s configure(). Admission reads model and can refresh instructions and extension names. maxTurns limits tool rounds. README.md index.ts view.ts |
pi.live |
Pi maintains run, generation.message, tools, and runFailure for the projection. Core checks run during admission and settings changes. Pipal sets approval details through Pi’s details() API and clears them when it reads the decision. index.ts view.ts |
pi.usage |
Pi tallies usage by provider/model and by tool name, including failed attempts and compaction. Pipal reports child usage separately. README.md session-info.ts |
| Transcript entries | Pi places plain input in pi.user, a model response in pi.assistant, and a tool result in pi.tool-result. It adds pi.system when instructions or tools change and uses pi.compaction for a summary. Its pi.reset kind marks a reset of model context. README.md |
The chat document holds Pipal’s rules for this conversation
When you create a chat with a workspace, Pipal pins it to This machine, SSH machine, or Docker. In a development workspace, the project name is what you recognize when you reopen the chat. The stored scope ties that name to the directory the host checked. Replacing the directory behind a familiar name can make the old binding invalid. index.ts development-workspace.ts
Pipal also stores whether you’ve given the chat automatic approval for that workspace, called YOLO. Core’s workspaceStatus() sends the browser a flag only when the saved grant still matches the current scope. The scope itself stays on the host. Approvals and YOLO follows the decision that uses it. index.ts
The clock for a reply has a place in the document too. When core accepts an input, it records the deadline. If the run runs out of time, core saves a marker so a later snapshot can tell a time limit from a click on Stop. index.ts
For a development worker, the parent’s document holds the link to its child conversation. Workers follows the work behind that link. workers.ts
Deep diveEvery field in the pipal.chat document
This conversation document starts from its initial value on a fork. Each change saves a full base for its latest value. view.ts README.md
export const Chat = defineDoc<Metadata>({ kind: 'pipal.chat', version: 1, scope: 'conversation', history: 'latest', fork: 'initial', initial: () => ({ title: 'New conversation', archived: false, createdAt: 0, profile: '', deadline: 0 }), checkpointWhen: () => true});| Field | What writes it |
|---|---|
title, createdAt |
Creation sets both, using the task text for a child’s title. PATCH can rename a top-level chat. index.ts |
archived, profile |
PATCH archives and can change an inactive top-level chat’s profile. Creation sets the profile for parents and children. index.ts |
location, project, projectScope |
create() saves the location (including none) and any project ID and scope. Docker stores a volume binding without a project ID. prepareChild() inherits the binding. PATCH rejects a different location or project ID with 409. index.ts |
yoloScope |
Creation or PATCH sets the current workspace scope. Changing profile or turning YOLO off clears the prior grant. Child preparation can inherit the parent’s grant when scope and profile allow it. index.ts |
deadline |
Admission sets the epoch-millisecond deadline. Foreground specialists share it. Workers get their own. Approvals, tool time, reply grace, and settled worker waits can extend it. index.ts workers.ts |
timeLimit |
Expiry marks the chat and unfinished delegated chats before aborting. Admission or a new worker budget clears the marker on that chat. index.ts |
toolTime |
Bounded tools reserve {startedAt, limitMs}. A tool exiting with an active context, or startup recovering a pending submission, adds capped elapsed time and clears the reservation. New budgets clear it. index.ts |
replyGraceMs |
Admission sets a finishing window. Expiry uses it once if text is streaming and the window has time left. Recovery skips it. index.ts |
worker, independentWorker |
Worker tools and the supervisor track the child, owner task, profile, assigning tool task ID (generation), status, and optional prompt, submission, waiter, stopping flag, and error. Core sets independentWorker: true on the child. workers.ts index.ts |
closeoutRun |
Marks the generation reserved for a text reply. Admission clears it. turn-budget.ts index.ts |
workerWait |
wait_worker reserves {task, start, until} on the parent. On wake it clears its reservation and adds elapsed time up to until to the deadline. Admission clears old reservations. workers.ts index.ts |
For an older chat without location, locationOf() reads a named project as ssh. Otherwise it uses the saved Docker migration flag, if present, or none. For Docker, pinnedScope() can recover the binding from the old YOLO grant or the migrated volume scope. index.ts workspace-locations.ts
Features attach records where their work belongs
When you send a PDF, the model can get prepared content while the transcript keeps the prompt and file name you recognize. Pipal chooses the pipal.attachment-message kind and supplies the display information in the entry’s data. Pi writes the entry during admission, including the prepared model input. Files in, artifacts out follows the input from the browser. index.ts view.ts
Publication captures a new copy in durable.sqlite. publish_web_artifact saves HTML in a pipal.web-artifact entry. publish_file saves an entire project file of 512 KiB or less as a file artifactA saved copy of a project file you can download from the chat.. The pipal.file-artifact entry stores the basename as the plain-text title and encodes only the file bytes as base64. The download is still there if the project file later changes or disappears. Either kind can link a new version to an earlier artifact of the same kind in the same delegation tree. Each version keeps its own entry and ID. project-coding.ts web-artifacts.ts
A scheduled prompt illustrates the other record types. The routine’s schedule lives in a document. A background task waits for its next due time. A signal, a keyed message addressed to a task, can wake an alarm that has been replaced so it can check whether it still owns the schedule. A task can save a checkpoint, the state it needs the next time it runs. Routines follows the dispatch, and Durable by default follows recovery. routines.ts
Deep diveThe other Pipal record kinds and their definitions
Pi runs Pipal’s tasks and signals the supervisor with SubmissionSettled when a worker submission settles. README.md workers.ts
| Kind | Scope or writer | Stored purpose |
|---|---|---|
pipal.routines |
Conversation document | Edits, archive, dispatch and expiry update schedules, last runs or the alarm pointer. Saves a new base after 32 deltas. routines.ts |
pipal.published-artifact |
Task document | Both tools commit the entry with its pointer. publishProjectFile() checks the pointer before reading the file, so replay can succeed after deletion. web-artifacts.ts |
pipal.chat-creation |
Keyed session document | Reserves the inputs, resolved location and original YOLO default for keyed retries, then records the conversation ID. An absent defaultYolo on an older receipt means false. index.ts |
pipal.worker-slots |
Session document | Worker assignment adds the supervisor’s task ID to the occupied slots. The supervisor removes it when it finishes handling the assignment, including admission failure or abort. workers.ts |
pipal.attachment-message |
Entry, message admission | data holds text, optional textFiles, and attachments. The model-facing user message holds the prepared content. view.ts index.ts |
pipal.routine-message |
Entry, scheduled admission | data holds routineId, name, and scheduledAt. The user message holds the prompt. view.ts index.ts |
pipal.resume |
Entry, response resume | The model gets a continuation prompt and any recoverable text from an aborted reply. The browser shows “Resume response”. view.ts index.ts |
pipal.web-artifact, pipal.file-artifact |
Entries, publish tools | data holds {title, html, revises?} or {title, base64, revises?}. The entries contain no model message. The tool result names the artifact by ID and title. web-artifacts.ts |
pipal.workspace-decision |
Signal, approval route | Delivers {allow} to the tool task under the key for the specific approval request. workspace-approval.ts index.ts |
pipal.routines-changed |
Signal, alarm replacement | An empty payload wakes a superseded alarm so it can check whether it still owns the schedule. routines.ts |
pipal.worker-change |
Signal, worker tools and supervisor | An empty payload wakes the parent’s wait on settlement or the supervisor when the worker gets a new assignment. workers.ts |
pipal.routine-alarm |
Background task owned by the chat | Waits for the due time or replacement signal. Dispatch checks alarm ownership and due time before admission. routines.ts |
pipal.development-worker |
Background task owned by the parent chat | Supervises a worker conversation that it owns. It admits assignments, waits for submissions to settle, and updates the parent’s record. workers.ts |
The IDs answer different questions
If an attachment has an ID, so does the message that shows it. The upload ID is a UUID assigned when the server saves the original file. The message ID tells the browser which transcript item it is looking at. Pipal makes that ID from the entry number, a dot, and the message’s zero-based position within the entry. That position stays the same if the browser loads the message on an older page. uploads.ts view.ts
Pi Durable’s Storage.mintId() contract gives conversations, entries, tasks, and submissions a shared numeric ID space within a store. It allocates fresh IDs in increasing order and above every stored ID after a reopen. Entry scans use ID order. README.md CHANGELOG.md
A request ID answers a different question. Suppose you press Send and the acknowledgment gets lost. The bundled browser gives that send a UUID and can reuse it for the same input. Core looks up that request ID within the conversation. If the stored input matches, the receipt returns the existing submission ID. The core runtime follows that check through admission. App.svelte index.ts
Deep diveWhere to use each kind of ID
| ID | Form and boundary |
|---|---|
| Conversation, task, submission | Pi record IDs. Chat lookup parses a positive safe integer from a decimal string. runId names the current generation task, resumableRunId names the generation available to resume, and approval.taskId names a tool task. In the send receipt {id, requestId}, id names the submission. index.ts view.ts README.md |
| Entry, message, artifact | A cursor names an entry. <entryId>.<index> names a transcript item. Artifact IDs are decimal entry IDs scoped by the conversation’s ownership tree. index.ts view.ts web-artifacts.ts |
| Request | HTTP message requests accept 1–128 ASCII letters, digits, underscores or hyphens. Chat creation has its own optional UUID key. Pipal’s internal sends use keys such as delegate:<taskId>, routine:<routineId>:<scheduledAt>, resume:<taskId> and worker:<generation>. app.ts delegate.ts index.ts workers.ts |
| Upload | Lowercase UUID from the host’s randomUUID(). It names a directory in uploads/, which the host looks up by UUID alone. uploads.ts |
| Tool call | Provider string. A provider can reuse an ID in a later round. The browser matches ID and tool name within a round. view.ts transcript.svelte.ts |
The browser sees a projection of the records
{
"id": "9", "title": "UTC time",
"profile": "chat", "archived": false,
"createdAt": 1796112000000,
"location": "none",
"model": "faux/faux-1",
"thinkingLevel": null,
"messages": [{
"id": "12.0", "role": "user",
"text": "What time is it in UTC?",
"timestamp": 1796112000000
}],
"contextWindow": { "used": 8,
"limit": 128000,
"source": "estimated" },
"status": "running", "runId": "14",
"partial": "I’ll check the clock for the current",
"liveTools": []
} - The chat’s identity
The ID comes from Pi’s conversation. Title, profile, archive flag, and creation time come from
pipal.chat. - Workspace location
This chat has no workspace location. A chat whose location no longer has a matching workspace binding also gets
workspaceUnavailable: true. - Agent settings
Pipal joins Pi’s model provider and model ID into one string. A null thinking level represents Auto.
- Saved transcript
This user message is the first model message in entry 12. The dot separates the entry ID from its zero-based message index.
- Context budget
The count estimates the tokens in the saved model context. The limit comes from Pipal’s model catalog. Both numbers are illustrative.
- Work in progress
The run ID names the current generation task. It can change within one reply when Pi moves to the next generation. Partial text can be visible while the saved message list remains unchanged.
{
,
,
,
,
,
} 1 The chat’s identity
The ID comes from Pi’s conversation. Title, profile, archive flag, and creation time come from pipal.chat.
When the tab receives a conversation snapshotThe JSON view Pipal assembles for the browser from saved chat state, recent messages, and live work., it gets a projection, the view core assembled for the browser. snapshot() in view.ts joins chat settings and the agent summary with the transcript window and live state. readSnapshot() supplies the context count and finds pending approval requests. contracts.ts names what the browser can receive. Live streams explains how that same view travels over the connection. view.ts index.ts
A ChatMessageAn item Pipal constructs from a saved entry for the browser’s transcript, such as a message, tool result, or artifact reference. is one item in that transcript. chatMessage() extracts display text and maps a model tool result to the browser’s tool role. A saved compaction summary can appear as system, while Pi’s own system messages are skipped. The Svelte workspace shows how these individual items become rows. view.ts
messages() turns each saved artifact into a card reference with its entry ID, publishing conversation ID, title, and optional revision link. A file adds kind: 'file'. The snapshot and history carry those references without the stored HTML or base64. Opening an HTML preview or downloading an artifact makes a separate signed-in request. File cards offer a download, with the original filename and the bytes decoded on the server. view.ts app.ts
Exa search and Jina Reader return ordinary tool results when Developer uses pipal.public-web. Provider-hosted search appears as search activity on the assistant message. public-web.ts view.ts
Deep diveA field guide to the browser’s JSON
contracts.ts marks optional fields with ?. Serialization omits undefined values. contracts.ts app.ts
| Snapshot fields | Meaning |
|---|---|
id, title, archived, profile, createdAt, model, thinkingLevel |
The conversation summary’s basic fields. An unset model becomes an empty string and Auto thinking is null. view.ts |
location, project, workspaceUnavailable, yolo |
The chat’s location, any named project and current grant. workspaceStatus() sets workspaceUnavailable: true when a selected location has no matching binding. view.ts index.ts |
messages, before |
Projected committed transcript window and the entry immediately before it, when present. view.ts README.md |
status, runId, resumableRunId, error, failureReason |
A run can be running, idle, stopped or failed. Model failures add a public reason. An unarchived main chat can offer Resume after an abort, a turn limit or a budget-reserved final reply. view.ts |
retry, compactions, lastCompactionFailure |
Scheduled generation retry, active summary tasks and the most recent summary failure. The API reference lists their fields. contracts.ts |
partial, liveSearches, liveTools, worker |
partial is generation text or an empty string. liveSearches holds hosted search activity. Tool slots have name, status, output, and optional callId, approval, and delegation. read_web_artifact slots show blank output. The optional worker has conversationId, profile, and status. Child approvals can appear in delegation.approvals or worker.approvals. contracts.ts view.ts |
contextWindow |
Used tokens, model limit (or null), and whether the count is reported or estimated. Search, context and cost traces the measurement. context-window.ts |
| Message fields | Meaning |
|---|---|
id, role, text, timestamp |
Required fields are ID, role, and text. Roles are user, assistant, tool, and system. Model messages carry timestamps. Artifact cards have empty text and omit the timestamp. contracts.ts view.ts |
textFiles, attachments, routineName |
Original display data for attached or scheduled input. Attachment descriptors hold id, name, mimeType and optional mode. contracts.ts view.ts |
calls, failed, searches, sources |
Assistant calls with formatted JSON arguments, a failure flag, and hosted search metadata when available. An HTML publish call exposes only title and revises from its arguments. A file publish call can show its project path. A saved search still marked running becomes interrupted. Tool results have their own failed flag. view.ts |
name, callId, delegation, artifact |
Tool results name the tool and call. A delegate result can link a specialist and its artifact references. Both use WebArtifactRef for the browser’s artifact references, including kind: 'file' for a downloadable file. contracts.ts view.ts |
chatMessage() strips echoed arguments from HTML publish validation errors and replaces successful read_web_artifact results with “Read saved artifact source.” The model can read saved HTML using that tool. findArtifact() permits lookup in the publishing conversation or another conversation that shares the same root in Pi’s ownership chain. view.ts web-artifacts.ts
Workspace settings, sign-in, and original files have their own stores
The owner’s choices in Settings → Workspace live in workspace-settings.json beside durable.sqlite. loadWorkspaceLocations() reads the enabled locations and the default from this file. A fresh install starts with every location off. If the database already exists and the settings file is missing, Pipal can import a configured SSH or Docker grant. Changing the default changes the starting choice for new chats that can use a workspace. Each existing chat keeps its location. workspace-locations.ts index.ts
If you need the original of an upload, follow its UUID to uploads/<id>/original beside metadata.json. The durable entry holds the prepared model input and the reference the browser can use. uploads.ts index.ts
Passkey mode keeps credential public keys, counters, and hostname in passkeys/auth.sqlite. ChatGPT model sign-in keeps the device ID and any saved credentials and model list in chatgpt-auth.json. Where everything lives and runs maps the rest of the data directory. passkey-store.ts credentials.ts
Once the tab has this JSON, how does it keep a transcript, tool cards and the composer in step as the view changes? The Svelte workspace picks up at that boundary.
Recap
- A Pipal chat is a Pi conversation with a
pipal.chatdocument. Pipal writes its own record kinds through Pi’s storage API. - A message ID comes from a saved entry and a position. Request and upload IDs let Pipal recognize a send or original file independently.
- Core turns chat records and live state into a conversation snapshot, with display-ready messages and references.
- You rename a chat and leave its model unchanged. Which record receives the new title?
- The latest assistant entry
- The pi.agent document
- The pipal.chat document
Answer and explanation
The pipal.chat document
PATCH changes the chat’s metadata document. The transcript entries and selected model have separate records.
- One saved entry contributes two model messages to the transcript. How can the browser identify both?
- It uses the shared entry ID with a different index for each.
- It uses the same ID and distinguishes them by their text.
- It uses the upload UUID for the second one.
Answer and explanation
It uses the shared entry ID with a different index for each.
The entry ID identifies the saved record. The index identifies the model message within that record.
- A file publish task replays after the project copy has been deleted. Where does it recover the published file’s ID?
- In the conversation title
- In its own pipal.published-artifact document
- In a new submission receipt from the browser
Answer and explanation
In its own pipal.published-artifact document
The same commit saves the captured bytes in the entry and the entry ID under the task. Replay can recover the ID without opening the project file again.
You rename a chat and leave its model unchanged. Which record receives the new title?
One saved entry contributes two model messages to the transcript. How can the browser identify both?
A file publish task replays after the project copy has been deleted. Where does it recover the published file’s ID?