Pipeline runs use the workspace's directory environment

Resolve the run workspace's environment with workenv (direnv, parent
.envrc, mise; same account rule as Claude chats) at run start and resume,
and apply it to Pi stage processes, a per-environment Pipelines-owned
OpenCode stage service (keyed by a hash of the change, reused across runs,
idle ones stopped after PIPELINES_OPENCODE_STAGE_IDLE_TIMEOUT, revived per
registration), delivery-gate checks and merges, plain-stage opencode CLI
calls and file-change capture git reads. Record the directory, .envrc
files, sources and variable names (never values) on the run detail; a
blocked .envrc becomes a run warning.
This commit is contained in:
2026-11-04 18:08:42 +00:00
parent e0d7b720f5
commit cedfc22e45
26 changed files with 1173 additions and 84 deletions
+13 -2
View File
@@ -160,7 +160,7 @@ func (s *Store) GetRun(ctx context.Context, id int64) (*protocol.RunDetail, erro
}
return nil, err
}
var input, output, paths string
var input, output, paths, environment string
var graphJSON string
if err := tx.QueryRowContext(ctx, "SELECT graph_json FROM pipeline_versions WHERE pipeline_id=? AND version=?", r.PipelineID, r.Version).Scan(&graphJSON); err != nil {
return nil, err
@@ -168,9 +168,15 @@ func (s *Store) GetRun(ctx context.Context, id int64) (*protocol.RunDetail, erro
if err := json.Unmarshal([]byte(graphJSON), &r.Graph); err != nil {
return nil, err
}
if err := tx.QueryRowContext(ctx, "SELECT workspace,allow_tools,write_paths,input_json,output_json,COALESCE((SELECT original_run_id FROM run_retries WHERE run_id=pipeline_runs.id),0),COALESCE((SELECT mode FROM retry_checkpoints WHERE run_id=pipeline_runs.id),CASE WHEN EXISTS(SELECT 1 FROM run_retries WHERE run_id=pipeline_runs.id) THEN 'restart' ELSE '' END),COALESCE((SELECT source_run_id FROM retry_checkpoints WHERE run_id=pipeline_runs.id),0),COALESCE((SELECT source_version FROM retry_checkpoints WHERE run_id=pipeline_runs.id),0),COALESCE((SELECT source_hash FROM retry_checkpoints WHERE run_id=pipeline_runs.id),''),title_source,title_model FROM pipeline_runs WHERE id=?", id).Scan(&r.Workspace, &r.AllowTools, &paths, &input, &output, &r.RetryOf, &r.RetryMode, &r.RetrySource, &r.RetrySourceVersion, &r.RetrySourceHash, &r.TitleSource, &r.TitleModel); err != nil {
if err := tx.QueryRowContext(ctx, "SELECT workspace,allow_tools,write_paths,input_json,output_json,COALESCE((SELECT original_run_id FROM run_retries WHERE run_id=pipeline_runs.id),0),COALESCE((SELECT mode FROM retry_checkpoints WHERE run_id=pipeline_runs.id),CASE WHEN EXISTS(SELECT 1 FROM run_retries WHERE run_id=pipeline_runs.id) THEN 'restart' ELSE '' END),COALESCE((SELECT source_run_id FROM retry_checkpoints WHERE run_id=pipeline_runs.id),0),COALESCE((SELECT source_version FROM retry_checkpoints WHERE run_id=pipeline_runs.id),0),COALESCE((SELECT source_hash FROM retry_checkpoints WHERE run_id=pipeline_runs.id),''),title_source,title_model,environment_json FROM pipeline_runs WHERE id=?", id).Scan(&r.Workspace, &r.AllowTools, &paths, &input, &output, &r.RetryOf, &r.RetryMode, &r.RetrySource, &r.RetrySourceVersion, &r.RetrySourceHash, &r.TitleSource, &r.TitleModel, &environment); err != nil {
return nil, err
}
if environment != "" {
r.Environment = &protocol.RunEnvironment{}
if err := json.Unmarshal([]byte(environment), r.Environment); err != nil {
return nil, err
}
}
if err := decodeValues(input, &r.Input); err != nil {
return nil, err
}
@@ -304,6 +310,11 @@ strftime('%Y-%m-%dT%H:%M:%SZ',started_at),COALESCE(strftime('%Y-%m-%dT%H:%M:%SZ'
// query and no transcript parse.
r.Usage = protocol.TotalUsage(r.Steps)
r.Warnings = protocol.RunWarnings(r.Steps)
if r.Environment != nil {
for _, warning := range r.Environment.Warnings {
r.Warnings = append(r.Warnings, "Workspace environment: "+warning)
}
}
alerts, err := tx.QueryContext(ctx, `SELECT sequence,event,channel,status,attempts,diagnostic,message_id FROM run_notifications WHERE run_id=? ORDER BY sequence,event,channel`, id)
if err != nil {
return nil, err
+13
View File
@@ -404,6 +404,19 @@ AND NOT EXISTS(SELECT 1 FROM run_steps WHERE run_id=pipeline_runs.id AND agent_a
return tx.Commit()
}
// SetRunEnvironment records the directory environment a run resolved (names
// and files only). A resumed run records its latest resolution.
func (s *Store) SetRunEnvironment(ctx context.Context, id int64, environment *protocol.RunEnvironment) error {
data := []byte{}
if environment != nil {
var err error
if data, err = json.Marshal(environment); err != nil {
return err
}
}
return affected(s.db.ExecContext(ctx, "UPDATE pipeline_runs SET environment_json=? WHERE id=?", string(data), id))
}
func (s *Store) MarkCleanupUnconfirmed(ctx context.Context, id int64) error {
return affected(s.db.ExecContext(ctx, `UPDATE pipeline_runs SET cleanup_unconfirmed=1,
diagnostic='Agent cleanup was not confirmed; workspace remains reserved until successful restart recovery'
+3
View File
@@ -76,6 +76,9 @@ CREATE TABLE IF NOT EXISTS retry_checkpoints (
if err := s.addColumnIfMissing("pipeline_runs", "notify_mode", "TEXT NOT NULL DEFAULT 'auto'"); err != nil {
return err
}
if err := s.addColumnIfMissing("pipeline_runs", "environment_json", "TEXT NOT NULL DEFAULT ''"); err != nil {
return err
}
if err := s.dropResourceSchema(); err != nil {
return err
}