Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Avoid serializing the whole CoS agent working set on every saveState

Open
#12,749 0 comments 0 reactions 0 assignees View on GitHub

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

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

effort:medium enhancement model:medium plan

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.js concurrency 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from atomantic/PortOS

All issues in atomantic/PortOS

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.