Avoid serializing the whole CoS agent working set on every saveState
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 62/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js
- Domain
- backend, performance
Research direction
Read server/lib/cosAgentRows.js and server/services/cosAgentLifecycle.js to trace planAgentSave and the listed mutation sites; then inspect server/services/cosState.js and its tests, including the concurrency case. Add dirty ID hints for the listed lifecycle updates while preserving full diffing when no hint is given. Done means hinted saves serialize only hinted records, unhinted saves detect every changed row, and an omitted changed ID is saved on the next unhinted save; measure with the synthetic 219-agent fixture from #12738.
Written by the indexing model from the issue text.
Description
Depends on #12738
Discovered while working issue #12738.
Problem
After #12738, saveState() (server/services/cosState.js) writes only the changed cos_agents rows, but to find them planAgentSave (server/lib/cosAgentRows.js) still runs JSON.stringify over every agent record in the working set and compares each with the last stored text. On a working set of ~200 agents / ~3 MB that is still O(total) CPU on every status/output update (the bytes written are now O(changed row), the CPU is not). It also keeps a second copy of every record's text in memory (agentStore.persisted).
Expected vs actual
- Expected: an update to one agent costs roughly the size of that agent.
- Actual: every save serializes all agents to detect which changed.
Chosen next step
Track dirty ids at the mutation sites that matter most (updateAgent, appendAgentOutput/output flush, completeAgent, registerAgent in server/services/cosAgentLifecycle.js) by passing a hint to saveState(state, { changedAgentIds }); serialize only those ids plus any added/removed keys, and keep the full diff as the fallback when no hint is given (so the ~140 other saveState callers stay correct). Measure with the synthetic 219-agent fixture used in the #12738 PR.
Acceptance criteria
- A hinted save serializes only the hinted records (assert via a spy on the serializer or a byte count).
- An unhinted save still detects every changed row (existing
cosState.test.jsconcurrency case keeps passing). - A hint that omits a really-changed record cannot lose that change on the next unhinted save.
Medium/medium: routine multi-file change with one correctness invariant (hint vs full diff fallback).
- Dominant language
- JavaScript
- Stars
- 38
- Forks
- 32
- Avg merge
- 34m
- Merged PRs (30d)
- 993
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from atomantic/PortOS
-
bug effort:high model:heavy plan
Difficulty 4/5 3-5 days Newbie friendliness 43/100
atomantic/PortOS#12748 · 1 comment ·
Maintainers usually reply within 1 day
-
Reconcile dead-owner settlement reservations left by crashed publicationsPossibly taken @atomantic claimed this today. Openbug effort:high in-progress model:medium plan
atomantic/PortOS#12740 · 1 assignee ·
Maintainers usually reply within 1 day
-
CI planner runs the full suite for requirements-only Python pin changesPossibly taken @atomantic claimed this today. Opencode-quality effort:low in-progress model:medium plan
atomantic/PortOS#12739 · 1 assignee ·
Maintainers usually reply within 1 day
-
Worktrees made outside the claim prompt never get dependency links, and a cache-only node_modules blocks a later linkPossibly taken @atomantic claimed this today. Openbug effort:medium in-progress model:medium plan
atomantic/PortOS#12734 · 1 assignee ·
Maintainers usually reply within 1 day
-
Held-checkout archiving holds the claim-ownership lock and starves ownership checks for minutesPossibly taken @atomantic claimed this today. Openbug effort:high in-progress model:heavy planner:opus-5-5
atomantic/PortOS#12682 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in atomantic/PortOS
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
docs
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
idean3885/claude-ops-agent#765 ·
Maintainers usually reply within 1 day
-
docs html v6
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
check:failed feeds:edit
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
iptv-org/database#38385 · 1 comment ·
Maintainers usually reply within 6 days
-
release-followup
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day