Robots that drive systems with no API, and a panel to command them
A multi-tenant platform to distribute, schedule and monitor robots on Windows workstations. I worked on the web panel, API and agent, connecting automation execution with the tracking of recurring tax and accounting work.
Full-stack work on an existing platform: workstation queues, pending work by company and reporting period, release distribution, department permissions and new robot integrations.
- Python
- FastAPI
- PostgreSQL
- WebSocket
- React
- TypeScript
- APScheduler
- pdfplumber
The problem
The automations use the screen, mouse and keyboard to operate portals and desktop accounting software without APIs. The operation spans multiple clients, each with its own companies, credentials and machines. The platform has to coordinate what runs, where, on which version and for which reporting period, without opening inbound ports on the client's network. It also needs to show unfinished work: a lost connection, a tax discrepancy and a defective robot require different responses.
Started by hand
Nobody could see what ran, when, or whether it worked.
One mouse, two robots
Robots that drive the mouse and keyboard cannot run in parallel.
A misread amount
A misread amount becomes a wrong e-mail.
How it works
The workstation opens the connection
The Windows agent opens a WebSocket to the panel, receives commands and sends events back. Heartbeats report machine availability; on reconnect, the agent and server reconcile what is still running.
One queue per workstation
The panel stores commands in PostgreSQL and releases one robot at a time per machine because they share a mouse and keyboard. Separate workstations run in parallel; a locked screen or disconnected session holds the queue.
From schedule to batch
A request creates a batch with one execution per company. Schedules use a time zone and can follow all eligible companies, a fixed selection or a company queue whose current membership is read on each occurrence.
Pending work with a clear meaning
The latest result for each company, automation and reporting period determines what needs attention. Cancellation does not hide an earlier failure, and success in another period does not resolve the work left behind.
A shared robot contract
Each release declares its parameters and requirements in a JSON manifest. The agent supplies configuration, follows JSON Lines events and interprets exit codes that distinguish success, errors, partial results and human intervention.
Controlled releases
Package integrity and signatures are verified before installation. The panel tracks installed releases and can require a minimum version; a failed update keeps its error visible and blocks the robot below that minimum.
The operation behind an execution request
Each platform client has an isolated environment, called a tenant. It holds the companies they serve, their users, machines and available automations. A routine may need to run for several companies and a specific reporting month, known as competência in Brazilian accounting. Tracking the robot process alone is insufficient: the panel needs to identify which company's work was completed for which period.
For a manual run, the operator selects the automation, workstation and companies. The server validates those relationships and creates an execution batch with an idempotency key, so resubmitting the same request does not create another batch. Scheduled runs use the same path. If the machine is offline, the selected policy records the work as skipped or keeps the command waiting for reconnection.
My work on the platform
I worked on the central machine queue and its visibility in the panel: the current execution, waiting work and completion estimates based on past runs. I also implemented pending-work tracking, reporting-period tracking and automatic retries for technical failures. Partial results and requests for intervention stay with a person, because retrying an automation that submits data can duplicate an external operation.
Other contributions included department permissions, release notes, bulk robot updates and package storage management. I later added reusable company queues for manual runs and schedules, avoiding repeated company-by-company selection. I also fixed workstation changes not being saved on schedules and made manual dispatch use the robot's configured default machine, while allowing the operator to select another ready workstation.
Distributing a fix while preserving queued work
Publishing a package does not update every workstation on its own. I implemented a minimum-version rollout with a preview of affected installations and progress per machine. Offline workstations update when they return. Executions for that robot wait for installation; other automations remain eligible to use the workstation.
If that automation is running when a mandatory update arrives, the rollout cancels the execution and creates a replacement with the same company, parameters and reporting period, prioritized in the queue. Before releasing queued work, the server validates its parameters against the new manifest. Incompatible work becomes a pending item with a reason; a failed update requires another attempt and keeps the old version blocked.
Automation across browsers and desktop applications
Some workflows cross a browser, a Windows application and files on disk. Playwright controls the web portion, while pywinauto and Windows APIs handle windows, focus and keyboard input. Each transition needs to confirm which window opened, wait for the required state and check the context before continuing. A click that raised no error still needs to produce the expected change in the interface.
Some robots reuse a session between companies in the same batch, reducing repeated authentication. A session is only reused while valid. Rejected credentials, authentication challenges and access restrictions receive their own handling, with a pause or a request for intervention, to avoid repeated attempts that could worsen a lockout.
OCR and calibration for interfaces without accessible controls
Some windows display a streamed interface as an image and expose no fields through accessibility APIs. The robot uses native Windows OCR to locate text and recognize values in those cases. Small regions can be enlarged before reading; recognized positions are converted back to screen coordinates. This supports menus whose positions change and tables that require scrolling.
The strategy depends on the screen: accessible selectors where available, visual recognition where needed and calibrated coordinates as an alternative. Adjustments can belong to a workstation because resolution, scaling and window size affect the target. Important fields are checked after input, and unfamiliar prompts can stop the workflow for human review.
Reading and reconciling files
The robots combine data from files and screens to check whether sources agree. Spreadsheet readers locate headers and normalize identifiers before matching records, instead of relying only on a column's position. Results distinguish missing data, mismatched records and files that could not be retrieved, preserving a reason for each difference.
In PDFs with adjacent boxes, word positions connect each amount to the correct label and preserve empty columns. Readers that require exact monetary comparisons convert amounts to Decimal. One validation requires the primary reading and at least one additional reading of the same amount; all readings found must agree. A mismatch stops the decision that depends on that number.
Staged execution and recovery after interruptions
In workflows with checkpoints, progress is stored on disk by company, period and stage. A new execution can reuse downloads and completed steps, while checks that depend on current file contents run again. Persistent state lives outside the installed release directory so it remains available after a package update.
The policy depends on each step's effect. Reading can be repeated; an external action needs more care. Steps marked as non-repeatable record that they have started before acting. If execution stops in that interval, the robot asks for the destination to be checked before trying again. A local checkpoint helps control recovery but cannot remove uncertainty about what happened in another system.
Explicit control over external actions
Some workflows support querying and checking without enabling the final action. For message delivery, simulation mode builds a complete draft for review. Actions that write or send require explicit parameters, and a validation mismatch can prevent continuation even when sending is enabled.
Delivery workflows keep a local record of completed actions by company and period, with an explicit resend option. Other workflows also look for an existing confirmation at the destination or in shared files. These checks reduce accidental repetition but still need specific handling when a process stops between the external action and recording its confirmation.
Session supervision and diagnostics by stage
An automation also needs to recognize whether its environment is usable: an active session, the expected window, the selected context and available credentials. Some checks preserve a healthy session and only start recovery when they identify that it has ended. During browser recovery, the profile identifies which processes belong to the automation, preserving personal browsers and other robots' profiles.
During execution, events report the current stage and the reason for the outcome. Depending on the workflow, logs, error screenshots and CSV or spreadsheet reports are attached to the execution in the panel. Diagnostics distinguish a technical failure from a condition that needs a person; having no work to perform also has its own state. Whoever handles a pending item can see where processing stopped and what was completed.
Outcome
The operation gained schedules, visible workstation queues, live logs and tracking by company and reporting period. The team can distinguish work waiting for a machine from failures and requests for human attention, retry unfinished work and follow the rollout of a fix. Company queues let operators reuse company groups across recurring routines, while execution history preserves each result.
Technical details
Decisions
PostgreSQL stores state; WebSocket transports it
An open connection is not the record of a command. Commands and states live in the database; WebSocket delivers messages. The agent stores events it could not send locally and replays them with sequence numbers. On reconnect, reconciliation distinguishes a robot that is still alive from an interrupted execution.
The scheduler enqueues; the agent executes
APScheduler stores jobs in PostgreSQL and creates executions through the same path as manual dispatch. I also corrected weekday interpretation: the panel's cron treated Sunday as zero, while the library started with Monday. Converting weekdays to names preserves the frequency selected in the interface.
Validate parameters against the release that will run
The manifest defines configuration fields without requiring a database column for every robot parameter. Automation, company and dispatch values override each other in that order. The final set is validated against the installed release; after an update, queued work is validated again.
Enforce access in queries and actions
I extended department scoping to include tenant administrators. A role determines which actions a person may perform, and their departments determine which automations they can reach. The API filters queries and checks access on actions; hiding a React button neither grants nor revokes access.
Remove packages while preserving history
I implemented release archiving to free storage while keeping the record, release notes and execution references. The policy protects packages installed or requested on a machine, required as a minimum version, and other releases still needed for distribution. The panel explains why a package cannot be archived.
Tests for rules that affect the operation
The contributions include tests for queues with locked sessions, reconciliation after reconnects, mandatory updates, department isolation and pending work by reporting period. Company-queue tests also check schedule membership and refusal to remove a queue still in use. These state and authorization scenarios need more evidence than a success notification in the interface.
A real problem
The automatic reporting period froze at the month of saving
A parameter could declare current month or previous month as a dynamic default. Saving configuration with an empty field resolved that default and stored a fixed month. A recurring routine would then keep using the month of saving in later months. I changed the flow to preserve the missing value and resolve the default on each new dispatch; an explicitly entered month stays fixed. I added tests for both behaviors. Retrying old work follows a different rule: it retains the original reporting period, even after the calendar has moved on.
Limits and next steps
- Execution depends on a usable Windows session. A locked screen or disconnected remote session pauses the queue; the agent needs to run in the user's session to access desktop application interfaces.
- Panel idempotency prevents creating the same request twice, but cannot guarantee that an external system accepts a submission only once. Automatic retries need to remain disabled for routines where resubmission can duplicate an operation.
- Layout changes in portals, desktop applications and documents can require robot maintenance or new workstation calibration. Ambiguous results need to remain visible for human review.
- Desktop automation with OCR: finding a target and checking the result
- RPA checkpoints: when to resume and when to request a review
- Simulate before sending: separating decisions from external effects
- Reading amounts from a PDF by position, not by text order