Skip to content

Add: Job lifecycle management and persistence#82

Closed
FL4TLiN3 wants to merge 2 commits intoepic/job-conceptfrom
feat/job-persistence
Closed

Add: Job lifecycle management and persistence#82
FL4TLiN3 wants to merge 2 commits intoepic/job-conceptfrom
feat/job-persistence

Conversation

@FL4TLiN3
Copy link
Contributor

@FL4TLiN3 FL4TLiN3 commented Dec 9, 2025

Summary

  • Add job-store.ts with storeJob, retrieveJob, createInitialJob functions
  • Create job.json when a new Job starts
  • Update job.json on each Run completion with totalSteps, status, usage, finishedAt

Test plan

  • pnpm typecheck passes
  • pnpm test passes
  • pnpm test:e2e passes

Closes #80


Note

Persist Jobs to job.json, move checkpoints to per-job directory with simplified APIs, update TUI to browse jobs, and clarify CLI/docs that --resume-from requires --continue-job.

  • Runtime/Storage:
    • Add job-store with storeJob, retrieveJob, createInitialJob; export via runtime index.
    • Persist job lifecycle in run() (create/update job.json; track status, totalSteps, usage, finishedAt).
    • Simplify checkpoint storage: move to perstack/jobs/<jobId>/checkpoints/<checkpointId>.json; update defaultStore/RetrieveCheckpoint and executeStateMachine storeCheckpoint signature.
    • Introduce job utilities in run manager: getAllJobs, getCheckpointsByJobId, refactor getMostRecentCheckpoint, getCheckpointById, and checkpoint/details helpers to job-scoped APIs.
  • CLI/TUI:
    • start command/history now lists Jobs (JobHistoryItem) instead of Runs; adapt callbacks (onLoadCheckpoints, onLoadEvents) and browsing UI to job-centric flow.
  • Docs:
    • Update cli.mdx and state management to state --resume-from requires --continue-job and adjust examples/notes.
  • Tests:
    • Adjust runtime store tests to new checkpoint paths and APIs.
    • Update e2e error assertion for --resume-from message.

Written by Cursor Bugbot for commit d402db5. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Dec 9, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
perstack Ignored Ignored Dec 9, 2025 1:23am

@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/runtime/src/job-store.ts 0.00% 13 Missing ⚠️

📢 Thoughts on this report? Let us know!

...job,
totalSteps: job.totalSteps + runResultCheckpoint.stepNumber,
usage: sumUsage(job.usage, runResultCheckpoint.usage),
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Step count double-counted during job delegation

When delegation occurs, the child run's checkpoint inherits the parent's stepNumber via buildDelegateToState (which spreads ...resultCheckpoint). The child's final stepNumber is therefore cumulative across all runs. Adding runResultCheckpoint.stepNumber to job.totalSteps in each while loop iteration causes double-counting.

For example: parent does 3 steps (stepNumber=3), child starts at step 4 and does 2 steps (stepNumber=5). The calculation 3 + 5 = 8 is wrong; it should be 3 + 2 = 5. The same issue affects usage accumulation via sumUsage, as child checkpoints also inherit parent usage.

Fix in Cursor Fix in Web

- Simplify checkpoint storage path to jobs/{jobId}/checkpoints/{id}.json
- Remove timestamp from checkpoint filename
- Update --resume-from to strictly require --continue-job
- Change TUI history from Run-based to Job-based display
- Show jobId and checkpointId in TUI for easier CLI usage

Closes #81
Closes #82
@FL4TLiN3
Copy link
Contributor Author

FL4TLiN3 commented Dec 9, 2025

Consolidated into a combined PR with #81

@FL4TLiN3 FL4TLiN3 closed this Dec 9, 2025
FL4TLiN3 added a commit that referenced this pull request Dec 9, 2025
* Add: Job lifecycle management and persistence

* Refactor: Simplify checkpoint path and display Job-based history in TUI

- Simplify checkpoint storage path to jobs/{jobId}/checkpoints/{id}.json
- Remove timestamp from checkpoint filename
- Update --resume-from to strictly require --continue-job
- Change TUI history from Run-based to Job-based display
- Show jobId and checkpointId in TUI for easier CLI usage

Closes #81
Closes #82

* Refactor: Move persistence logic from run-manager to runtime

- Add getAllJobs() to job-store.ts
- Add getAllRuns() to run-setting-store.ts
- Add getCheckpointsByJobId(), getEventsByRun(), getEventContents() to default-store.ts
- Export new functions from runtime index
- Simplify run-manager.ts to delegate to runtime functions

* Fix: Job totalSteps and usage double-counting

stepNumber and usage in checkpoints are cumulative within a Job,
so directly assign instead of summing to avoid double-counting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant